1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.util.web.Method.*
7 import org.hamcrest.MatcherAssert.*
8 import org.hamcrest.Matchers.*
10 import org.mockito.ArgumentMatchers.any
11 import org.mockito.Mockito.never
12 import org.mockito.Mockito.verify
15 * Unit test for [UnlockSonePage].
17 class UnlockSonePageTest : WebPageTest(::UnlockSonePage) {
20 fun `page returns correct path`() {
21 assertThat(page.path, equalTo("unlockSone.html"))
25 fun `page does not require login`() {
26 assertThat(page.requiresLogin(), equalTo(false))
30 fun `page returns correct title`() {
31 addTranslation("Page.UnlockSone.Title", "unlock page title")
32 assertThat(page.getPageTitle(soneRequest), equalTo("unlock page title"))
36 fun `post request without sone redirects to return page`() {
38 addHttpRequestPart("returnPage", "return.html")
39 verifyRedirect("return.html") {
40 verify(core, never()).unlockSone(any())
45 fun `post request without invalid local sone does not unlock any sone and redirects to return page`() {
47 addHttpRequestPart("returnPage", "return.html")
48 addHttpRequestPart("sone", "invalid-sone")
49 verifyRedirect("return.html") {
50 verify(core, never()).unlockSone(any())
55 fun `post request without remote sone does not unlock any sone and redirects to return page`() {
57 addHttpRequestPart("returnPage", "return.html")
58 addHttpRequestPart("sone", "remote-sone")
59 addSone("remote-sone", mock())
60 verifyRedirect("return.html") {
61 verify(core, never()).unlockSone(any())
66 fun `post request with local sone unlocks sone and redirects to return page`() {
68 addHttpRequestPart("returnPage", "return.html")
69 addHttpRequestPart("sone", "local-sone")
70 val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
71 addLocalSone("local-sone", sone)
72 verifyRedirect("return.html") {
73 verify(core).unlockSone(sone)
78 fun `page can be created by dependency injection`() {
79 assertThat(baseInjector.getInstance<UnlockSonePage>(), notNullValue())