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.getInstance
6 import net.pterodactylus.sone.test.mock
7 import net.pterodactylus.sone.test.whenever
8 import net.pterodactylus.sone.web.baseInjector
9 import org.hamcrest.MatcherAssert.assertThat
10 import org.hamcrest.Matchers.equalTo
11 import org.hamcrest.Matchers.notNullValue
13 import org.mockito.Mockito.never
14 import org.mockito.Mockito.verify
17 * Unit test for [LikeAjaxPage].
19 class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage) {
22 fun `request with invalid type results in invalid-type error`() {
23 addRequestParameter("type", "invalid")
24 addRequestParameter("invalid", "invalid-id")
25 assertThatJsonFailed("invalid-type")
29 fun `request with valid post id results in post being liked by current sone`() {
30 addRequestParameter("type", "post")
31 addRequestParameter("post", "post-id")
32 addPost(mock<Post>().apply { whenever(id).thenReturn("post-id") })
33 assertThatJsonIsSuccessful()
34 verify(currentSone).addLikedPostId("post-id")
35 verify(core).touchConfiguration()
39 fun `request with valid reply id results in reply being liked by current sone`() {
40 addRequestParameter("type", "reply")
41 addRequestParameter("reply", "reply-id")
42 addReply(mock<PostReply>().apply { whenever(id).thenReturn("reply-id") })
43 assertThatJsonIsSuccessful()
44 verify(currentSone).addLikedReplyId("reply-id")
45 verify(core).touchConfiguration()
49 fun `request with invalid post id results in post being liked by current sone`() {
50 addRequestParameter("type", "post")
51 addRequestParameter("post", "post-id")
52 assertThat(json.isSuccess, equalTo(false))
53 verify(currentSone, never()).addLikedPostId("post-id")
54 verify(core, never()).touchConfiguration()
58 fun `request with invalid reply id results in reply being liked by current sone`() {
59 addRequestParameter("type", "reply")
60 addRequestParameter("reply", "reply-id")
61 assertThat(json.isSuccess, equalTo(false))
62 verify(currentSone, never()).addLikedReplyId("reply-id")
63 verify(core, never()).touchConfiguration()
67 fun `page can be created by dependency injection`() {
68 assertThat(baseInjector.getInstance<LikeAjaxPage>(), notNullValue())