package net.pterodactylus.sone.web.ajax
+import net.pterodactylus.sone.data.Post
+import net.pterodactylus.sone.data.PostReply
+import net.pterodactylus.sone.test.getInstance
+import net.pterodactylus.sone.test.mock
+import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.web.baseInjector
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
import org.junit.Test
+import org.mockito.Mockito.never
import org.mockito.Mockito.verify
/**
@Test
fun `request with invalid type results in invalid-type error`() {
- addRequestParameter("type", "invalid")
+ addRequestParameter("type", "invalid")
addRequestParameter("invalid", "invalid-id")
- assertThat(json.isSuccess, equalTo(false))
- assertThat(json.error, equalTo("invalid-type"))
+ assertThatJsonFailed("invalid-type")
}
@Test
- fun `request with post id results in post being liked by current sone`() {
+ fun `request with valid post id results in post being liked by current sone`() {
addRequestParameter("type", "post")
addRequestParameter("post", "post-id")
- assertThat(json.isSuccess, equalTo(true))
+ addPost(mock<Post>().apply { whenever(id).thenReturn("post-id") })
+ assertThatJsonIsSuccessful()
verify(currentSone).addLikedPostId("post-id")
verify(core).touchConfiguration()
}
@Test
- fun `request with reply id results in reply being liked by current sone`() {
+ fun `request with valid reply id results in reply being liked by current sone`() {
addRequestParameter("type", "reply")
addRequestParameter("reply", "reply-id")
- assertThat(json.isSuccess, equalTo(true))
+ addReply(mock<PostReply>().apply { whenever(id).thenReturn("reply-id") })
+ assertThatJsonIsSuccessful()
verify(currentSone).addLikedReplyId("reply-id")
verify(core).touchConfiguration()
}
+ @Test
+ fun `request with invalid post id results in post being liked by current sone`() {
+ addRequestParameter("type", "post")
+ addRequestParameter("post", "post-id")
+ assertThat(json.isSuccess, equalTo(false))
+ verify(currentSone, never()).addLikedPostId("post-id")
+ verify(core, never()).touchConfiguration()
+ }
+
+ @Test
+ fun `request with invalid reply id results in reply being liked by current sone`() {
+ addRequestParameter("type", "reply")
+ addRequestParameter("reply", "reply-id")
+ assertThat(json.isSuccess, equalTo(false))
+ verify(currentSone, never()).addLikedReplyId("reply-id")
+ verify(core, never()).touchConfiguration()
+ }
+
+ @Test
+ fun `page can be created by dependency injection`() {
+ assertThat(baseInjector.getInstance<LikeAjaxPage>(), notNullValue())
+ }
+
}