Skip to content

Commit

Permalink
feat: add more scenarios for pickup protocol (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Baliasnikov committed Aug 3, 2023
1 parent d0c7f49 commit 53fd632
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 35 deletions.
35 changes: 31 additions & 4 deletions src/test/kotlin/features/pickup_message/PickupMessageSteps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<MessagePickupStatusBody>(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)
)
}

Expand All @@ -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<Message>("initialMessage")
Expand All @@ -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<String>("attachmentId"))
),
type = DidcommMessageTypes.PICKUP_MESSAGES_RECEIVED
).from(recipient.recall("peerDid"))
.to(listOf(MEDIATOR_PEER_DID))
.thid(recipient.recall<String>("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),
)
}
}
61 changes: 30 additions & 31 deletions src/test/resources/features/pickup_message/pickup_message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
#
Expand Down

0 comments on commit 53fd632

Please sign in to comment.