1 package net.pterodactylus.sone.web.ajax
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
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
14 * Unit test for [LikeAjaxPage].
16 class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage) {
19 fun `request with invalid type results in invalid-type error`() {
20 addRequestParameter("type", "invalid")
21 addRequestParameter("invalid", "invalid-id")
22 assertThatJsonFailed("invalid-type")
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()
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()
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()
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()