Add test for get notifications ajax page
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / GetStatusAjaxPageTest.kt
index 1b0df13..0d8cb54 100644 (file)
@@ -23,15 +23,16 @@ import org.junit.Before
 import org.junit.Test
 import org.mockito.ArgumentMatchers.any
 import org.mockito.ArgumentMatchers.anyLong
+import java.util.TimeZone
 
 /**
  * Unit test for [GetStatusAjaxPage].
  */
-class GetStatusAjaxPageTest: JsonPageTest() {
+class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = false, needsFormPassword = false) {
 
        private val timeTextConverter = mock<TimeTextConverter>()
        private val l10nFilter = mock<L10nFilter>()
-       override var page: JsonPage = GetStatusAjaxPage(webInterface, elementLoader, timeTextConverter, l10nFilter)
+       override var page: JsonPage = GetStatusAjaxPage(webInterface, elementLoader, timeTextConverter, l10nFilter, TimeZone.getTimeZone("UTC"))
 
        @Before
        fun setupTimeTextConverter() {
@@ -40,21 +41,6 @@ class GetStatusAjaxPageTest: JsonPageTest() {
        }
 
        @Test
-       fun `page returns correct path`() {
-               assertThat(page.path, equalTo("getStatus.ajax"))
-       }
-
-       @Test
-       fun `page does not require form password`() {
-               assertThat(page.needsFormPassword(), equalTo(false))
-       }
-
-       @Test
-       fun `page does not require login`() {
-               assertThat(page.requiresLogin(), equalTo(false))
-       }
-
-       @Test
        fun `page returns correct attribute “loggedIn” if sone is logged in`() {
                assertThat(json.get("loggedIn").asText(), equalTo("true"))
        }
@@ -68,9 +54,9 @@ class GetStatusAjaxPageTest: JsonPageTest() {
        @Test
        fun `page returns options for sone if sone is logged in`() {
                assertThat(json.get("options").toMap(), allOf(
-                               hasEntry("ShowNotification/NewSones", "false"),
-                               hasEntry("ShowNotification/NewPosts", "false"),
-                               hasEntry("ShowNotification/NewReplies", "false")
+                               hasEntry("ShowNotification/NewSones", "true"),
+                               hasEntry("ShowNotification/NewPosts", "true"),
+                               hasEntry("ShowNotification/NewReplies", "true")
                ))
        }
 
@@ -89,7 +75,7 @@ class GetStatusAjaxPageTest: JsonPageTest() {
        @Test
        fun `page returns a sones object with the current sone if not other sones parameter is given`() {
                assertThat(json.get("sones").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
-                               mapOf<String, String?>("id" to "soneId", "name" to "Sone_Id", "local" to "true", "status" to "idle", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 01:00:01", "lastUpdatedText" to "1000")
+                               mapOf<String, String?>("id" to "soneId", "name" to "Sone_Id", "local" to "true", "status" to "idle", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:01", "lastUpdatedText" to "1000")
                ))
        }
 
@@ -99,9 +85,9 @@ class GetStatusAjaxPageTest: JsonPageTest() {
                addSone(deepMock<Sone>().mock("sone3", "Sone 3", true, 3000, inserting))
                addRequestParameter("soneIds", "sone1,sone2,sone3")
                assertThat(json.get("sones").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
-                               mapOf<String, String?>("id" to "soneId", "name" to "Sone_Id", "local" to "true", "status" to "idle", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 01:00:01", "lastUpdatedText" to "1000"),
-                               mapOf("id" to "sone1", "name" to "Sone 1", "local" to "false", "status" to "downloading", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 01:00:02", "lastUpdatedText" to "2000"),
-                               mapOf("id" to "sone3", "name" to "Sone 3", "local" to "true", "status" to "inserting", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 01:00:03", "lastUpdatedText" to "3000")
+                               mapOf<String, String?>("id" to "soneId", "name" to "Sone_Id", "local" to "true", "status" to "idle", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:01", "lastUpdatedText" to "1000"),
+                               mapOf("id" to "sone1", "name" to "Sone 1", "local" to "false", "status" to "downloading", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:02", "lastUpdatedText" to "2000"),
+                               mapOf("id" to "sone3", "name" to "Sone 3", "local" to "true", "status" to "inserting", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:03", "lastUpdatedText" to "3000")
                ))
        }
 
@@ -111,7 +97,7 @@ class GetStatusAjaxPageTest: JsonPageTest() {
                                mock<Notification>().apply { whenever(this.createdTime).thenReturn(2000) },
                                mock<Notification>().apply { whenever(this.createdTime).thenReturn(1000) }
                )
-               addNotification(*notifications.toTypedArray())
+               notifications.forEachIndexed { index, notification -> addNotification(notification, "notification$index")}
                assertThat(json.get("notificationHash").asInt(), equalTo(notifications.sortedBy { it.createdTime }.hashCode()))
        }