Add test for DI constructability of UnlikeAjaxPage
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / UnlikeAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.test.getInstance
4 import net.pterodactylus.sone.web.baseInjector
5 import org.hamcrest.MatcherAssert.assertThat
6 import org.hamcrest.Matchers.equalTo
7 import org.hamcrest.Matchers.notNullValue
8 import org.junit.Test
9 import org.mockito.Mockito.verify
10
11 /**
12  * Unit test for [UnlikeAjaxPage].
13  */
14 class UnlikeAjaxPageTest : JsonPageTest("unlike.ajax", pageSupplier = ::UnlikeAjaxPage) {
15
16         @Test
17         fun `request without type results in error`() {
18                 assertThat(json.isSuccess, equalTo(false))
19         }
20
21         @Test
22         fun `request for post without id results in invalid-post-id`() {
23                 addRequestParameter("type", "post")
24                 assertThatJsonFailed("invalid-post-id")
25         }
26
27         @Test
28         fun `request for invalid type results in invalid-type`() {
29                 addRequestParameter("type", "invalid")
30                 addRequestParameter("invalid", "invalid")
31                 assertThatJsonFailed("invalid-type")
32         }
33
34         @Test
35         fun `request for post with id removes id from liked posts`() {
36                 addRequestParameter("type", "post")
37                 addRequestParameter("post", "post-id")
38                 assertThatJsonIsSuccessful()
39                 verify(currentSone).removeLikedPostId("post-id")
40                 verify(core).touchConfiguration()
41         }
42
43         @Test
44         fun `request for reply without id results in invalid-reply-id`() {
45                 addRequestParameter("type", "reply")
46                 assertThatJsonFailed("invalid-reply-id")
47         }
48
49         @Test
50         fun `request for reply with id removes id from liked replys`() {
51                 addRequestParameter("type", "reply")
52                 addRequestParameter("reply", "reply-id")
53                 assertThatJsonIsSuccessful()
54                 verify(currentSone).removeLikedReplyId("reply-id")
55                 verify(core).touchConfiguration()
56         }
57
58         @Test
59         fun `page can be created by dependency injection`() {
60             assertThat(baseInjector.getInstance<UnlikeAjaxPage>(), notNullValue())
61         }
62
63 }