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 assertThat(json.isSuccess, equalTo(false))
23 assertThat(json.error, equalTo("invalid-type"))
27 fun `request with valid post id results in post being liked by current sone`() {
28 addRequestParameter("type", "post")
29 addRequestParameter("post", "post-id")
30 addPost(mock<Post>().apply { whenever(id).thenReturn("post-id") })
31 assertThat(json.isSuccess, equalTo(true))
32 verify(currentSone).addLikedPostId("post-id")
33 verify(core).touchConfiguration()
37 fun `request with valid reply id results in reply being liked by current sone`() {
38 addRequestParameter("type", "reply")
39 addRequestParameter("reply", "reply-id")
40 addReply(mock<PostReply>().apply { whenever(id).thenReturn("reply-id") })
41 assertThat(json.isSuccess, equalTo(true))
42 verify(currentSone).addLikedReplyId("reply-id")
43 verify(core).touchConfiguration()
47 fun `request with invalid post id results in post being liked by current sone`() {
48 addRequestParameter("type", "post")
49 addRequestParameter("post", "post-id")
50 assertThat(json.isSuccess, equalTo(false))
51 verify(currentSone, never()).addLikedPostId("post-id")
52 verify(core, never()).touchConfiguration()
56 fun `request with invalid reply id results in reply being liked by current sone`() {
57 addRequestParameter("type", "reply")
58 addRequestParameter("reply", "reply-id")
59 assertThat(json.isSuccess, equalTo(false))
60 verify(currentSone, never()).addLikedReplyId("reply-id")
61 verify(core, never()).touchConfiguration()