1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.test.mock
4 import net.pterodactylus.sone.web.WebInterface
5 import org.hamcrest.MatcherAssert.assertThat
6 import org.hamcrest.Matchers.equalTo
10 * Base class for tests for any [JsonPage] implementations.
12 abstract class JsonPageTest(
13 private val expectedPath: String,
14 private val requiresLogin: Boolean = true,
15 private val needsFormPassword: Boolean = true,
16 pageSupplier: (WebInterface) -> JsonPage = { mock() }): TestObjects() {
18 protected open val page: JsonPage by lazy { pageSupplier(webInterface) }
19 protected val json by lazy {
20 page.createJsonObject(freenetRequest)
23 protected val JsonReturnObject.error get() = if (this is JsonErrorReturnObject) this.error else null
26 fun `page returns correct path`() {
27 assertThat(page.path, equalTo(expectedPath))
31 fun `page needs form password`() {
32 assertThat(page.needsFormPassword(), equalTo(needsFormPassword))
36 fun `page requires login`() {
37 assertThat(page.requiresLogin(), equalTo(requiresLogin))