6ea28f3ad60831bf292712e9fb4a3e1b2c93d697
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / DeleteProfileFieldAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import org.hamcrest.MatcherAssert.assertThat
4 import org.hamcrest.Matchers.equalTo
5 import org.hamcrest.Matchers.nullValue
6 import org.junit.Test
7 import org.mockito.Mockito.verify
8
9 /**
10  * Unit test for [DeleteProfileFieldAjaxPage].
11  */
12 class DeleteProfileFieldAjaxPageTest : JsonPageTest("deleteProfileField.ajax", pageSupplier = ::DeleteProfileFieldAjaxPage) {
13
14         @Test
15         fun `request without field id results in invalid field id error`() {
16                 assertThat(json.isSuccess, equalTo(false))
17                 assertThat(json.error, equalTo("invalid-field-id"))
18         }
19
20         @Test
21         fun `request with valid field id results in field deletion`() {
22                 profile.addField("foo")
23                 val fieldId = profile.getFieldByName("foo")!!.id
24                 addRequestParameter("field", fieldId)
25                 assertThat(json.isSuccess, equalTo(true))
26                 assertThat(profile.getFieldByName("foo"), nullValue())
27                 verify(currentSone).profile = profile
28                 verify(core).touchConfiguration()
29         }
30
31 }