1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.sone.test.whenever
6 import net.pterodactylus.util.web.Method.POST
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
10 import org.mockito.ArgumentMatchers
11 import org.mockito.ArgumentMatchers.any
12 import org.mockito.ArgumentMatchers.anyString
13 import org.mockito.Mockito.never
14 import org.mockito.Mockito.verify
17 * Unit test for [FollowSonePage].
19 class FollowSonePageTest: WebPageTest(::FollowSonePage) {
22 fun `page returns correct path`() {
23 assertThat(page.path, equalTo("followSone.html"))
27 fun `page requires login`() {
28 assertThat(page.requiresLogin(), equalTo(true))
32 fun `page returns correct title`() {
33 whenever(l10n.getString("Page.FollowSone.Title")).thenReturn("follow sone page title")
34 assertThat(page.getPageTitle(freenetRequest), equalTo("follow sone page title"))
38 fun `get request does not redirect`() {
39 page.processTemplate(freenetRequest, templateContext)
43 fun `a single sone can be followed`() {
45 val sone = mock<Sone>()
46 addSone("sone-id", sone)
47 addHttpRequestPart("sone", "sone-id")
48 addHttpRequestPart("returnPage", "return.html")
49 verifyRedirect("return.html") {
50 verify(core).followSone(currentSone, "sone-id")
51 verify(core).markSoneKnown(sone)
56 fun `multiple sones can be followed`() {
58 val firstSone = mock<Sone>()
59 addSone("sone-id1", firstSone)
60 val secondSone = mock<Sone>()
61 addSone("sone-id2", secondSone)
62 addHttpRequestPart("sone", "sone-id1,sone-id2")
63 addHttpRequestPart("returnPage", "return.html")
64 verifyRedirect("return.html") {
65 verify(core).followSone(currentSone, "sone-id1")
66 verify(core).followSone(currentSone, "sone-id2")
67 verify(core).markSoneKnown(firstSone)
68 verify(core).markSoneKnown(secondSone)
73 fun `a non-existing sone is not followed`() {
75 addHttpRequestPart("sone", "sone-id")
76 addHttpRequestPart("returnPage", "return.html")
77 verifyRedirect("return.html") {
78 verify(core, never()).followSone(ArgumentMatchers.eq(currentSone), anyString())
79 verify(core, never()).markSoneKnown(any<Sone>())