🐛 Fix follow and unfollow functions
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / DistrustAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
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
10 import org.junit.Test
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [DistrustAjaxPage].
15  */
16 class DistrustAjaxPageTest : JsonPageTest("distrustSone.ajax", pageSupplier = ::DistrustAjaxPage) {
17
18         @Test
19         fun `request with missing sone results in invalid-sone-id`() {
20                 assertThatJsonFailed("invalid-sone-id")
21         }
22
23         @Test
24         fun `request with invalid sone results in invalid-sone-id`() {
25                 addRequestParameter("sone", "invalid-sone")
26                 assertThatJsonFailed("invalid-sone-id")
27         }
28
29         @Test
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)
36         }
37
38         @Test
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))
46         }
47
48         @Test
49         fun `page can be created by dependency injection`() {
50             assertThat(baseInjector.getInstance<DistrustAjaxPage>(), notNullValue())
51         }
52
53 }