diff --git a/features/adapter_broadcast.feature b/features/adapter_broadcast.feature new file mode 100644 index 0000000000000000000000000000000000000000..e37344afab59cc9f6cea2ce9be74ba7bcf8ba9de --- /dev/null +++ b/features/adapter_broadcast.feature @@ -0,0 +1,18 @@ +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 diff --git a/test/cucumber/adapter/before.steps.js b/test/cucumber/adapter/before.steps.js index 9471285eb547e173f243c4af1a42add30edf807f..90505ec27764a1b7c0569cb155f6b1e89122c6bb 100644 --- a/test/cucumber/adapter/before.steps.js +++ b/test/cucumber/adapter/before.steps.js @@ -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(); diff --git a/test/cucumber/adapter/broadcast.steps.js b/test/cucumber/adapter/broadcast.steps.js new file mode 100644 index 0000000000000000000000000000000000000000..38e495ddb4d3264c5dab2df204c9abca03a557f6 --- /dev/null +++ b/test/cucumber/adapter/broadcast.steps.js @@ -0,0 +1,26 @@ +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