diff --git a/package.json b/package.json index f8b9ee6fc0c9a826a59f2c1def55c70f73f81243..46409e37aea5dcefbc5c287840c97b85205e45f0 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "axios": "^1.2.3", "axios-mock-adapter": "^1.21.2", "babel-jest": "^27.4.4", - "backbone-adapter-testsuite": "git+https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-testsuite.git#dd29691a", + "backbone-adapter-testsuite": "git+https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-testsuite.git#1fd8622a", "cross-env": "^7.0.3", "eslint": "^8.4.1", "eslint-config-prettier": "^8.3.0", diff --git a/test/cucumber/adapter/before.steps.js b/test/cucumber/adapter/before.steps.js index fc17ad9d2a9c230fd96280b646e6a6e48cce9247..1ac9d79ba1fdf259d20d7affb9ebff72f45f18cf 100644 --- a/test/cucumber/adapter/before.steps.js +++ b/test/cucumber/adapter/before.steps.js @@ -87,6 +87,7 @@ class TrackedGenericProtocol extends GenericProtocol { } Before(function() { + this.api = mockValidConfig.api; this.schema = mockSchema; this.tracker = tracker; this.recorder = recorder; @@ -98,11 +99,13 @@ Before(function() { TrackedAdapter, TrackedGenericProtocol, }; + this.callCounts = {}; this.protocol = new this.classes.TrackedGenericProtocol(this.schema, services); this.protocol.setupCallTracking(this.recorder, this.tracker); this.protocol.resetTracker(); this.mockAxios = mockAxios; this.mockAxios.reset(); + this.mockAxios.resetHistory(); this.mockAxios.onGet( `${mockValidConfig.api}/token`, diff --git a/test/cucumber/adapter/broadcast.steps.js b/test/cucumber/adapter/broadcast.steps.js index d0206a7fe25f8b51c6d2ae6004dd0825077eb9a5..05a9cd07254c23b92525b18aa55252c9aa0ca7c7 100644 --- a/test/cucumber/adapter/broadcast.steps.js +++ b/test/cucumber/adapter/broadcast.steps.js @@ -12,10 +12,14 @@ When('a mock notify API response is configured to return success', function() { ).reply(200, response); }); -When('a mock notify API response is configured to return an error', function() { +When('a mock notify API response is configured to return a {int} error', function(statusCode) { + const statusMessages = { + 403: 'Token expired', + 503: 'Service unavailable' + }; this.mockAxios.onPost( `${mockValidConfig.api}/notify`, - ).reply(403, { message: 'Token expired' }) + ).reply(statusCode, { message: statusMessages[statusCode] }) }); When('the broadcast method is called', function() { @@ -23,7 +27,7 @@ When('the broadcast method is called', function() { this.message = message; const body = JSON.stringify(message); this.call = this.adapter.broadcast(body); - this.broadcastCallCount = this.adapter.getTrackedCalls('broadcast').length; + this.callCounts.broadcast = this.adapter.getTrackedCalls('broadcast').length; }); When('the broadcast method is called with is_retry on', function() { @@ -31,7 +35,7 @@ When('the broadcast method is called with is_retry on', function() { this.message = message; const body = JSON.stringify(message); this.call = this.adapter.broadcast(body, true); - this.broadcastCallCount = this.adapter.getTrackedCalls('broadcast').length; + this.callCounts.broadcast = this.adapter.getTrackedCalls('broadcast').length; }); Then('the broadcast method was called with is_retry on', function() { @@ -42,5 +46,5 @@ Then('the broadcast method was called with is_retry on', function() { Then('the broadcast method is not called again', function() { let newBroadcastCallCount = this.adapter.getTrackedCalls('broadcast').length; - assert.equal(this.broadcastCallCount, newBroadcastCallCount); + assert.equal(this.callCounts.broadcast, newBroadcastCallCount); }); \ No newline at end of file diff --git a/test/cucumber/adapter/common.steps.js b/test/cucumber/adapter/common.steps.js index c48982e1cb5387f3b272353920ffdd6b8170b301..a0f065c9a98eae23b1993f6ccb63e420434efa88 100644 --- a/test/cucumber/adapter/common.steps.js +++ b/test/cucumber/adapter/common.steps.js @@ -38,4 +38,30 @@ Then('an error response is returned with status {int}', function(expectedStatus) Then('the credentials are deleted', function() { assert.equal(this.adapter.credentials, null); -}); \ No newline at end of file +}); + +Then('the credentials are not deleted', function() { + assert.notEqual(this.adapter.credentials, null); +}); + +When('the {string} method call counts are checked', function(method) { + let newCallCount = this.adapter.getTrackedCalls(method).length; + this.callCounts[method] = newCallCount; +}); + +Then('the {string} method is not called again', function(method) { + let newCallCount = this.adapter.getTrackedCalls(method).length; + assert.equal(this.callCounts[method], newCallCount); +}); + +Then('the total number of calls to {string} was {int}', function(method, expectedCallCount) { + let callCount = this.adapter.getTrackedCalls(method).length; + assert.equal(callCount, expectedCallCount); +}); + +Then('the total number of {string} requests to {string} was {int}', function(method, endpoint, expectedCallCount) { + let url = `${this.api}${endpoint}`; + let requestHistory = this.mockAxios.history[method.toLowerCase()].filter((request) => request.url === url); + assert.equal(requestHistory.length, expectedCallCount); +}); + diff --git a/test/cucumber/adapter/get-authorization-header.steps.js b/test/cucumber/adapter/get-authorization-header.steps.js index af31d0bcd5b4fed0b1cf876ec6742b3087c84f4b..a9fd6525480aca700b27a1e3f4c568308edd759b 100644 --- a/test/cucumber/adapter/get-authorization-header.steps.js +++ b/test/cucumber/adapter/get-authorization-header.steps.js @@ -2,7 +2,9 @@ const assert = require('assert'); const { When, Then } = require('@cucumber/cucumber'); When('the getAuthorizationHeader method is called', function() { - this.call = this.adapter.getAuthorizationHeader() + this.call = this.adapter.getAuthorizationHeader(); + let callCount = this.adapter.getTrackedCalls('getAuthorizationHeader').length; + this.callCounts.getAuthorizationHeader = callCount; }); Then('a headers object is returned containing a bearer token authorization header', function() { @@ -12,4 +14,4 @@ Then('a headers object is returned containing a bearer token authorization heade assert.ok(authHeaderWords[0] === 'Bearer'); assert.ok(authHeaderWords[1] === this.adapter.credentials.token); }); -}); \ No newline at end of file +}); diff --git a/test/cucumber/adapter/poll.steps.js b/test/cucumber/adapter/poll.steps.js index 60fc2c03fc495fe9dcbbf710fd1bbe69d61cc9ea..a2b50a03cf745ebc9d086f1957e2ebd22723c155 100644 --- a/test/cucumber/adapter/poll.steps.js +++ b/test/cucumber/adapter/poll.steps.js @@ -24,14 +24,19 @@ When('a mock receive API response is configured to return {int} messages', funct ).reply(200, response); }); -When('a mock receive API response is configured to return an error', function() { +When('a mock receive API response is configured to return a {int} error', function(statusCode) { + const statusMessages = { + 403: 'Token expired', + 503: 'Service unavailable' + }; this.mockAxios.onGet( `${mockValidConfig.api}/receive`, - ).reply(403, { message: 'Token expired' }) + ).reply(statusCode, { message: statusMessages[statusCode] }) }); When('the poll method is called', function() { this.call = this.adapter.poll(); + this.callCounts.poll = this.adapter.getTrackedCalls('poll').length; }); Then('a successful response is returned with {int} messages', function(xMessages) { @@ -48,7 +53,7 @@ Then('the protocol {string} method is called {int} times', function(method, xInv When('the poll method is called with is_retry on', function() { this.call = this.adapter.poll(true); - this.pollCallCount = this.adapter.getTrackedCalls('poll').length; + this.callCounts.poll = this.adapter.getTrackedCalls('poll').length; }); Then('the poll method was called with is_retry on', function() { @@ -59,5 +64,5 @@ Then('the poll method was called with is_retry on', function() { Then('the poll method is not called again', function() { let newPollCallCount = this.adapter.getTrackedCalls('poll').length; - assert.equal(this.pollCallCount, newPollCallCount); + assert.equal(this.callCounts.poll, newPollCallCount); }); diff --git a/test/cucumber/adapter/publish.steps.js b/test/cucumber/adapter/publish.steps.js index 43648c08503ebee1072e2f4200afd70104a66ea4..e207488c52ec6439bb5b14298e450f689d6c23c6 100644 --- a/test/cucumber/adapter/publish.steps.js +++ b/test/cucumber/adapter/publish.steps.js @@ -12,10 +12,14 @@ When('a mock send API response is configured to return success', function() { ).reply(200, response); }); -When('a mock send API response is configured to return an error', function() { +When('a mock send API response is configured to return a {int} error', function(statusCode) { + const statusMessages = { + 403: 'Token expired', + 503: 'Service unavailable' + }; this.mockAxios.onPost( `${mockValidConfig.api}/send`, - ).reply(403, { message: 'Token expired' }) + ).reply(statusCode, { message: statusMessages[statusCode] }) }); When('the publish method is called', function() { @@ -24,7 +28,7 @@ When('the publish method is called', function() { const topic = message.metadata.destination; const body = JSON.stringify(message); this.call = this.adapter.publish(topic, body); - this.publishCallCount = this.adapter.getTrackedCalls('publish').length; + this.callCounts.publish = this.adapter.getTrackedCalls('publish').length; }); When('the publish method is called with is_retry on', function() { @@ -33,7 +37,7 @@ When('the publish method is called with is_retry on', function() { const topic = message.metadata.destination; const body = JSON.stringify(message); this.call = this.adapter.publish(topic, body, true); - this.publishCallCount = this.adapter.getTrackedCalls('publish').length; + this.callCounts.publish = this.adapter.getTrackedCalls('publish').length; }); Then('the publish method was called with is_retry on', function() { @@ -44,5 +48,5 @@ Then('the publish method was called with is_retry on', function() { Then('the publish method is not called again', function() { let newPublishCallCount = this.adapter.getTrackedCalls('publish').length; - assert.equal(this.publishCallCount, newPublishCallCount); + assert.equal(this.callCounts.publish, newPublishCallCount); }); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 15f970c01e51c2dc031f469197d26700cade779e..38992e1391547ff5c25820daec37175b3f322a65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1318,9 +1318,9 @@ babel-preset-jest@^27.5.1: babel-plugin-jest-hoist "^27.5.1" babel-preset-current-node-syntax "^1.0.0" -"backbone-adapter-testsuite@git+https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-testsuite.git#dd29691a": +"backbone-adapter-testsuite@git+https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-testsuite.git#1fd8622a": version "0.0.1" - resolved "git+https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-testsuite.git#dd29691affa53b04ac65b5fe7dc90df8e0286867" + resolved "git+https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-testsuite.git#1fd8622a217eda84f05c91a9a7181d5cfad0aace" balanced-match@^1.0.0: version "1.0.2"