1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.test.getInstance
4 import net.pterodactylus.sone.web.baseInjector
5 import org.hamcrest.MatcherAssert.assertThat
6 import org.hamcrest.Matchers.equalTo
7 import org.hamcrest.Matchers.notNullValue
9 import org.mockito.Mockito.verify
12 * Unit test for [UnlikeAjaxPage].
14 class UnlikeAjaxPageTest : JsonPageTest("unlike.ajax", pageSupplier = ::UnlikeAjaxPage) {
17 fun `request without type results in error`() {
18 assertThat(json.isSuccess, equalTo(false))
22 fun `request for post without id results in invalid-post-id`() {
23 addRequestParameter("type", "post")
24 assertThatJsonFailed("invalid-post-id")
28 fun `request for invalid type results in invalid-type`() {
29 addRequestParameter("type", "invalid")
30 addRequestParameter("invalid", "invalid")
31 assertThatJsonFailed("invalid-type")
35 fun `request for post with id removes id from liked posts`() {
36 addRequestParameter("type", "post")
37 addRequestParameter("post", "post-id")
38 assertThatJsonIsSuccessful()
39 verify(currentSone).removeLikedPostId("post-id")
40 verify(core).touchConfiguration()
44 fun `request for reply without id results in invalid-reply-id`() {
45 addRequestParameter("type", "reply")
46 assertThatJsonFailed("invalid-reply-id")
50 fun `request for reply with id removes id from liked replys`() {
51 addRequestParameter("type", "reply")
52 addRequestParameter("reply", "reply-id")
53 assertThatJsonIsSuccessful()
54 verify(currentSone).removeLikedReplyId("reply-id")
55 verify(core).touchConfiguration()
59 fun `page can be created by dependency injection`() {
60 assertThat(baseInjector.getInstance<UnlikeAjaxPage>(), notNullValue())