Add unit test for JSON base page
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / LockSonePageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.util.web.Method.POST
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.junit.Test
9 import org.mockito.ArgumentMatchers.any
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [LockSonePage].
15  */
16 class LockSonePageTest: WebPageTest(::LockSonePage) {
17
18         @Test
19         fun `page returns correct path`() {
20                 assertThat(page.path, equalTo("lockSone.html"))
21         }
22
23         @Test
24         fun `page does not require login`() {
25             assertThat(page.requiresLogin(), equalTo(false))
26         }
27
28         @Test
29         fun `page returns correct title`() {
30             addTranslation("Page.LockSone.Title", "lock Sone page title")
31                 assertThat(page.getPageTitle(freenetRequest), equalTo("lock Sone page title"))
32         }
33
34         @Test
35         fun `locking an invalid local sone redirects to return page`() {
36                 setMethod(POST)
37                 addHttpRequestPart("returnPage", "return.html")
38                 verifyRedirect("return.html") {
39                         verify(core, never()).lockSone(any<Sone>())
40                 }
41         }
42
43         @Test
44         fun `locking an valid local sone locks the sone and redirects to return page`() {
45                 setMethod(POST)
46                 addHttpRequestPart("sone", "sone-id")
47                 val sone = mock<Sone>()
48                 addLocalSone("sone-id", sone)
49                 addHttpRequestPart("returnPage", "return.html")
50                 verifyRedirect("return.html") {
51                         verify(core).lockSone(sone)
52                 }
53         }
54
55 }