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
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 `post request without sone redirects to return page`() {
24 addHttpRequestPart("returnPage", "return.html")
25 verifyRedirect("return.html") {
26 verify(core, never()).unlockSone(any())
31 fun `post request without invalid local sone does not unlock any sone and redirects to return page`() {
33 addHttpRequestPart("returnPage", "return.html")
34 addHttpRequestPart("sone", "invalid-sone")
35 verifyRedirect("return.html") {
36 verify(core, never()).unlockSone(any())
41 fun `post request without remote sone does not unlock any sone and redirects to return page`() {
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())
52 fun `post request with local sone unlocks sone and redirects to return page`() {
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)