diff --git a/dist/adapter.esm.js b/dist/adapter.esm.js index ac53dcc5a799d7bf699b62d37900fcd547e16280..21ae71a7131ab3865190f32faa788c99be8725c7 100644 --- a/dist/adapter.esm.js +++ b/dist/adapter.esm.js @@ -10,7 +10,7 @@ class Adapter { this.config = config; this.axios = axios; this.validator = new Validator(protocol.schema); - this.auth(); + //this.auth(); } /** @@ -79,6 +79,9 @@ class Adapter { .then((response) => { this.credentials = response.data; return response; + }) + .catch((error) => { + return Promise.reject(error); }); } diff --git a/dist/adapter.js b/dist/adapter.js index f68489df57d3a4b0df762d826f5ccfb2bf918ed0..fb5072a3243af3e41468936bd24b2a1364304384 100644 --- a/dist/adapter.js +++ b/dist/adapter.js @@ -12,7 +12,7 @@ class Adapter { this.config = config; this.axios = axios; this.validator = new Validator(protocol.schema); - this.auth(); + //this.auth(); } /** @@ -81,6 +81,9 @@ class Adapter { .then((response) => { this.credentials = response.data; return response; + }) + .catch((error) => { + return Promise.reject(error); }); } diff --git a/features/adapter_authenticates.feature b/features/adapter_authenticates.feature new file mode 100644 index 0000000000000000000000000000000000000000..c55e27199db07f4ca6145afc63ed0ddf36cad4a9 --- /dev/null +++ b/features/adapter_authenticates.feature @@ -0,0 +1,13 @@ +Feature: Does the adapter authenticate? + When an adapter instance is created it authenticates and receives a token + + Scenario: A token is granted with valid config + Given valid config + When the adapter instance is created + When the auth method is called + Then the adapter credentials are populated + + Scenario: Auth fails with invalid config + Given invalid config + When the adapter instance is created + Then the adapter auth fails \ No newline at end of file diff --git a/features/adapter_works.feature b/features/adapter_works.feature deleted file mode 100644 index a86687a3c53409d9bdd2050084773ec4f68624a8..0000000000000000000000000000000000000000 --- a/features/adapter_works.feature +++ /dev/null @@ -1,10 +0,0 @@ -Feature: Does the adapter work? - The adapter behaves as expected - - Scenario: A token is granted with valid config - Given valid config - Then the adapter credentials are populated - - Scenario: Auth fails with invalid config - Given invalid config - Then the adapter auth fails \ No newline at end of file diff --git a/features/step_definitions/stepdefs.js b/features/step_definitions/stepdefs.js index ececa01d59052882e405d30535dc160ab9fc3e69..926115a60c66e6c80d773c1680719a7d906a88c6 100644 --- a/features/step_definitions/stepdefs.js +++ b/features/step_definitions/stepdefs.js @@ -17,6 +17,8 @@ const { Adapter } = require('../../dist/adapter'); const { GenericProtocol } = require('../../dist/protocol'); Before(function() { + + mockAxios.reset(); mockAxios.onGet( `${mockValidConfig.api}/token`, @@ -35,10 +37,17 @@ Given('valid config', function() { this.config = mockValidConfig }); -Then('the adapter credentials are populated', function() { +When('the adapter instance is created', function() { let mockProtocol = new GenericProtocol(this.schema); let mockAdapter = new Adapter(mockProtocol, this.config); - this.adapter = mockAdapter; + this.adapter = mockAdapter; +}); + +When('the auth method is called', async function() { + await this.adapter.auth(); +}); + +Then(('the adapter credentials are populated'), function() { assert.equal(this.adapter.credentials.token, fixtures.get('response-valid-token').token); }); @@ -47,15 +56,9 @@ Given('invalid config', function() { this.config = mockInvalidConfig; }); -Then('the adapter auth fails', function() { - assert.throws( - function() { - let mockProtocol = new GenericProtocol(mockSchema); - let mockAdapter = new Adapter(mockProtocol, mockInvalidConfig); - this.adapter = mockAdapter; - }, - { - name: "AxiosError" - } - ); +Then('the adapter auth fails', async function() { + this.adapter.auth() + .catch((error) => { + assert.equal(error.response.status, 403); + }); }); \ No newline at end of file diff --git a/src/adapter/index.js b/src/adapter/index.js index 4796b55ed2a881cdc3a831f4e4e2ecb345f1b8d3..8eff44cde3c87e2bb77a4357b143a38db52f5a50 100644 --- a/src/adapter/index.js +++ b/src/adapter/index.js @@ -10,7 +10,6 @@ export class Adapter { this.config = config; this.axios = axios; this.validator = new Validator(protocol.schema); - this.auth(); } /** @@ -79,6 +78,9 @@ export class Adapter { .then((response) => { this.credentials = response.data; return response; + }) + .catch((error) => { + return Promise.reject(error); }); }