From 645b90f64f5133a874025275ac496777ed13162c Mon Sep 17 00:00:00 2001 From: Dan Jones <dan.jones@noc.ac.uk> Date: Wed, 18 Jan 2023 17:04:15 +0000 Subject: [PATCH] refactor: move common steps from auth into common + correct the feature description for getAuthorizationHeader --- .../adapter_get-authorization-header.feature | 4 ++-- test/cucumber/adapter/auth.steps.js | 24 +------------------ test/cucumber/adapter/common.steps.js | 23 +++++++++++++++++- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/features/adapter_get-authorization-header.feature b/features/adapter_get-authorization-header.feature index 59de9a4..554acdf 100644 --- a/features/adapter_get-authorization-header.feature +++ b/features/adapter_get-authorization-header.feature @@ -1,5 +1,5 @@ -Feature: Does the adapter authenticate? - When an adapter instance is created it authenticates and receives a token +Feature: Can the adapter create an authorization header? + The adapter getAuthorizationHeader method works as expected Scenario: getAuthorizationHeader returns a bearer token Given valid config diff --git a/test/cucumber/adapter/auth.steps.js b/test/cucumber/adapter/auth.steps.js index 110d21c..386c5f5 100644 --- a/test/cucumber/adapter/auth.steps.js +++ b/test/cucumber/adapter/auth.steps.js @@ -1,25 +1,8 @@ const assert = require('assert'); -const { Given, When, Then } = require('@cucumber/cucumber'); +const { When, Then } = require('@cucumber/cucumber'); const { fixtures } = require('../../fixtures/server'); -const mockValidConfig = fixtures.get('config-valid'); -const mockInvalidConfig = fixtures.get('config-invalid'); - -const mockSchema = require('../../mock/swagger.json'); -const { Adapter } = require('../../../dist/adapter'); - - -Given('valid config', function() { - this.config = mockValidConfig -}); - -When('the adapter instance is created', function() { - //let mockProtocol = new GenericProtocol(this.schema); - let mockAdapter = new Adapter(this.protocol, this.config); - this.adapter = mockAdapter; -}); - When('the auth method is called', async function() { await this.adapter.auth(); }); @@ -28,11 +11,6 @@ Then('the adapter credentials are populated', function() { assert.equal(this.adapter.credentials.token, fixtures.get('response-valid-token').token); }); -Given('invalid config', function() { - this.schema = mockSchema; - this.config = mockInvalidConfig; -}); - Then('the adapter auth fails', function() { this.adapter.auth() .catch((error) => { diff --git a/test/cucumber/adapter/common.steps.js b/test/cucumber/adapter/common.steps.js index 5236e90..3979c10 100644 --- a/test/cucumber/adapter/common.steps.js +++ b/test/cucumber/adapter/common.steps.js @@ -1,5 +1,26 @@ const assert = require('assert'); -const { When, Then } = require('@cucumber/cucumber'); +const { Given, When, Then } = require('@cucumber/cucumber'); + +const { fixtures } = require('../../fixtures/server'); + +const mockValidConfig = fixtures.get('config-valid'); +const mockInvalidConfig = fixtures.get('config-invalid'); +const mockSchema = require('../../mock/swagger.json'); +const { Adapter } = require('../../../dist/adapter'); + +Given('valid config', function() { + this.config = mockValidConfig +}); + +Given('invalid config', function() { + this.schema = mockSchema; + this.config = mockInvalidConfig; +}); + +When('the adapter instance is created', function() { + let mockAdapter = new Adapter(this.protocol, this.config); + this.adapter = mockAdapter; +}); Then('a successful response is returned with status {int}', function(expectedStatus) { this.call -- GitLab