Clean up some imports
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / UnlockSonePageTest.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.sone.test.whenever
6 import net.pterodactylus.util.web.Method.POST
7 import org.junit.Test
8 import org.mockito.ArgumentMatchers.any
9 import org.mockito.Mockito.never
10 import org.mockito.Mockito.verify
11
12 /**
13  * Unit test for [UnlockSonePage].
14  */
15 class UnlockSonePageTest : WebPageTest() {
16
17         private val page = UnlockSonePage(template, webInterface)
18
19         override fun getPage() = page
20
21         @Test
22         fun `post request without sone redirects to return page`() {
23                 setMethod(POST)
24                 addHttpRequestPart("returnPage", "return.html")
25                 verifyRedirect("return.html") {
26                         verify(core, never()).unlockSone(any())
27                 }
28         }
29
30         @Test
31         fun `post request without invalid local sone does not unlock any sone and redirects to return page`() {
32                 setMethod(POST)
33                 addHttpRequestPart("returnPage", "return.html")
34                 addHttpRequestPart("sone", "invalid-sone")
35                 verifyRedirect("return.html") {
36                         verify(core, never()).unlockSone(any())
37                 }
38         }
39
40         @Test
41         fun `post request without remote sone does not unlock any sone and redirects to return page`() {
42                 setMethod(POST)
43                 addHttpRequestPart("returnPage", "return.html")
44                 addHttpRequestPart("sone", "remote-sone")
45                 addSone("remote-sone", mock<Sone>())
46                 verifyRedirect("return.html") {
47                         verify(core, never()).unlockSone(any())
48                 }
49         }
50
51         @Test
52         fun `post request with local sone unlocks sone and redirects to return page`() {
53                 setMethod(POST)
54                 addHttpRequestPart("returnPage", "return.html")
55                 addHttpRequestPart("sone", "local-sone")
56                 val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
57                 addLocalSone("local-sone", sone)
58                 verifyRedirect("return.html") {
59                         verify(core).unlockSone(sone)
60                 }
61         }
62
63 }