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.sone.web.pages.UnlockSonePage
8 import org.mockito.ArgumentMatchers.any
9 import org.mockito.Mockito.never
10 import org.mockito.Mockito.verify
13 * Unit test for [UnlockSonePage].
15 class UnlockSonePageTest : WebPageTest() {
17 private val page = UnlockSonePage(template, webInterface)
19 override fun getPage() = page
22 fun `get request without sone redirects to return page`() {
23 addHttpRequestParameter("returnPage", "return.html")
24 verifyRedirect("return.html") {
25 verify(core, never()).unlockSone(any())
30 fun `get request without invalid local sone does not unlock any sone and redirects to return page`() {
31 addHttpRequestParameter("returnPage", "return.html")
32 addHttpRequestParameter("sone", "invalid-sone")
33 verifyRedirect("return.html") {
34 verify(core, never()).unlockSone(any())
39 fun `get request without remote sone does not unlock any sone and redirects to return page`() {
40 addHttpRequestParameter("returnPage", "return.html")
41 addHttpRequestParameter("sone", "remote-sone")
42 addSone("remote-sone", mock<Sone>())
43 verifyRedirect("return.html") {
44 verify(core, never()).unlockSone(any())
49 fun `get request with local sone unlocks sone and redirects to return page`() {
50 addHttpRequestParameter("returnPage", "return.html")
51 addHttpRequestParameter("sone", "local-sone")
52 val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
53 addLocalSone("local-sone", sone)
54 verifyRedirect("return.html") {
55 verify(core).unlockSone(sone)