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/03 03:58:37 UTC

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

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



##########
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
##########
@@ -196,6 +196,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(TIME_FORMATTER)}",
+           |                        "types": ["Mailbox"]
+           |                    },
+           |                    {
+           |                        "id": "${pushSubscription2.id.serialise}",
+           |                        "deviceClientId": "12c6d087",
+           |                        "expires": "${UTCDate(pushSubscription2.expires.value).asUTC.format(TIME_FORMATTER)}",
+           |                        "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(TIME_FORMATTER)}",
+           |                        "types": ["Mailbox"]
+           |                    },
+           |                    {
+           |                        "id": "${pushSubscription2.id.serialise}",
+           |                        "deviceClientId": "12c6d087",
+           |                        "expires": "${UTCDate(pushSubscription2.expires.value).asUTC.format(TIME_FORMATTER)}",
+           |                        "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:
       Following Tung's remark, should we have a test then showing we get the verification code property in the get when the sub has been 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