diff --git a/src/test/kotlin/features/pickup_message/PickupMessageSteps.kt b/src/test/kotlin/features/pickup_message/PickupMessageSteps.kt index b29abcd..2a59d92 100644 --- a/src/test/kotlin/features/pickup_message/PickupMessageSteps.kt +++ b/src/test/kotlin/features/pickup_message/PickupMessageSteps.kt @@ -80,13 +80,13 @@ class PickupMessageSteps { ) } - @Then("Mediator responds with a status message detailing the queued messages of {actor}") - fun mediatorRespondsWithAStatusMessageDetailingTheQueuedMessagesOfRecipient(recipient: Actor) { + @Then("Mediator responds with a status message with {int} queued messages of {actor}") + fun mediatorRespondsWithAStatusMessageDetailingTheQueuedMessagesOfRecipient(numberOfMessages: Int, recipient: Actor) { val didcommResponse = recipient.usingAbilityTo(CommunicateViaDidcomm::class.java).unpackLastDidcommMessage() val pickupStatus = Json.decodeFromString(didcommResponse.body.toJSONString()) recipient.attemptsTo( Ensure.that(pickupStatus.recipient_did).isEqualTo(recipient.recall("peerDid")), - Ensure.that(pickupStatus.message_count).isGreaterThan(0) + Ensure.that(pickupStatus.message_count).isEqualTo(numberOfMessages) ) } @@ -109,7 +109,7 @@ class PickupMessageSteps { @Then("Mediator delivers message of {actor} to {actor}") fun mediatorDeliversMessageOfSenderToRecipient(sender: Actor, recipient: Actor) { val didcommResponse = recipient.usingAbilityTo(CommunicateViaDidcomm::class.java).unpackLastDidcommMessage() - val encryptedMessage: Attachment.Data.Base64 = didcommResponse.attachments!!.first().data as Attachment.Data.Base64 + val encryptedMessage = didcommResponse.attachments!!.first().data as Attachment.Data.Base64 val decryptedMessage = Base64.getUrlDecoder().decode(encryptedMessage.base64).decodeToString() val achievedMessage = recipient.usingAbilityTo(CommunicateViaDidcomm::class.java).unpackMessage(decryptedMessage) val initialMessage = sender.recall("initialMessage") @@ -120,5 +120,32 @@ class PickupMessageSteps { Ensure.that(achievedMessage.from.toString()).isEqualTo(initialMessage.from.toString()), Ensure.that(achievedMessage.to!!.first()).isEqualTo(initialMessage.to!!.first()) ) + recipient.remember("deliveryThid", didcommResponse.thid!!) + recipient.remember("attachmentId", didcommResponse.attachments!!.first().id) + } + + @When("{actor} sends a messages-received message") + fun recipientSendsAMessagesReceivedMessage(recipient: Actor) { + val messagesReceivedMessage = Message.builder( + id = idGeneratorDefault(), + body = mapOf( + "message_id_list" to listOf(recipient.recall("attachmentId")) + ), + type = DidcommMessageTypes.PICKUP_MESSAGES_RECEIVED + ).from(recipient.recall("peerDid")) + .to(listOf(MEDIATOR_PEER_DID)) + .thid(recipient.recall("deliveryThid")) + .build() + recipient.attemptsTo( + SendDidcommMessage(messagesReceivedMessage) + ) + } + + @Then("Mediator responds that there are no messages from {actor} to {actor}") + fun mediatorRespondsThatThereAreNoMessagesFrom(sender: Actor, recipient: Actor) { + val didcommResponse = recipient.usingAbilityTo(CommunicateViaDidcomm::class.java).unpackLastDidcommMessage() + recipient.attemptsTo( + Ensure.that(didcommResponse.attachments!!.size).isEqualTo(0), + ) } } diff --git a/src/test/resources/features/pickup_message/pickup_message.feature b/src/test/resources/features/pickup_message/pickup_message.feature index 3d3d43e..6d919c8 100644 --- a/src/test/resources/features/pickup_message/pickup_message.feature +++ b/src/test/resources/features/pickup_message/pickup_message.feature @@ -18,16 +18,16 @@ Feature: Pickup message protocol Given Sender sent a forward message to Recipient When Recipient sends a status-request message - Then Mediator responds with a status message detailing the queued messages of Recipient + Then Mediator responds with a status message with 1 queued messages of Recipient + + Scenario: Recipient sends a status-request message with no forward message available + + Recipient asks mediator if any forward messages are available for him, + Mediator should answer that there are no messages available for delivery. + + When Recipient sends a status-request message + Then Mediator responds with a status message with 0 queued messages of Recipient -# Scenario: Recipient sends a status-request message with no forward message available -# -# Recipient asks mediator if any forward messages are available for him, -# Mediator should answer that there are no messages available for delivery. -# -# When Recipient sends a status-request message -# Then Mediator responds with a status message detailing the queued messages of Recipient -# Scenario: Recipient sends a delivery-request message with one forward message available Recipient is trying to get one forward message from Mediator, @@ -36,28 +36,27 @@ Feature: Pickup message protocol Given Sender sent a forward message to Recipient When Recipient sends a delivery-request message Then Mediator delivers message of Sender to Recipient -# -# Scenario: Recipient sends a delivery-request message with no available forward messages -# -# Recipient is trying to request delivery when no messages are available, -# Mediator should respond with a delivery response with no attachments. -# -# When Recipient sends a delivery-request message -# Then Mediator responds that there are none messages from Sender to Recipient -# -# Scenario: Recipient sends a delivery-request and confirms that messages were received -# -# Recipient acknowledges and confirms that they received the message -# using `messages-received` message after which mediator should clear its messages queue for Recipient -# and respond with `status` message that should not contain any messages anymore. -# -# Given Recipient sends a mediate request message to the mediator -# And Mediator responds to Recipient with mediate grant message -# And Sender sent a forward message to Recipient -# And Recipient sends a delivery-request message -# And Mediator delivers message of Sender to Recipient -# When Recipient sends a messages-received message -# Then Mediator responds with a status message with no messages available + + Scenario: Recipient sends a delivery-request message with no available forward messages + + Recipient is trying to request delivery when no messages are available, + Mediator should respond with a delivery response with no attachments. + + When Recipient sends a delivery-request message + Then Mediator responds that there are no messages from Sender to Recipient + + Scenario: Recipient sends a delivery-request and confirms that messages were received + + Recipient acknowledges and confirms that they received the message + using `messages-received` message after which mediator should clear its messages queue for Recipient + and respond with `status` message that should not contain any messages anymore. + + Given Sender sent a forward message to Recipient + And Recipient sends a delivery-request message + And Mediator delivers message of Sender to Recipient + When Recipient sends a messages-received message + When Recipient sends a status-request message + Then Mediator responds with a status message with 0 queued messages of Recipient # # Scenario Outline: Recipient limits number of messages for delivery #