Replace reply-specific interfaces with Kotlin versions
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / LikeAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.data.PostReply
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.sone.test.whenever
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
9 import org.junit.Test
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [LikeAjaxPage].
15  */
16 class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage) {
17
18         @Test
19         fun `request with invalid type results in invalid-type error`() {
20                 addRequestParameter("type", "invalid")
21                 addRequestParameter("invalid", "invalid-id")
22                 assertThatJsonFailed("invalid-type")
23         }
24
25         @Test
26         fun `request with valid post id results in post being liked by current sone`() {
27                 addRequestParameter("type", "post")
28                 addRequestParameter("post", "post-id")
29                 addPost(mock<Post>().apply { whenever(id).thenReturn("post-id") })
30                 assertThatJsonIsSuccessful()
31                 verify(currentSone).addLikedPostId("post-id")
32                 verify(core).touchConfiguration()
33         }
34
35         @Test
36         fun `request with valid reply id results in reply being liked by current sone`() {
37                 addRequestParameter("type", "reply")
38                 addRequestParameter("reply", "reply-id")
39                 addReply(mock<PostReply>().apply { whenever(id).thenReturn("reply-id") })
40                 assertThatJsonIsSuccessful()
41                 verify(currentSone).addLikedReplyId("reply-id")
42                 verify(core).touchConfiguration()
43         }
44
45         @Test
46         fun `request with invalid post id results in post being liked by current sone`() {
47                 addRequestParameter("type", "post")
48                 addRequestParameter("post", "post-id")
49                 assertThat(json.isSuccess, equalTo(false))
50                 verify(currentSone, never()).addLikedPostId("post-id")
51                 verify(core, never()).touchConfiguration()
52         }
53
54         @Test
55         fun `request with invalid reply id results in reply being liked by current sone`() {
56                 addRequestParameter("type", "reply")
57                 addRequestParameter("reply", "reply-id")
58                 assertThat(json.isSuccess, equalTo(false))
59                 verify(currentSone, never()).addLikedReplyId("reply-id")
60                 verify(core, never()).touchConfiguration()
61         }
62
63 }