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 [DistrustAjaxPage].
16 class DistrustAjaxPageTest : JsonPageTest("distrustSone.ajax", pageSupplier = ::DistrustAjaxPage) {
19 fun `request with missing sone results in invalid-sone-id`() {
20 assertThatJsonFailed("invalid-sone-id")
24 fun `request with invalid sone results in invalid-sone-id`() {
25 addRequestParameter("sone", "invalid-sone")
26 assertThatJsonFailed("invalid-sone-id")
30 fun `request with valid sone results in distrusted sone`() {
31 val sone = mock<Sone>()
32 addSone(sone, "sone-id")
33 addRequestParameter("sone", "sone-id")
34 assertThatJsonIsSuccessful()
35 verify(core).distrustSone(currentSone, sone)
39 fun `request with valid sone results in correct trust value being sent back`() {
40 core.preferences.newNegativeTrust = -33
41 val sone = mock<Sone>()
42 addSone(sone, "sone-id")
43 addRequestParameter("sone", "sone-id")
44 assertThatJsonIsSuccessful()
45 assertThat(json["trustValue"]?.asInt(), equalTo(-33))
49 fun `page can be created by dependency injection`() {
50 assertThat(baseInjector.getInstance<DistrustAjaxPage>(), notNullValue())