You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/11/02 10:57:12 UTC

[GitHub] [james-project] chibenwa commented on a change in pull request #728: JAMES-3539 Implement PushSubscription/get

chibenwa commented on a change in pull request #728:
URL: https://github.com/apache/james-project/pull/728#discussion_r740943804



##########
File path: server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/PushSubscriptionSetMethodContract.scala
##########
@@ -170,6 +170,306 @@ trait PushSubscriptionSetMethodContract {
            |}""".stripMargin)
   }
 
+  @Test
+  def getShouldReturnEmptyWhenNone(): Unit = {
+    val request: String =
+      """{
+        |    "using": ["urn:ietf:params:jmap:core"],
+        |    "methodCalls": [ [ "PushSubscription/get", { }, "c1" ] ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [
+           |        [
+           |            "PushSubscription/get",
+           |            {
+           |                "list": []
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def getShouldReturnAllRecords(server: GuiceJamesServer): Unit = {
+    val probe = server.getProbe(classOf[PushSubscriptionProbe])
+    val pushSubscription1 = probe
+      .createPushSubscription(username = BOB,
+        url = PushSubscriptionServerURL(new URL("https://example.com/push/?device=X8980fc&client=12c6d086")),
+        deviceId = DeviceClientId("12c6d086"),
+        types = Seq(MailboxTypeName))
+    val pushSubscription2 = probe
+      .createPushSubscription(username = BOB,
+        url = PushSubscriptionServerURL(new URL("https://example.com/push/?device=X8980fc&client=12c6d086")),
+        deviceId = DeviceClientId("12c6d087"),
+        types = Seq(EmailTypeName))
+
+    val request: String =
+      """{
+        |    "using": ["urn:ietf:params:jmap:core"],
+        |    "methodCalls": [ [ "PushSubscription/get", { }, "c1" ] ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [
+           |        [
+           |            "PushSubscription/get",
+           |            {
+           |                "list": [
+           |                    {
+           |                        "id": "${pushSubscription1.id.serialise}",
+           |                        "deviceClientId": "12c6d086",
+           |                        "expires": "${UTCDate(pushSubscription1.expires.value).asUTC.format(UTC_DATE_FORMAT)}",
+           |                        "types": ["Mailbox"]
+           |                    },
+           |                    {
+           |                        "id": "${pushSubscription2.id.serialise}",
+           |                        "deviceClientId": "12c6d087",
+           |                        "expires": "${UTCDate(pushSubscription2.expires.value).asUTC.format(UTC_DATE_FORMAT)}",
+           |                        "types": ["Email"]
+           |                    }
+           |                ]
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def getByIdShouldReturnRecords(server: GuiceJamesServer): Unit = {
+    val probe = server.getProbe(classOf[PushSubscriptionProbe])
+    val pushSubscription1 = probe
+      .createPushSubscription(username = BOB,
+        url = PushSubscriptionServerURL(new URL("https://example.com/push/?device=X8980fc&client=12c6d086")),
+        deviceId = DeviceClientId("12c6d086"),
+        types = Seq(MailboxTypeName))
+    val pushSubscription2 = probe
+      .createPushSubscription(username = BOB,
+        url = PushSubscriptionServerURL(new URL("https://example.com/push/?device=X8980fc&client=12c6d086")),
+        deviceId = DeviceClientId("12c6d087"),
+        types = Seq(EmailTypeName))
+    val pushSubscription3 = probe
+      .createPushSubscription(username = BOB,
+        url = PushSubscriptionServerURL(new URL("https://example.com/push/?device=X8980fc&client=12c6d086")),
+        deviceId = DeviceClientId("12c6d088"),
+        types = Seq(EmailTypeName))
+
+    val request: String =
+      s"""{
+        |    "using": ["urn:ietf:params:jmap:core"],
+        |    "methodCalls": [ [ "PushSubscription/get", {
+        |       "ids": ["${pushSubscription1.id.serialise}", "${pushSubscription2.id.serialise}"]
+        |     }, "c1" ] ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [
+           |        [
+           |            "PushSubscription/get",
+           |            {
+           |                "list": [
+           |                    {
+           |                        "id": "${pushSubscription1.id.serialise}",
+           |                        "deviceClientId": "12c6d086",
+           |                        "expires": "${UTCDate(pushSubscription1.expires.value).asUTC.format(UTC_DATE_FORMAT)}",
+           |                        "types": ["Mailbox"]
+           |                    },
+           |                    {
+           |                        "id": "${pushSubscription2.id.serialise}",
+           |                        "deviceClientId": "12c6d087",
+           |                        "expires": "${UTCDate(pushSubscription2.expires.value).asUTC.format(UTC_DATE_FORMAT)}",
+           |                        "types": ["Email"]
+           |                    }
+           |                ]
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def getByIdShouldReturnEmptyWhenEmpty(server: GuiceJamesServer): Unit = {
+    val probe = server.getProbe(classOf[PushSubscriptionProbe])
+    val pushSubscription1 = probe
+      .createPushSubscription(username = BOB,
+        url = PushSubscriptionServerURL(new URL("https://example.com/push/?device=X8980fc&client=12c6d086")),
+        deviceId = DeviceClientId("12c6d086"),
+        types = Seq(MailboxTypeName))
+
+    val request: String =
+      s"""{
+        |    "using": ["urn:ietf:params:jmap:core"],
+        |    "methodCalls": [ [ "PushSubscription/get", {
+        |       "ids": []
+        |     }, "c1" ] ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [
+           |        [
+           |            "PushSubscription/get",
+           |            {
+           |                "list": []
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def getByIdShouldReturnNotFound(): Unit = {
+    val request: String =
+      s"""{
+        |    "using": ["urn:ietf:params:jmap:core"],
+        |    "methodCalls": [ [ "PushSubscription/get", {
+        |       "ids": ["notFound"]
+        |     }, "c1" ] ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [
+           |        [
+           |            "PushSubscription/get",
+           |            {
+           |                "notFound": ["notFound"],
+           |                "list": []
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def getShouldFilterProperties(server: GuiceJamesServer): Unit = {
+    val probe = server.getProbe(classOf[PushSubscriptionProbe])
+    val pushSubscription1 = probe
+      .createPushSubscription(username = BOB,
+        url = PushSubscriptionServerURL(new URL("https://example.com/push/?device=X8980fc&client=12c6d086")),
+        deviceId = DeviceClientId("12c6d086"),
+        types = Seq(MailboxTypeName))
+    val pushSubscription2 = probe
+      .createPushSubscription(username = BOB,
+        url = PushSubscriptionServerURL(new URL("https://example.com/push/?device=X8980fc&client=12c6d086")),
+        deviceId = DeviceClientId("12c6d087"),
+        types = Seq(EmailTypeName))
+
+    val request: String =
+      """{
+        |    "using": ["urn:ietf:params:jmap:core"],
+        |    "methodCalls": [ [ "PushSubscription/get", { "properties": ["types"] }, "c1" ] ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [
+           |        [
+           |            "PushSubscription/get",
+           |            {
+           |                "list": [
+           |                    {
+           |                        "id": "${pushSubscription1.id.serialise}",
+           |                        "types": ["Mailbox"]
+           |                    },
+           |                    {
+           |                        "id": "${pushSubscription2.id.serialise}",
+           |                        "types": ["Email"]
+           |                    }
+           |                ]
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+

Review comment:
       No need IMO.
   
   verificationCode is always a valid property, but the underlying data is null if not yet validated. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org