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