Unverified Commit bb722d6b authored by Dan Jones's avatar Dan Jones
Browse files

test: add tests for adapter broadcast method

parent b3e0ef86
Feature: Can the adapter broadcast messages?
The adapter publish method works as expected
Scenario: A message can be published successfully
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 success
When the broadcast method is called
Then a successful response is returned with status 200
Scenario: A failed publish returns a 403
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
\ No newline at end of file
......@@ -60,8 +60,8 @@ Before(function() {
this.tracker = tracker;
this.recorder = recorder;
let services = {
recorder: this.recorder,
tracker: this.tracker
recorder,
tracker
};
this.protocol = new TrackedGenericProtocol(this.schema, services);
this.protocol.resetTracker();
......
const assert = require('assert');
const { When, Then } = require('@cucumber/cucumber');
const { fixtures } = require('../../fixtures/server');
const mockValidConfig = fixtures.get('config-valid');
When('a mock notify API response is configured to return success', function() {
const response = {};
this.mockAxios.onPost(
`${mockValidConfig.api}/notify`,
).reply(200, response);
});
When('a mock notify API response is configured to return an error', function() {
this.mockAxios.onPost(
`${mockValidConfig.api}/notify`,
).reply(403, { message: 'Token expired' })
});
When('the broadcast method is called', function() {
const message = fixtures.get('message-vehicle-status');
this.message = message;
const body = JSON.stringify(message);
this.call = this.adapter.broadcast(body);
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment