1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.getInstance
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.sone.web.baseInjector
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
9 import org.hamcrest.Matchers.notNullValue
11 import org.mockito.Mockito.verify
14 * Unit test for [TrustAjaxPage].
16 class TrustAjaxPageTest : JsonPageTest("trustSone.ajax", requiresLogin = true, needsFormPassword = true, pageSupplier = ::TrustAjaxPage) {
18 private val sone = mock<Sone>()
21 fun `request with invalid sone results in invalid-sone-id`() {
22 assertThatJsonFailed("invalid-sone-id")
26 fun `request with valid sone trust sone`() {
27 addSone(sone, "sone-id")
28 addRequestParameter("sone", "sone-id")
29 assertThatJsonIsSuccessful()
30 verify(core).trustSone(currentSone, sone)
34 fun `request with valid sone returns positive trust value`() {
35 addSone(sone, "sone-id")
36 addRequestParameter("sone", "sone-id")
37 core.preferences.newPositiveTrust = 31
38 assertThatJsonIsSuccessful()
39 assertThat(json["trustValue"]?.asInt(), equalTo(31))
43 fun `page can be created by dependency injection`() {
44 assertThat(baseInjector.getInstance<TrustAjaxPage>(), notNullValue())