/**
* Unit test for [BookmarkAjaxPage].
*/
-class BookmarkAjaxPageTest : JsonPageTest(::BookmarkAjaxPage) {
-
- @Test
- fun `page returns correct path`() {
- assertThat(page.path, equalTo("bookmark.ajax"))
- }
-
- @Test
- fun `page does not require login`() {
- assertThat(page.requiresLogin(), equalTo(false))
- }
+class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false, pageSupplier = ::BookmarkAjaxPage) {
@Test
fun `missing post ID results in invalid id response`() {
- assertThat(json.isSuccess, equalTo(false))
- assertThat((json as JsonErrorReturnObject).error, equalTo("invalid-post-id"))
+ assertThatJsonFailed("invalid-post-id")
}
@Test
fun `empty post ID results in invalid id response`() {
addRequestParameter("post", "")
- assertThat(json.isSuccess, equalTo(false))
- assertThat((json as JsonErrorReturnObject).error, equalTo("invalid-post-id"))
+ assertThatJsonFailed("invalid-post-id")
}
@Test
fun `invalid post ID results in success but does not bookmark anything`() {
addRequestParameter("post", "missing")
- assertThat(json.isSuccess, equalTo(true))
+ assertThatJsonIsSuccessful()
verify(core, never()).bookmarkPost(any<Post>())
}
fun `valid post ID results in success and bookmarks the post`() {
addRequestParameter("post", "valid-post-id")
val post = addNewPost("valid-post-id", "1", 2)
- assertThat(json.isSuccess, equalTo(true))
+ assertThatJsonIsSuccessful()
verify(core).bookmarkPost(post)
}