adapter_poll.feature 2.68 KB
Newer Older
1 2 3 4 5 6 7
# When the queue contains x messages 
# only mocks the API response 
# Testing how the API behaves with a full queue are defined in the API 

Feature: Can the adapter receive messages?
  The adapter poll method works as expected

8
  Scenario: No messages are received successfully if the queue is empty
9 10 11 12 13 14 15
    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 0 messages
    When the poll method is called
    Then a successful response is returned with 0 messages  

16
  Scenario: 2 messages are received successfully if the queue contains 2 messages
17 18 19 20 21 22 23 24 25
    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 2 messages 
    When the poll method is called
    Then a successful response is returned with 2 messages
    Then the protocol "validate" method is called 2 times
    Then the protocol "decode" method is called 2 times

26
  Scenario: 10 messages are received successfully if the queue contains 10 messages
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    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 10 messages 
    When the poll method is called
    Then a successful response is returned with 10 messages
    Then the protocol "validate" method is called 10 times
    Then the protocol "decode" method is called 10 times

  Scenario: An invalid token returns a forbidden response 
    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 poll method is called 
    Then an error response is returned with status 403
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

  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