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:51:29 UTC

[GitHub] [james-project] chibenwa commented on a change in pull request #725: JAMES-3539 PushSubscription/set update types

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



##########
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
##########
@@ -912,6 +914,245 @@ trait PushSubscriptionSetMethodContract {
     assertThat(probe.retrievePushSubscription(BOB, pushSubscription.id).validated).isTrue
   }
 
+  @Test
+  def updateShouldModifyTypes(server: GuiceJamesServer): Unit = {
+    val probe = server.getProbe(classOf[PushSubscriptionProbe])
+    val pushSubscription = 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/set",
+        |        {
+        |            "update": {
+        |                "${pushSubscription.id.serialise}": {
+        |                  "types": ["Mailbox", "Email"]
+        |                }
+        |              }
+        |        },
+        |        "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/set",
+           |            {
+           |                "updated": {
+           |                    "${pushSubscription.id.serialise}": {}
+           |                }
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+
+    assertThat(probe.retrievePushSubscription(BOB, pushSubscription.id).types.asJava)
+      .containsExactlyInAnyOrder(MailboxTypeName, EmailTypeName)
+  }
+
+  @Test
+  def updateShouldRejectUnknownTypes(server: GuiceJamesServer): Unit = {
+    val probe = server.getProbe(classOf[PushSubscriptionProbe])
+    val pushSubscription = 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/set",
+        |        {
+        |            "update": {
+        |                "${pushSubscription.id.serialise}": {
+        |                  "types": ["Mailbox", "Unknown"]
+        |                }
+        |              }
+        |        },
+        |        "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/set",
+           |            {
+           |                "notUpdated":{
+           |                    "${pushSubscription.id.serialise}":{
+           |                        "type":"invalidArguments",
+           |                        "description":"Unknown typeName Unknown",
+           |                        "properties":["types"]
+           |                    }
+           |                }
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def updateShouldRejectBadTypes(server: GuiceJamesServer): Unit = {
+    val probe = server.getProbe(classOf[PushSubscriptionProbe])
+    val pushSubscription = 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/set",
+        |        {
+        |            "update": {
+        |                "${pushSubscription.id.serialise}": {
+        |                  "types": 36
+        |                }
+        |              }
+        |        },
+        |        "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/set",
+           |            {
+           |                "notUpdated":{
+           |                    "${pushSubscription.id.serialise}":{
+           |                        "type":"invalidArguments",
+           |                        "description":"Expecting an array of JSON strings as an argument",
+           |                        "properties":["types"]
+           |                    }
+           |                }
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def updateShouldRejectBadType(server: GuiceJamesServer): Unit = {
+    val probe = server.getProbe(classOf[PushSubscriptionProbe])
+    val pushSubscription = 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/set",
+        |        {
+        |            "update": {
+        |                "${pushSubscription.id.serialise}": {
+        |                  "types": ["Email", 36]
+        |                }
+        |              }
+        |        },
+        |        "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/set",
+           |            {
+           |                "notUpdated":{
+           |                    "${pushSubscription.id.serialise}":{
+           |                        "type":"invalidArguments",
+           |                        "description":"Expecting an array of JSON strings as an argument",
+           |                        "properties":["types"]
+           |                    }
+           |                }
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+

Review comment:
       Where did you get that?
   
   I just re-read the spec and cannot find anything related to this.




-- 
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