import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.data.PostReply
import net.pterodactylus.sone.data.Sone
+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
/**
@Test
fun `invalid post ID results in error message`() {
- assertThat(json.isSuccess, equalTo(false))
- assertThat(json.error, equalTo("invalid-post-id"))
+ assertThatJsonFailed("invalid-post-id")
}
@Test
fun `valid post ID results in created reply`() {
val post = mock<Post>()
- addPost("post-id", post)
+ addPost(post, "post-id")
val reply = mock<PostReply>().apply { whenever(id).thenReturn("reply-id") }
whenever(core.createReply(currentSone, post, "")).thenReturn(reply)
addRequestParameter("post", "post-id")
- assertThat(json.isSuccess, equalTo(true))
- assertThat(json["reply"].asText(), equalTo("reply-id"))
- assertThat(json["sone"].asText(), equalTo("soneId"))
+ assertThatJsonIsSuccessful()
+ assertThat(json["reply"]?.asText(), equalTo("reply-id"))
+ assertThat(json["sone"]?.asText(), equalTo("soneId"))
}
@Test
fun `text is filtered when creating reply`() {
val post = mock<Post>()
- addPost("post-id", post)
+ addPost(post, "post-id")
val reply = mock<PostReply>().apply { whenever(id).thenReturn("reply-id") }
whenever(core.createReply(currentSone, post, "Text with KSK@foo.bar link")).thenReturn(reply)
addRequestParameter("post", "post-id")
addRequestParameter("text", "Text with http://127.0.0.1:8888/KSK@foo.bar link")
addRequestHeader("Host", "127.0.0.1:8888")
- assertThat(json.isSuccess, equalTo(true))
- assertThat(json["reply"].asText(), equalTo("reply-id"))
- assertThat(json["sone"].asText(), equalTo("soneId"))
+ assertThatJsonIsSuccessful()
+ assertThat(json["reply"]?.asText(), equalTo("reply-id"))
+ assertThat(json["sone"]?.asText(), equalTo("soneId"))
}
@Test
fun `sender can be chosen from local sones`() {
val sone = mock<Sone>().apply { whenever(id).thenReturn("local-sone") }
- addLocalSone("local-sone", sone)
+ addLocalSone(sone)
val post = mock<Post>()
- addPost("post-id", post)
+ addPost(post, "post-id")
val reply = mock<PostReply>().apply { whenever(id).thenReturn("reply-id") }
whenever(core.createReply(sone, post, "Text")).thenReturn(reply)
addRequestParameter("post", "post-id")
addRequestParameter("text", "Text")
addRequestParameter("sender", "local-sone")
- assertThat(json.isSuccess, equalTo(true))
- assertThat(json["reply"].asText(), equalTo("reply-id"))
- assertThat(json["sone"].asText(), equalTo("local-sone"))
+ assertThatJsonIsSuccessful()
+ assertThat(json["reply"]?.asText(), equalTo("reply-id"))
+ assertThat(json["sone"]?.asText(), equalTo("local-sone"))
+ }
+
+ @Test
+ fun `page can be created by dependency injection`() {
+ assertThat(baseInjector.getInstance<CreateReplyAjaxPage>(), notNullValue())
}
}