🐛 Fix follow and unfollow functions
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / TrustAjaxPageTest.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 [TrustAjaxPage].
15  */
16 class TrustAjaxPageTest : JsonPageTest("trustSone.ajax", requiresLogin = true, needsFormPassword = true, pageSupplier = ::TrustAjaxPage) {
17
18         private val sone = mock<Sone>()
19
20         @Test
21         fun `request with invalid sone results in invalid-sone-id`() {
22                 assertThatJsonFailed("invalid-sone-id")
23         }
24
25         @Test
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)
31         }
32
33         @Test
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))
40         }
41
42         @Test
43         fun `page can be created by dependency injection`() {
44             assertThat(baseInjector.getInstance<TrustAjaxPage>(), notNullValue())
45         }
46
47 }