Add test for DI constructability of UnfollowSoneAjaxPage
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / UnfollowSoneAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.getInstance
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.sone.test.whenever
7 import net.pterodactylus.sone.web.baseInjector
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
10 import org.hamcrest.Matchers.notNullValue
11 import org.junit.Test
12 import org.mockito.Mockito.verify
13
14 /**
15  * Unit test for [UnfollowSoneAjaxPage].
16  */
17 class UnfollowSoneAjaxPageTest : JsonPageTest("unfollowSone.ajax", pageSupplier = ::UnfollowSoneAjaxPage) {
18
19         @Test
20         fun `request without sone returns invalid-sone-id`() {
21                 assertThatJsonFailed("invalid-sone-id")
22         }
23
24         @Test
25         fun `request with invalid sone returns invalid-sone-id`() {
26                 addRequestParameter("sone", "invalid")
27                 assertThatJsonFailed("invalid-sone-id")
28         }
29
30         @Test
31         fun `request with valid sone unfollows sone`() {
32                 addSone(mock<Sone>().apply { whenever(id).thenReturn("sone-id") })
33                 addRequestParameter("sone", "sone-id")
34                 assertThatJsonIsSuccessful()
35                 verify(core).unfollowSone(currentSone, "sone-id")
36         }
37
38         @Test
39         fun `page can be created by dependency injection`() {
40             assertThat(baseInjector.getInstance<UnfollowSoneAjaxPage>(), notNullValue())
41         }
42
43 }