🔥 Remove “create” flag from session provider interface
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / UnlockSoneAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import org.hamcrest.MatcherAssert.*
7 import org.hamcrest.Matchers.*
8 import org.junit.*
9 import org.mockito.Mockito.*
10
11 /**
12  * Unit test for [UnlockSoneAjaxPage].
13  */
14 class UnlockSoneAjaxPageTest : JsonPageTest("unlockSone.ajax", requiresLogin = false, pageSupplier = ::UnlockSoneAjaxPage) {
15
16         @Test
17         fun `request without sone results in invalid-sone-id`() {
18                 assertThatJsonFailed("invalid-sone-id")
19         }
20
21         @Test
22         fun `request with invalid sone results in invalid-sone-id`() {
23                 addRequestParameter("sone", "invalid")
24                 assertThatJsonFailed("invalid-sone-id")
25         }
26
27         @Test
28         fun `request with valid sone results in locked sone`() {
29                 val sone = mock<Sone>()
30                 addLocalSone(sone, "sone-id")
31                 addRequestParameter("sone", "sone-id")
32                 assertThatJsonIsSuccessful()
33                 verify(core).unlockSone(sone)
34         }
35
36         @Test
37         fun `page can be created by dependency injection`() {
38             assertThat(baseInjector.getInstance<UnlockSoneAjaxPage>(), notNullValue())
39         }
40
41 }