Merge branch 'release-0.9.7'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / FollowSoneAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.sone.test.whenever
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.junit.Test
9 import org.mockito.Mockito.verify
10
11 /**
12  * Unit test for [FollowSoneAjaxPage].
13  */
14 class FollowSoneAjaxPageTest : JsonPageTest("followSone.ajax", pageSupplier = ::FollowSoneAjaxPage) {
15
16         @Test
17         fun `request without sone id results in invalid-sone-id`() {
18                 assertThatJsonFailed("invalid-sone-id")
19         }
20
21         @Test
22         fun `request with sone follows sone`() {
23                 addSone(mock<Sone>().apply { whenever(id).thenReturn("sone-id") })
24                 addRequestParameter("sone", "sone-id")
25                 assertThatJsonIsSuccessful()
26                 verify(core).followSone(currentSone, "sone-id")
27         }
28
29         @Test
30         fun `request with sone makes sone as known`() {
31                 val sone = mock<Sone>()
32                 addSone(sone, "sone-id")
33                 addRequestParameter("sone", "sone-id")
34                 assertThatJsonIsSuccessful()
35                 verify(core).markSoneKnown(sone)
36         }
37
38 }