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.test.whenever
7 import net.pterodactylus.sone.web.baseInjector
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
10 import org.hamcrest.Matchers.notNullValue
12 import org.mockito.Mockito.verify
15 * Unit test for [FollowSoneAjaxPage].
17 class FollowSoneAjaxPageTest : JsonPageTest("followSone.ajax", pageSupplier = ::FollowSoneAjaxPage) {
20 fun `request without sone id results in invalid-sone-id`() {
21 assertThatJsonFailed("invalid-sone-id")
25 fun `request with sone follows sone`() {
26 addSone(mock<Sone>().apply { whenever(id).thenReturn("sone-id") })
27 addRequestParameter("sone", "sone-id")
28 assertThatJsonIsSuccessful()
29 verify(core).followSone(currentSone, "sone-id")
33 fun `request with sone makes sone as known`() {
34 val sone = mock<Sone>()
35 addSone(sone, "sone-id")
36 addRequestParameter("sone", "sone-id")
37 assertThatJsonIsSuccessful()
38 verify(core).markSoneKnown(sone)
42 fun `page can be created by dependency injection`() {
43 assertThat(baseInjector.getInstance<FollowSoneAjaxPage>(), notNullValue())