From 74a0fd7b410fe8495840b2a4d5e2677915fa423a Mon Sep 17 00:00:00 2001
From: Dan Jones <dan.jones@noc.ac.uk>
Date: Mon, 20 Feb 2023 15:19:05 +0000
Subject: [PATCH] test: add tests for broadcast and poll retries

Retry once on 403 with new credentials
---
 features/adapter_broadcast.feature | 23 ++++++++++++++++++++++-
 features/adapter_poll.feature      | 21 +++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/features/adapter_broadcast.feature b/features/adapter_broadcast.feature
index e37344a..34fea13 100644
--- a/features/adapter_broadcast.feature
+++ b/features/adapter_broadcast.feature
@@ -15,4 +15,25 @@ Feature: Can the adapter broadcast messages?
     When the auth method is called
     When a mock notify API response is configured to return an error
     When the broadcast method is called
-    Then an error response is returned with status 403
\ No newline at end of file
+    Then an error response is returned with status 403
+
+  Scenario: On 403 the message is retried once with new credentials 
+    Given valid config 
+    When the adapter instance is created 
+    When the auth method is called 
+    When a mock notify API response is configured to return an error 
+    When the broadcast method is called 
+    Then an error response is returned with status 403 
+    Then the credentials are deleted
+    Then the broadcast method was called with is_retry on
+    Then the getAuthorizationHeader method is called 
+    
+  Scenario: On a retried 403 the message is not retried again
+    Given valid config 
+    When the adapter instance is created 
+    When the auth method is called 
+    When a mock notify API response is configured to return an error 
+    When the broadcast method is called with is_retry on
+    Then an error response is returned with status 403
+    Then the credentials are deleted 
+    Then the broadcast method is not called again
diff --git a/features/adapter_poll.feature b/features/adapter_poll.feature
index ff05566..1a860b7 100644
--- a/features/adapter_poll.feature
+++ b/features/adapter_poll.feature
@@ -40,3 +40,24 @@ Feature: Can the adapter receive messages?
     When a mock receive API response is configured to return an error
     When the poll method is called 
     Then an error response is returned with status 403
+
+  Scenario: On 403 the message is retried once with new credentials 
+    Given valid config 
+    When the adapter instance is created 
+    When the auth method is called 
+    When a mock receive API response is configured to return an error 
+    When the publish method is called 
+    Then an error response is returned with status 403 
+    Then the credentials are deleted
+    Then the receive method was called with is_retry on
+    Then the getAuthorizationHeader method is called 
+    
+  Scenario: On a retried 403 the message is not retried again
+    Given valid config 
+    When the adapter instance is created 
+    When the auth method is called 
+    When a mock receive API response is configured to return an error 
+    When the receive method is called with is_retry on
+    Then an error response is returned with status 403
+    Then the credentials are deleted 
+    Then the receive method is not called again
-- 
GitLab