1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.util.web.Method.POST
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
9 import org.mockito.ArgumentMatchers.any
10 import org.mockito.ArgumentMatchers.eq
11 import org.mockito.Mockito.never
12 import org.mockito.Mockito.verify
15 * Unit test for [UntrustPage].
17 class UntrustPageTest: WebPageTest(::UntrustPage) {
20 fun `page returns correct path`() {
21 assertThat(page.path, equalTo("untrust.html"))
25 fun `page requires login`() {
26 assertThat(page.requiresLogin(), equalTo(true))
30 fun `page returns correct title`() {
31 addTranslation("Page.Untrust.Title", "untrust page title")
32 assertThat(page.getPageTitle(freenetRequest), equalTo("untrust page title"))
36 fun `get request does not redirect`() {
38 verify(core, never()).untrustSone(eq(currentSone), any())
43 fun `post request without sone parameter does not untrust but redirects`() {
45 addHttpRequestPart("returnPage", "return.html")
46 verifyRedirect("return.html") {
47 verify(core, never()).untrustSone(eq(currentSone), any())
52 fun `post request with invalid sone parameter does not untrust but redirects`() {
54 addHttpRequestPart("returnPage", "return.html")
55 addHttpRequestPart("sone", "no-sone")
56 verifyRedirect("return.html") {
57 verify(core, never()).untrustSone(eq(currentSone), any())
62 fun `post request with valid sone parameter untrusts and redirects`() {
64 addHttpRequestPart("returnPage", "return.html")
65 addHttpRequestPart("sone", "sone-id")
66 val sone = mock<Sone>()
67 addSone("sone-id", sone)
68 verifyRedirect("return.html") {
69 verify(core).untrustSone(currentSone, sone)