From 59c8684209b907b52ca099f7bfdccfce635a5946 Mon Sep 17 00:00:00 2001 From: Calem Roelofs Date: Fri, 19 Apr 2024 13:45:45 +0200 Subject: [PATCH] Update tests to fix breaking changes --- test/commands/api/create.test.js | 38 +++++------ test/commands/api/delete.test.js | 16 ++--- test/commands/api/get.test.js | 26 ++++---- test/commands/api/publish.test.js | 42 ++++++------ test/commands/api/setdefault.test.js | 4 +- test/commands/api/unpublish.test.js | 4 +- test/commands/api/update.test.js | 48 +++++++------- .../api/validate/download-rules.test.js | 35 +++++----- test/commands/api/validate/index.test.js | 24 +++---- test/commands/api/validate/local.test.js | 16 ++--- test/commands/configure.test.js | 47 +++++++++----- test/commands/domain/create.test.js | 34 +++++----- test/commands/domain/delete.test.js | 64 +++++++++++-------- test/commands/domain/get.test.js | 20 +++--- test/commands/domain/publish.test.js | 4 +- test/commands/domain/setdefault.test.js | 4 +- test/commands/domain/unpublish.test.js | 4 +- test/commands/domain/update.test.js | 48 +++++++------- test/commands/integration/create.test.js | 8 +-- test/commands/integration/delete.test.js | 6 +- test/commands/integration/execute.test.js | 6 +- test/commands/integration/get.test.js | 6 +- test/commands/integration/list.test.js | 8 +-- test/commands/integration/update.test.js | 4 +- test/commands/project/api/add.test.js | 8 +-- test/commands/project/api/remove.test.js | 8 +-- test/commands/project/create.test.js | 18 +++--- test/commands/project/delete.test.js | 4 +- test/commands/project/domain/add.test.js | 8 +-- test/commands/project/domain/remove.test.js | 8 +-- test/commands/project/get.test.js | 12 ++-- test/commands/project/list.test.js | 13 +--- test/commands/project/member/list.test.js | 6 +- test/support/config.test.js | 10 +-- 34 files changed, 315 insertions(+), 296 deletions(-) diff --git a/test/commands/api/create.test.js b/test/commands/api/create.test.js index d3e1c995..10bb26f0 100644 --- a/test/commands/api/create.test.js +++ b/test/commands/api/create.test.js @@ -52,7 +52,7 @@ describe('invalid api:create file issues', () => { describe('invalid api:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(200) @@ -68,7 +68,7 @@ describe('invalid api:create', () => { .it('runs api:create with API version already exists') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(500, '{ "code": 500, "message": "Error"}') @@ -78,7 +78,7 @@ describe('invalid api:create', () => { .it('runs api:create with error retrieving APIs') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(200) @@ -92,7 +92,7 @@ describe('invalid api:create', () => { .it('runs api:create with error on retrieving API version') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/orgNotExist/api') .reply(404) @@ -108,7 +108,7 @@ describe('invalid api:create', () => { .it('runs api:create with org that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/overLimitApi') .reply(404) @@ -124,7 +124,7 @@ describe('invalid api:create', () => { .it('runs api:create with org that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/orgNotExist/api') .reply(404) @@ -146,7 +146,7 @@ describe('invalid api:create', () => { .it('error shows as create failed and publish and setdefault are not executed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -167,7 +167,7 @@ describe('invalid api:create', () => { .it('error shows as publish failed and setdefault is not executed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -194,7 +194,7 @@ describe('invalid api:create', () => { describe('valid api:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -211,7 +211,7 @@ describe('valid api:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -232,7 +232,7 @@ describe('valid api:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -253,7 +253,7 @@ describe('valid api:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -285,7 +285,7 @@ describe('valid api:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -313,7 +313,7 @@ describe('valid api:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -335,7 +335,7 @@ describe('valid api:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -356,7 +356,7 @@ describe('valid api:create', () => { expect(ctx.stdout).to.contains('Created API \'org/api\'') }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(404) @@ -380,7 +380,7 @@ describe('valid api:create', () => { describe('valid create new version with api:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(200) @@ -401,7 +401,7 @@ describe('valid create new version with api:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api') .reply(200) @@ -428,7 +428,7 @@ describe('valid create new version with api:create', () => { describe('valid create new version with api:create using invalid swaggerhub url', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: `${shubUrl}/v1` })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: `${shubUrl}/v1` })) .stdout() .command(['api:create', 'org/api', '--file=test/resources/valid_api.yaml']) .exit(2) diff --git a/test/commands/api/delete.test.js b/test/commands/api/delete.test.js index 31c30429..711f7c90 100644 --- a/test/commands/api/delete.test.js +++ b/test/commands/api/delete.test.js @@ -7,7 +7,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid api:delete', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .delete('/org/api/1.0.0') .reply(200) @@ -19,8 +19,8 @@ describe('valid api:delete', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .stub(inquirer, 'prompt', () => Promise.resolve({ answer: true })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .stub(inquirer, 'prompt', stub => stub.returns(Promise.resolve({ answer: true }))) .nock(`${shubUrl}/apis`, api => api .delete('/org/api') .reply(200) @@ -32,14 +32,14 @@ describe('valid api:delete', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .stub(inquirer, 'prompt', () => Promise.resolve({ answer: false })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .stub(inquirer, 'prompt', stub => stub.returns(Promise.resolve({ answer: false }))) .stdout() .command(['api:delete', apiId]) .it('runs api:delete on API, enter \'No\' on confirmation') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .delete('/org/api') .reply(200) @@ -51,7 +51,7 @@ describe('valid api:delete', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .delete('/org/api') .reply(200) @@ -78,7 +78,7 @@ describe('invalid api:delete command issues', () => { describe('api:delete error responses', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .delete('/org/api') .reply(404, `{ "code": 404, "message": "Unknown API ${apiId}"}`) diff --git a/test/commands/api/get.test.js b/test/commands/api/get.test.js index 137738e0..08f4e6e2 100644 --- a/test/commands/api/get.test.js +++ b/test/commands/api/get.test.js @@ -27,7 +27,7 @@ describe('invalid identifier on apis:get', () => { describe('valid identifier on api:get', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${validIdentifier}`) .reply(200, jsonResponse) @@ -39,7 +39,7 @@ describe('valid identifier on api:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${validIdentifier}`) .reply(200, jsonResponse) @@ -51,7 +51,7 @@ describe('valid identifier on api:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/yaml' } }, api => api .get(`/${validIdentifier}`) .reply(200, yaml.dump(jsonResponse)) @@ -63,7 +63,7 @@ describe('valid identifier on api:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', api => api .get('/org1/api2/settings/default') .reply(200, { version: '1.0.0' }) @@ -79,7 +79,7 @@ describe('valid identifier on api:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', api => api .get('/org1/api2/settings/default') .reply(200, { version: '1.0.0' }) @@ -95,7 +95,7 @@ describe('valid identifier on api:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/yaml' } }, api => api .get(`/${validIdentifier}?resolved=true`) .reply(200, yaml.dump(jsonResponse)) @@ -107,7 +107,7 @@ describe('valid identifier on api:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', api => api .get('/org1/api2/settings/default') .reply(200, { version: '1.0.0' }) @@ -123,7 +123,7 @@ describe('valid identifier on api:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${validIdentifier}?resolved=true`) .reply(200, jsonResponse) @@ -137,7 +137,7 @@ describe('valid identifier on api:get', () => { describe('swaggerhub errors on api:get', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', api => api .get(`/${validIdentifier}`) .reply(500, { message: 'Internal Server Error' }) @@ -147,7 +147,7 @@ describe('swaggerhub errors on api:get', () => { .it('internal server error returned by SwaggerHub, command fails') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', api => api .get(`/${validIdentifier}`) .reply(404, { message: 'Not found' }) @@ -157,7 +157,7 @@ describe('swaggerhub errors on api:get', () => { .it('not found returned by SwaggerHub, command fails') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', api => api .get('/org1/api2/settings/default') .reply(404, { message: 'Unknown API org1/api2' }) @@ -167,7 +167,7 @@ describe('swaggerhub errors on api:get', () => { .it('not found returned when fetching default version of API') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', api => api .get(`/${validIdentifier}`) .reply(200) @@ -179,7 +179,7 @@ describe('swaggerhub errors on api:get', () => { .it('no content returned from swaggerhub') test - .stub(config, 'isURLValid', () => false) + .stub(config, 'isURLValid', stub => stub.returns(false)) .command(['api:get', 'org1/api2/1.0.0']) .catch(ctx => expect(ctx.message).to.equal('Please verify that the configured SwaggerHub URL is correct.') diff --git a/test/commands/api/publish.test.js b/test/commands/api/publish.test.js index dd194867..087c76b2 100644 --- a/test/commands/api/publish.test.js +++ b/test/commands/api/publish.test.js @@ -2,13 +2,13 @@ const { exit } = require('@oclif/core') const { expect, test } = require('@oclif/test') const inquirer = require('inquirer') const config = require('../../../src/config') -const shubUrl = 'https://test-api.swaggerhub.com' +const shubUrl = 'https://api.swaggerhub.com' describe('valid api:publish', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .nock(`${shubUrl}/apis`, api => api - .put('/org/api/1.0.0/settings/lifecycle', { published: true }) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}`, api => api + .put('/apis/org/api/1.0.0/settings/lifecycle', { published: true }) .reply(200) ) .stdout() @@ -18,14 +18,14 @@ describe('valid api:publish', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .nock(`${shubUrl}/apis`, api => api - .put('/org/api/1.0.0/settings/lifecycle', { published: true }) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}`, api => api + .put('/apis/org/api/1.0.0/settings/lifecycle', { published: true }) .reply(424, '{ "code": 424, "message": "conflict detected"}') ) - .stub(inquirer, 'prompt', () => Promise.resolve({ answer: true })) - .nock(`${shubUrl}/apis`, api => api - .put('/org/api/1.0.0/settings/lifecycle?force=true', { published: true }) + .stub(inquirer, 'prompt', stub => stub.returns(Promise.resolve({ answer: true }))) + .nock(`${shubUrl}`, api => api + .put('/apis/org/api/1.0.0/settings/lifecycle?force=true', { published: true }) .reply(200) ) .stdout() @@ -33,9 +33,9 @@ describe('valid api:publish', () => { .it('runs api:publish with enter \'Yes\' on confirmation') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .nock(`${shubUrl}/apis`, api => api - .put('/org/api/1.0.0/settings/lifecycle?force=true', { published: true }) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}`, api => api + .put('/apis/org/api/1.0.0/settings/lifecycle?force=true', { published: true }) .reply(200) ) .stdout() @@ -62,9 +62,9 @@ describe('invalid apis:publish', () => { .it('runs api:publish with unrecognised flag') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .nock(`${shubUrl}/apis`, api => api - .put('/org/api/1.2.3/settings/lifecycle') + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}`, api => api + .put('/apis/org/api/1.2.3/settings/lifecycle') .reply(404, '{ "code": 404, "message": "Unknown API org/api:1.2.3"}') ) .command(['api:publish', 'org/api/1.2.3']) @@ -72,12 +72,12 @@ describe('invalid apis:publish', () => { .it('runs api:publish with invalid API version') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .nock(`${shubUrl}/apis`, api => api - .put('/org/api/1.2.3/settings/lifecycle') - .reply(424, '{ "code": 424, "message": "conflict detected"}') + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .stub(inquirer, 'prompt', stub => stub.returns(Promise.resolve({ answer: false }))) + .nock(`${shubUrl}`, api => api + .put('/apis/org/api/1.2.3/settings/lifecycle') + .reply(424, '{ "code": 424, "message": "conflict detected" }') ) - .stub(inquirer, 'prompt', () => Promise.resolve({ answer: false })) .command(['api:publish', 'org/api/1.2.3']) .it('runs api:publish with \'No\' on confirmation') }) diff --git a/test/commands/api/setdefault.test.js b/test/commands/api/setdefault.test.js index 40579914..4c40e428 100644 --- a/test/commands/api/setdefault.test.js +++ b/test/commands/api/setdefault.test.js @@ -4,7 +4,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid api:setdefault', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .put('/org/api/settings/default', { version: '2.0.0' }) .reply(200) @@ -34,7 +34,7 @@ describe('invalid apis:setdefault', () => { .it('runs api:setdefault with unrecognised flag') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .put('/org/api/settings/default', { version: '1.2.3' }) .reply(404, '{ "code": 404, "message": "Unknown API org/api:1.2.3"}') diff --git a/test/commands/api/unpublish.test.js b/test/commands/api/unpublish.test.js index 4992bf13..22522c53 100644 --- a/test/commands/api/unpublish.test.js +++ b/test/commands/api/unpublish.test.js @@ -4,7 +4,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid api:unpublish', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .put('/org/api/1.0.0/settings/lifecycle', { published: false }) .reply(200) @@ -33,7 +33,7 @@ describe('invalid apis:unpublish', () => { .it('runs api:unpublish with unrecognised flag') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .put('/org/api/1.2.3/settings/lifecycle') .reply(404, '{ "code": 404, "message": "Unknown API org/api:1.2.3"}') diff --git a/test/commands/api/update.test.js b/test/commands/api/update.test.js index bd71f9ce..f3ad98fe 100644 --- a/test/commands/api/update.test.js +++ b/test/commands/api/update.test.js @@ -19,7 +19,7 @@ describe('invalid api:update command issues', () => { test .command(['api:update', 'org/api', '-f=test/resources/valid_api.json', '--visibility']) .catch(err => { - expect(err.message).to.equal('Flag --visibility expects a value') + expect(err.message).to.equal('Flag --visibility expects one of these values: public, private') }) .it('runs api:update with no required --visibility flag') @@ -70,7 +70,7 @@ describe('invalid api:update file issues', () => { describe('invalid api:update', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/1.0.0') .reply(404, '{"code": 404, "message": "Unknown API org/api/1.0.0"}') @@ -80,7 +80,7 @@ describe('invalid api:update', () => { .it('runs api:update with API version not found') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/1.0.0') .reply(500, '{"code": 500, "message": "Error"}') @@ -90,7 +90,7 @@ describe('invalid api:update', () => { .it('runs api:update with error retrieving API version') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/1.0.0') .reply(200) @@ -104,7 +104,7 @@ describe('invalid api:update', () => { .it('runs api:update with error on updating API') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/1.0.0') .reply(404, '{"code": 404, "message": "Unknown API org/api/1.0.0"}') @@ -116,7 +116,7 @@ describe('invalid api:update', () => { .it('error shows as update failed and publish and setdefault are not executed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/1.0.0') .reply(200) @@ -136,7 +136,7 @@ describe('invalid api:update', () => { .it('error shows as publish failed and setdefault is not executed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/1.0.0') .reply(200) @@ -160,7 +160,7 @@ describe('invalid api:update', () => { .it('error shows as setdefault failed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .stdout() .command(['api:update', 'org/api/2.0.0']) @@ -173,7 +173,7 @@ describe('invalid api:update', () => { describe('valid api:update', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/1.0.0') .reply(200) @@ -190,7 +190,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/2.0.0') .reply(200) @@ -207,7 +207,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/2.0.0') .reply(200) @@ -224,7 +224,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/2.0.0') .reply(200) @@ -241,7 +241,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') @@ -259,7 +259,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') @@ -277,7 +277,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/2.0.0') .reply(200) @@ -299,7 +299,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/2.0.0') .reply(200) @@ -321,7 +321,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/2.0.0') .reply(200) @@ -343,7 +343,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') .reply(200, { version: '2.0.0' }) @@ -370,7 +370,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') .reply(200, { version: '2.0.0' }) @@ -397,7 +397,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/2.0.0') .reply(200) @@ -431,7 +431,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/2.0.0') .reply(200) @@ -458,7 +458,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') .reply(200, { version: '2.0.0' }) @@ -475,7 +475,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') .reply(200, { version: '2.0.0' }) @@ -492,7 +492,7 @@ describe('valid api:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') .reply(200, { version: '2.0.0' }) diff --git a/test/commands/api/validate/download-rules.test.js b/test/commands/api/validate/download-rules.test.js index 14cc4e40..4e955268 100644 --- a/test/commands/api/validate/download-rules.test.js +++ b/test/commands/api/validate/download-rules.test.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ const { expect, test } = require('@oclif/test') const config = require('../../../../src/config') const { @@ -16,10 +17,10 @@ describe('invalid api:validate:download-rules', () => { .it('runs api:validate:download-rules with no organization name provided') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) - .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api - .get(`/org2/spectral`) - .query({ includeSystemRules : false, includeDisabledRules : false}) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' } }, api => api + .get('/org2/spectral') + .query({ includeSystemRules: false, includeDisabledRules: false }) .reply(404, 'Access Denied') ) .command(['api:validate:download-rules', 'org2']) @@ -27,7 +28,7 @@ describe('invalid api:validate:download-rules', () => { .it('Access Denied returned when trying to fetch ruleset of not existing or not available organization') test - .stub(config, 'isURLValid', () => false) + .stub(config, 'isURLValid', stub => stub.returns(false)) .command(['api:validate:download-rules', 'org1']) .catch(ctx => expect(ctx.message).to.equal('Please verify that the configured SwaggerHub URL is correct.') @@ -37,10 +38,10 @@ describe('invalid api:validate:download-rules', () => { describe('valid api:validate:download-rules', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) - .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' } }, api => api .get(`/${orgName}/spectral`) - .query({ includeSystemRules : false, includeDisabledRules : false}) + .query({ includeSystemRules: false, includeDisabledRules: false }) .reply(200, ruleset) ) .stdout() @@ -50,10 +51,10 @@ describe('valid api:validate:download-rules', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) - .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' } }, api => api .get(`/${orgName}/spectral`) - .query({ includeSystemRules : true, includeDisabledRules : false}) + .query({ includeSystemRules: true, includeDisabledRules: false }) .reply(200, rulesetWithSystemRule) ) .stdout() @@ -63,10 +64,10 @@ describe('valid api:validate:download-rules', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) - .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' } }, api => api .get(`/${orgName}/spectral`) - .query({ includeSystemRules : false, includeDisabledRules : true}) + .query({ includeSystemRules: false, includeDisabledRules: true }) .reply(200, rulesetWithDisabledRule) ) .stdout() @@ -77,10 +78,10 @@ describe('valid api:validate:download-rules', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) - .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' } }, api => api .get(`/${orgName}/spectral`) - .query({ includeSystemRules : true, includeDisabledRules : true}) + .query({ includeSystemRules: true, includeDisabledRules: true }) .reply(200, rulesetWithDisabledAndSystemRule) ) .stdout() diff --git a/test/commands/api/validate/index.test.js b/test/commands/api/validate/index.test.js index 7506577d..18878490 100644 --- a/test/commands/api/validate/index.test.js +++ b/test/commands/api/validate/index.test.js @@ -6,7 +6,7 @@ const heading = ' Line Severity Description \n ──── ──── describe('invalid api:validate', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(404, { @@ -19,7 +19,7 @@ describe('invalid api:validate', () => { .exit(2) .it('not found returned when fetching validation result of a non existing API') - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -38,7 +38,7 @@ describe('invalid api:validate', () => { .exit(0) .it('not enabled returned when fetching validation result an existing') - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -56,7 +56,7 @@ describe('invalid api:validate', () => { .exit(0) .it('an error is returned when user has no permission to access API') - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath.substring(0, apiPath.lastIndexOf('/'))}/settings/default`) .reply(404, { message: 'Unknown API org1/api2' }) @@ -130,7 +130,7 @@ describe('valid api:validate', () => { const severity = 'critical' describe('without -c flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -154,7 +154,7 @@ describe('valid api:validate', () => { }) describe('with -c flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -178,7 +178,7 @@ describe('valid api:validate', () => { }) describe('with --fail-on-critical flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -206,7 +206,7 @@ describe('valid api:validate', () => { const severity = 'WARNING' describe('without -c flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -231,7 +231,7 @@ describe('valid api:validate', () => { describe('with -c flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -255,7 +255,7 @@ describe('valid api:validate', () => { }) describe('with --fail-on-critical flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -280,7 +280,7 @@ describe('valid api:validate', () => { }) describe('when no standardization errors present', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { @@ -300,7 +300,7 @@ describe('valid api:validate', () => { expect(ctx.stdout).to.contains('') }) - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/apis', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${apiPath}`) .reply(200, { diff --git a/test/commands/api/validate/local.test.js b/test/commands/api/validate/local.test.js index 22f8ff9d..ffac2b62 100644 --- a/test/commands/api/validate/local.test.js +++ b/test/commands/api/validate/local.test.js @@ -61,7 +61,7 @@ describe('valid api:validate:local', () => { const severity = 'critical' describe('without -c flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization', api => api .post(`/${orgName}/scan`) .matchHeader('Content-Type', 'application/yaml') @@ -82,7 +82,7 @@ describe('valid api:validate:local', () => { }) describe('with -c flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization', api => api .post(`/${orgName}/scan`) .reply(200, { @@ -102,7 +102,7 @@ describe('valid api:validate:local', () => { }) describe('with --fail-on-critical flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization', api => api .post(`/${orgName}/scan`) .reply(200, { @@ -126,7 +126,7 @@ describe('valid api:validate:local', () => { const severity = 'WARNING' describe('without -c flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization', api => api .post(`/${orgName}/scan`) .reply(200, { @@ -144,7 +144,7 @@ describe('valid api:validate:local', () => { }) describe('with -c flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization', api => api .post(`/${orgName}/scan`) .reply(200, { @@ -162,7 +162,7 @@ describe('valid api:validate:local', () => { }) describe('with --fail-on-critical flag', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization', api => api .post(`/${orgName}/scan`) .reply(200, { @@ -183,7 +183,7 @@ describe('valid api:validate:local', () => { }) describe('when no standardization errors present', () => { - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization', api => api .post(`/${orgName}/scan`) .reply(200, { @@ -201,7 +201,7 @@ describe('valid api:validate:local', () => { describe('when sending a JSON file', () => { const severity = 'WARNING' - test.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + test.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization', api => api .post(`/${orgName}/scan`) .reply(200, { diff --git a/test/commands/configure.test.js b/test/commands/configure.test.js index d0bdaf25..1f8880ad 100644 --- a/test/commands/configure.test.js +++ b/test/commands/configure.test.js @@ -1,23 +1,38 @@ const path = require('path') const { expect, test } = require('@oclif/test') const inquirer = require('inquirer') +const sinon = require('sinon') const { setConfig } = require('../../src/config') -describe('successful configuration', () => { - test - .stub(inquirer, 'prompt', () => Promise.resolve().then(setConfig)) - .stdout() - .command(['configure']) - .it('runs sets up config and logs the location of the file', ctx => { - const configFilePath = [...ctx.config.configDir.split(path.sep), 'config.json'].join(path.sep) - expect(ctx.stdout).to.contains(`Saved config to ${configFilePath}`) - }) -}) +describe('configure command', () => { + let promptStub + + beforeEach(() => { + promptStub = sinon.stub(inquirer, 'prompt') + }) + + afterEach(() => { + promptStub.restore() + }) -describe('failed configuration', () => { - test - .stub(inquirer, 'prompt', () => Promise.reject()) - .command(['configure']) - .catch(err => expect(err.message).to.contain('Failed to write config to')) - .it('fails to setup the config and throws an error message') + describe('successful configuration', () => { + test + .do(() => promptStub.returns(Promise.resolve().then(setConfig))) + .stdout() + .command(['configure']) + .it('runs sets up config and logs the location of the file', ctx => { + const configFilePath = [...ctx.config.configDir.split(path.sep), 'config.json'].join(path.sep) + expect(ctx.stdout).to.contains(`Saved config to ${configFilePath}`) + }) + }) + + describe('failed configuration', () => { + test + .do(() => promptStub.returns(Promise.reject())) + .command(['configure']) + .catch(err => expect(err.message).to.contain('Failed to write config to')) + .it('fails to setup the config and throws an error message') + }) }) + + diff --git a/test/commands/domain/create.test.js b/test/commands/domain/create.test.js index d093b8e1..8a37e709 100644 --- a/test/commands/domain/create.test.js +++ b/test/commands/domain/create.test.js @@ -45,7 +45,7 @@ describe('invalid domain:create file issues', () => { describe('invalid domain:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(200) @@ -61,7 +61,7 @@ describe('invalid domain:create', () => { .it('runs domain:create with domain version already exists') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(500, '{ "code": 500, "message": "Error"}') @@ -71,7 +71,7 @@ describe('invalid domain:create', () => { .it('runs domain:create with error retrieving domains') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(200) @@ -85,7 +85,7 @@ describe('invalid domain:create', () => { .it('runs domain:create with error on retrieving domain version') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/orgNotExist/domain') .reply(404) @@ -101,7 +101,7 @@ describe('invalid domain:create', () => { .it('runs domain:create with org that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/overLimit') .reply(404) @@ -117,7 +117,7 @@ describe('invalid domain:create', () => { .it('runs domain:create with org that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/orgNotExist/domain') .reply(404) @@ -134,7 +134,7 @@ describe('invalid domain:create', () => { .it('error shows as create failed and publish and setdefault are not executed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(404) @@ -155,7 +155,7 @@ describe('invalid domain:create', () => { .it('error shows as publish failed and setdefault is not executed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(404) @@ -182,7 +182,7 @@ describe('invalid domain:create', () => { describe('valid domain:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(404) @@ -199,7 +199,7 @@ describe('valid domain:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(404) @@ -220,7 +220,7 @@ describe('valid domain:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(404) @@ -241,7 +241,7 @@ describe('valid domain:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(404) @@ -258,7 +258,7 @@ describe('valid domain:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(404) @@ -286,7 +286,7 @@ describe('valid domain:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(404) @@ -310,7 +310,7 @@ describe('valid domain:create', () => { describe('valid create new version with domain:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(200) @@ -331,7 +331,7 @@ describe('valid create new version with domain:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain') .reply(200) @@ -358,7 +358,7 @@ describe('valid create new version with domain:create', () => { describe('valid create new version with domain:create using invalid swaggerhub url', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: `${shubUrl}/v1` })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: `${shubUrl}/v1` })) .stdout() .command(['domain:create', 'org/domain', '--file=test/resources/valid_domain.yaml']) .exit(2) diff --git a/test/commands/domain/delete.test.js b/test/commands/domain/delete.test.js index bb9fc4fc..c8b055de 100644 --- a/test/commands/domain/delete.test.js +++ b/test/commands/domain/delete.test.js @@ -1,4 +1,5 @@ const { expect, test } = require('@oclif/test') +const sinon = require('sinon') const inquirer = require('inquirer') const config = require('../../../src/config') const domainId = 'org/domain' @@ -7,7 +8,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid domain:delete', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .delete('/org/domain/1.0.0') .query({ force: 'true' }) @@ -20,28 +21,7 @@ describe('valid domain:delete', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .stub(inquirer, 'prompt', () => Promise.resolve({ answer: true })) - .nock(`${shubUrl}/domains`, domain => domain - .delete('/org/domain') - .query({ force: 'true' }) - .reply(200) - ) - .stdout() - .command(['domain:delete', domainId]) - .it('runs domain:delete on domain defintion', ctx => { - expect(ctx.stdout).to.contains(`Deleted domain '${domainId}'`) - }) - - test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) - .stub(inquirer, 'prompt', () => Promise.resolve({ answer: false })) - .stdout() - .command(['domain:delete', domainId]) - .it('runs domain:delete on domain, enter \'No\' on confirmation') - - test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .delete('/org/domain') .query({ force: 'true' }) @@ -54,7 +34,7 @@ describe('valid domain:delete', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .delete('/org/domain') .query({ force: 'true' }) @@ -82,7 +62,7 @@ describe('invalid domain:delete command issues', () => { describe('domain:delete error responses', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .delete('/org/domain') .query({ force: 'true' }) @@ -94,3 +74,37 @@ describe('domain:delete error responses', () => { }) .it('runs domain:delete with domain that does not exist') }) + + +describe('inquirer prompts', () => { + let promptStub + + beforeEach(() => { + promptStub = sinon.stub(inquirer, 'prompt') + }) + + afterEach(() => { + promptStub.restore() + }) + + test + .do(() => promptStub.returns(Promise.resolve({ answer: true }))) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}/domains`, domain => domain + .delete('/org/domain') + .query({ force: 'true' }) + .reply(200) + ) + .stdout() + .command(['domain:delete', domainId]) + .it('runs domain:delete on domain defintion', ctx => { + expect(ctx.stdout).to.contains(`Deleted domain '${domainId}'`) + }) + + test + .do(() => promptStub.returns(Promise.resolve({ answer: false }))) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .stdout() + .command(['domain:delete', domainId]) + .it('runs domain:delete on domain, enter \'No\' on confirmation') +}) \ No newline at end of file diff --git a/test/commands/domain/get.test.js b/test/commands/domain/get.test.js index 7ec1f632..17480642 100644 --- a/test/commands/domain/get.test.js +++ b/test/commands/domain/get.test.js @@ -28,7 +28,7 @@ describe('invalid identifier on domain:get', () => { describe('valid identifier on domain:get', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', { reqheaders: { Accept: 'application/json' } }, domain => domain .get(`/${validIdentifier}`) .reply(200, jsonResponse) @@ -40,7 +40,7 @@ describe('valid identifier on domain:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', { reqheaders: { Accept: 'application/json' } }, domain => domain .get(`/${validIdentifier}`) .reply(200, jsonResponse) @@ -52,7 +52,7 @@ describe('valid identifier on domain:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', { reqheaders: { Accept: 'application/yaml' } }, domain => domain .get(`/${validIdentifier}`) .reply(200, yaml.dump(jsonResponse)) @@ -64,7 +64,7 @@ describe('valid identifier on domain:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', domain => domain .get('/org1/domain2/settings/default') .reply(200, { version: '1.0.0' }) @@ -80,7 +80,7 @@ describe('valid identifier on domain:get', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', domain => domain .get('/org1/domain2/settings/default') .reply(200, { version: '1.0.0' }) @@ -98,7 +98,7 @@ describe('valid identifier on domain:get', () => { describe('swaggerhub errors on domain:get', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', domain => domain .get(`/${validIdentifier}`) .reply(500, { message: 'Internal Server Error' }) @@ -108,7 +108,7 @@ describe('swaggerhub errors on domain:get', () => { .it('internal server error returned by SwaggerHub, command fails') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', domain => domain .get(`/${validIdentifier}`) .reply(404, { message: 'Not found' }) @@ -118,7 +118,7 @@ describe('swaggerhub errors on domain:get', () => { .it('not found returned by SwaggerHub, command fails') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', domain => domain .get(`/${validIdentifier}`) .reply(403, { message: 'Error: This private API is blocked because you have exceeded your current ' + @@ -132,7 +132,7 @@ describe('swaggerhub errors on domain:get', () => { .it('not found returned by SwaggerHub, command fails') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', api => api .get(`/${validIdentifier}`) .reply(200) @@ -144,7 +144,7 @@ describe('swaggerhub errors on domain:get', () => { .it('no content returned from swaggerhub') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/domains', domain => domain .get('/org1/domain2/settings/default') .reply(404, { message: 'Unknown domain org1/domain2' }) diff --git a/test/commands/domain/publish.test.js b/test/commands/domain/publish.test.js index 0e45bce5..a8bbb575 100644 --- a/test/commands/domain/publish.test.js +++ b/test/commands/domain/publish.test.js @@ -4,7 +4,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid domain:publish', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .put('/org/domain/1.0.0/settings/lifecycle', { published: true }) .reply(200) @@ -33,7 +33,7 @@ describe('invalid domains:publish', () => { .it('runs domain:publish with unrecognised flag') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .put('/org/domain/1.2.3/settings/lifecycle') .reply(404, '{ "code": 404, "message": "Unknown domain org/domain:1.2.3"}') diff --git a/test/commands/domain/setdefault.test.js b/test/commands/domain/setdefault.test.js index 18f058db..848740d9 100644 --- a/test/commands/domain/setdefault.test.js +++ b/test/commands/domain/setdefault.test.js @@ -4,7 +4,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid domain:setdefault', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .put('/org/domain/settings/default', { version: '2.0.0' }) .reply(200) @@ -34,7 +34,7 @@ describe('invalid domain:setdefault', () => { .it('runs domain:setdefault with unrecognised flag') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .put('/org/domain/settings/default', { version: '1.2.3' }) .reply(404, '{ "code": 404, "message": "Unknown domain org/domain:1.2.3"}') diff --git a/test/commands/domain/unpublish.test.js b/test/commands/domain/unpublish.test.js index 04ef11fd..dcfb9984 100644 --- a/test/commands/domain/unpublish.test.js +++ b/test/commands/domain/unpublish.test.js @@ -4,7 +4,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid domain:unpublish', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .put('/org/domain/1.0.0/settings/lifecycle', { published: false }) .reply(200) @@ -33,7 +33,7 @@ describe('invalid domains:unpublish', () => { .it('runs domain:unpublish with unrecognised flag') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .put('/org/domain/1.2.3/settings/lifecycle') .reply(404, '{ "code": 404, "message": "Unknown domain org/domain:1.2.3"}') diff --git a/test/commands/domain/update.test.js b/test/commands/domain/update.test.js index a2d99ef0..10f35eb2 100644 --- a/test/commands/domain/update.test.js +++ b/test/commands/domain/update.test.js @@ -19,7 +19,7 @@ describe('invalid domain:update command issues', () => { test .command(['domain:update', 'org/domain', '-f=test/resources/valid_domain.json', '--visibility']) .catch(err => { - expect(err.message).to.equal('Flag --visibility expects a value') + expect(err.message).to.equal('Flag --visibility expects one of these values: public, private') }) .it('runs domain:update with no required --visibility flag') @@ -70,7 +70,7 @@ describe('invalid domain:update file issues', () => { describe('invalid domain:update', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.0.0') .reply(404, '{"code": 404, "message": "Unknown domain org/domain/1.0.0"}') @@ -80,7 +80,7 @@ describe('invalid domain:update', () => { .it('runs domain:update with domain version not found') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.0.0') .reply(500, '{"code": 500, "message": "Error"}') @@ -90,7 +90,7 @@ describe('invalid domain:update', () => { .it('runs domain:update with error retrieving domain version') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.0.0') .reply(200) @@ -104,7 +104,7 @@ describe('invalid domain:update', () => { .it('runs domain:update with error on updating domain') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.0.0') .reply(404, '{"code": 404, "message": "Unknown domain org/domain/1.0.0"}') @@ -116,7 +116,7 @@ describe('invalid domain:update', () => { .it('error shows as update failed and publish and setdefault are not executed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.0.0') .reply(200) @@ -136,7 +136,7 @@ describe('invalid domain:update', () => { .it('error shows as publish failed and setdefault is not executed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.0.0') .reply(200) @@ -160,7 +160,7 @@ describe('invalid domain:update', () => { .it('error shows as setdefault failed') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .stdout() .command(['domain:update', 'org/domain/2.0.0']) @@ -173,7 +173,7 @@ describe('invalid domain:update', () => { describe('valid domain:update', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.0.0') .reply(200) @@ -190,7 +190,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.2.3') .reply(200) @@ -207,7 +207,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.2.3') .reply(200) @@ -224,7 +224,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.2.3') .reply(200) @@ -241,7 +241,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/settings/default') @@ -259,7 +259,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/settings/default') @@ -277,7 +277,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.2.3') .reply(200) @@ -299,7 +299,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.2.3') .reply(200) @@ -321,7 +321,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.2.3') .reply(200) @@ -343,7 +343,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/settings/default') .reply(200, { version: '2.0.0' }) @@ -370,7 +370,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/settings/default') .reply(200, { version: '2.0.0' }) @@ -397,7 +397,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.2.3') .reply(200) @@ -431,7 +431,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/1.2.3') .reply(200) @@ -464,7 +464,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/settings/default') .reply(200, { version: '2.0.0' }) @@ -481,7 +481,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/settings/default') .reply(200, { version: '2.0.0' }) @@ -498,7 +498,7 @@ describe('valid domain:update', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain .get('/org/domain/settings/default') .reply(200, { version: '2.0.0' }) diff --git a/test/commands/integration/create.test.js b/test/commands/integration/create.test.js index 64ef27b8..4c54de17 100644 --- a/test/commands/integration/create.test.js +++ b/test/commands/integration/create.test.js @@ -5,7 +5,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid integration:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .post(`/${validIdentifier}/integrations`) .matchHeader('Content-Type', 'application/json') @@ -18,7 +18,7 @@ describe('valid integration:create', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') .reply(200, { version: '1.0.0' }) @@ -54,7 +54,7 @@ describe('invalid integration:create command issues', () => { describe('invalid integration:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .post(`/${validIdentifier}/integrations`) .reply(409, { message: 'Integration \'Integration Name\' already exists' }) @@ -66,7 +66,7 @@ describe('invalid integration:create', () => { .it('runs integration:create with integration name conflict') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .post(`/${validIdentifier}/integrations`) .reply(404, { message: 'Unknown API org/api/1.0.0' }) diff --git a/test/commands/integration/delete.test.js b/test/commands/integration/delete.test.js index 36b42fc9..3379762a 100644 --- a/test/commands/integration/delete.test.js +++ b/test/commands/integration/delete.test.js @@ -14,7 +14,7 @@ const integrationResponse = { describe('valid integration:delete', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .delete(`/${validPath}`) .reply(200, 'ok') @@ -40,7 +40,7 @@ describe('invalid integration:delete command issues', () => { describe('invalid integration:delete', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .delete(`/${validPath}`) .reply(404, { message: 'The specified API or integration ID was not found' }) @@ -52,7 +52,7 @@ describe('invalid integration:delete', () => { .it('runs integration:delete with an integration that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .delete(`/${validPath}`) .reply(404, { message: 'Unknown API org/api:1.0.0' }) diff --git a/test/commands/integration/execute.test.js b/test/commands/integration/execute.test.js index 5f64f660..16092af6 100644 --- a/test/commands/integration/execute.test.js +++ b/test/commands/integration/execute.test.js @@ -6,7 +6,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid integration:execute', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .post(`/${validPath}/execute`) .reply(200, 'ok') @@ -32,7 +32,7 @@ describe('invalid integration:execute command issues', () => { describe('invalid integration:execute', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .post(`/${validPath}/execute`) .reply(404, { message: 'The specified API or integration ID was not found' }) @@ -44,7 +44,7 @@ describe('invalid integration:execute', () => { .it('runs integration:execute with an integration that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .post(`/${validPath}/execute`) .reply(404, { message: 'Unknown API org/api:1.0.0' }) diff --git a/test/commands/integration/get.test.js b/test/commands/integration/get.test.js index 50e730f0..06a4e4f7 100644 --- a/test/commands/integration/get.test.js +++ b/test/commands/integration/get.test.js @@ -14,7 +14,7 @@ const integrationResponse = { describe('valid integration:get', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, { reqheaders: { Accept: 'application/json' } }, integration => integration .get(`/${validPath}`) .reply(200, integrationResponse) @@ -40,7 +40,7 @@ describe('invalid integration:get command issues', () => { describe('invalid integration:get', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .get(`/${validPath}`) .reply(404, { message: 'The specified API or integration ID was not found' }) @@ -52,7 +52,7 @@ describe('invalid integration:get', () => { .it('runs integration:get with an integration that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .get(`/${validPath}`) .reply(404, { message: 'Unknown API org/api:1.0.0' }) diff --git a/test/commands/integration/list.test.js b/test/commands/integration/list.test.js index ff380f54..6bc6be8a 100644 --- a/test/commands/integration/list.test.js +++ b/test/commands/integration/list.test.js @@ -21,7 +21,7 @@ const integrationResponse = { describe('valid integration:list', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, { reqheaders: { Accept: 'application/json' } }, integrations => integrations .get(`/${validApi}/integrations`) .reply(200, integrationResponse) @@ -34,7 +34,7 @@ describe('valid integration:list', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') .reply(200, { version: '1.0.0' }) @@ -65,7 +65,7 @@ describe('invalid integration:list command issues', () => { describe('invalid integration:list', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integrations => integrations .get(`/${validApi}/integrations`) .reply(404, { message: 'Unknown API org/api:1.0.0' }) @@ -77,7 +77,7 @@ describe('invalid integration:list', () => { .it('runs integration:list with an API version that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, api => api .get('/org/api/settings/default') .reply(404, { message: 'Unknown API org/api' }) diff --git a/test/commands/integration/update.test.js b/test/commands/integration/update.test.js index 4860a501..abd51de1 100644 --- a/test/commands/integration/update.test.js +++ b/test/commands/integration/update.test.js @@ -6,7 +6,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid integration:update', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .put(`/${apiIdentifier}/integrations/${integrationId}`) .matchHeader('Content-Type', 'application/json') @@ -43,7 +43,7 @@ describe('invalid integration:update command issues', () => { describe('invalid integration:update', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/apis`, integration => integration .put(`/${apiIdentifier}/integrations/${integrationId}`) .reply(404, { message: `Integration type GITHUB with ID '${integrationId}' not found` }) diff --git a/test/commands/project/api/add.test.js b/test/commands/project/api/add.test.js index 8e6bbf1a..cef05651 100644 --- a/test/commands/project/api/add.test.js +++ b/test/commands/project/api/add.test.js @@ -23,7 +23,7 @@ describe('invalid project:api:add command issues', () => { describe('valid project:api:add', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .put(`/${validIdentifier}/apis/testapi`) .matchHeader('Content-Type', 'application/json') @@ -38,7 +38,7 @@ describe('valid project:api:add', describe('invalid project:api:add', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .put(`/${validIdentifier}/apis/testapi`) .matchHeader('Content-Type', 'application/json') @@ -51,7 +51,7 @@ describe('invalid project:api:add', () => { .it('runs project:api:add with a project that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .put(`/${validIdentifier}/apis/testapi`) .reply(404, { message: 'Unknown owner \'testowner\'' }) @@ -63,7 +63,7 @@ describe('invalid project:api:add', () => { .it('runs project:api:add with an owner that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .put(`/${validIdentifier}/apis/testapi`) .reply(409, { diff --git a/test/commands/project/api/remove.test.js b/test/commands/project/api/remove.test.js index f0b75464..c8991cd3 100644 --- a/test/commands/project/api/remove.test.js +++ b/test/commands/project/api/remove.test.js @@ -32,7 +32,7 @@ describe('invalid project:api:remove command issues', () => { describe('valid project:api:remove', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, project => project .get(`/${validIdentifier}`) .reply(200, validProjectJson) @@ -51,7 +51,7 @@ describe('valid project:api:remove', () => { describe('invalid project:api:remove', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, project => project .get(`/${validIdentifier}`) .reply(404, { message: 'Project \'testproject\' does not exist' }) @@ -63,7 +63,7 @@ describe('invalid project:api:remove', () => { .it('runs project:api:remove with a project that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, project => project .get(`/${validIdentifier}`) .reply(404, { message: 'Organization \'testowner\' does not exist' }) @@ -75,7 +75,7 @@ describe('invalid project:api:remove', () => { .it('runs project:api:remove with an organization that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, project => project .get(`/${validIdentifier}`) .reply(200, validProjectJson) diff --git a/test/commands/project/create.test.js b/test/commands/project/create.test.js index 7a2bc155..21863509 100644 --- a/test/commands/project/create.test.js +++ b/test/commands/project/create.test.js @@ -24,7 +24,7 @@ describe('invalid project:create command issues', () => { describe('valid project:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .matchHeader('Content-Type', 'application/json') @@ -37,7 +37,7 @@ describe('valid project:create', }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .matchHeader('Content-Type', 'application/json') @@ -50,7 +50,7 @@ describe('valid project:create', }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .matchHeader('Content-Type', 'application/json') @@ -63,7 +63,7 @@ describe('valid project:create', }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .matchHeader('Content-Type', 'application/json') @@ -76,7 +76,7 @@ describe('valid project:create', }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .matchHeader('Content-Type', 'application/json') @@ -89,7 +89,7 @@ describe('valid project:create', }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .matchHeader('Content-Type', 'application/json') @@ -102,7 +102,7 @@ describe('valid project:create', }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .matchHeader('Content-Type', 'application/json') @@ -123,7 +123,7 @@ describe('valid project:create', describe('invalid project:create', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .matchHeader('Content-Type', 'application/json') @@ -136,7 +136,7 @@ describe('invalid project:create', () => { .it('runs project:create with project name conflict') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .post(`/${validOwner}`) .reply(404, { message: 'Unknown owner \'testowner\'' }) diff --git a/test/commands/project/delete.test.js b/test/commands/project/delete.test.js index f78a119d..9bccb0e7 100644 --- a/test/commands/project/delete.test.js +++ b/test/commands/project/delete.test.js @@ -5,7 +5,7 @@ const shubUrl = 'https://test-api.swaggerhub.com' describe('valid project:delete', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, api => api .delete(`/${validIdentifier}`) .reply(200, `Deleted project \'${validIdentifier}\'`) @@ -33,7 +33,7 @@ describe('invalid project:delete command problems', () => { describe('invalid project:delete', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .delete(`/${validIdentifier}`) .reply(404, { message: 'The specified project was not found' }) diff --git a/test/commands/project/domain/add.test.js b/test/commands/project/domain/add.test.js index 6b32811f..3365dfdd 100644 --- a/test/commands/project/domain/add.test.js +++ b/test/commands/project/domain/add.test.js @@ -23,7 +23,7 @@ describe('invalid project:domain:add command issues', () => { describe('valid project:domain:add', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .put(`/${validIdentifier}/domains/testdomain`) .matchHeader('Content-Type', 'application/json') @@ -38,7 +38,7 @@ describe('valid project:domain:add', describe('invalid project:domain:add', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .put(`/${validIdentifier}/domains/testdomain`) .matchHeader('Content-Type', 'application/json') @@ -51,7 +51,7 @@ describe('invalid project:domain:add', () => { .it('runs project:domain:add with a project that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .put(`/${validIdentifier}/domains/testdomain`) .reply(404, { message: 'Unknown owner \'testowner\'' }) @@ -63,7 +63,7 @@ describe('invalid project:domain:add', () => { .it('runs project:domain:add with an owner that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, integration => integration .put(`/${validIdentifier}/domains/testdomain`) .reply(409, { diff --git a/test/commands/project/domain/remove.test.js b/test/commands/project/domain/remove.test.js index c68619b7..1f9077ab 100644 --- a/test/commands/project/domain/remove.test.js +++ b/test/commands/project/domain/remove.test.js @@ -32,7 +32,7 @@ describe('invalid project:domain:remove command issues', () => { describe('valid project:domain:remove', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, project => project .get(`/${validIdentifier}`) .reply(200, validProjectJson) @@ -51,7 +51,7 @@ describe('valid project:domain:remove', () => { describe('invalid project:domain:remove', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, project => project .get(`/${validIdentifier}`) .reply(404, { message: 'Project \'testproject\' does not exist' }) @@ -63,7 +63,7 @@ describe('invalid project:domain:remove', () => { .it('runs project:domain:remove with a project that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, project => project .get(`/${validIdentifier}`) .reply(404, { message: 'Organization \'testowner\' does not exist' }) @@ -75,7 +75,7 @@ describe('invalid project:domain:remove', () => { .it('runs project:domain:remove with an organization that doesn\'t exist') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, project => project .get(`/${validIdentifier}`) .reply(200, validProjectJson) diff --git a/test/commands/project/get.test.js b/test/commands/project/get.test.js index 228a81a3..957916f1 100644 --- a/test/commands/project/get.test.js +++ b/test/commands/project/get.test.js @@ -27,7 +27,7 @@ describe('invalid identifier on project:get', () => { describe('valid identifier on project:get', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) .nock('https://test.api.swaggerhub.com/projects', { reqheaders: { Accept: 'application/json' } }, api => api .get(`/${validIdentifier}`) .reply(200, jsonResponse) @@ -41,7 +41,7 @@ describe('valid identifier on project:get', () => { describe('swaggerhub errors on project:get', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) .nock('https://test.api.swaggerhub.com/projects', api => api .get(`/${validIdentifier}`) .reply(500, { message: 'Internal Server Error' }) @@ -51,7 +51,7 @@ describe('swaggerhub errors on project:get', () => { .it('internal server error returned by SwaggerHub, command fails') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) .nock('https://test.api.swaggerhub.com/projects', api => api .get(`/${validIdentifier}`) .reply(404, { message: 'Not found' }) @@ -61,7 +61,7 @@ describe('swaggerhub errors on project:get', () => { .it('not found returned by SwaggerHub, command fails') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) .nock('https://test.api.swaggerhub.com/projects', api => api .get('/testowner/nonexistantproject') .reply(404, { message: 'Unknown project testowner/nonexistantproject' }) @@ -71,7 +71,7 @@ describe('swaggerhub errors on project:get', () => { .it('not found returned when fetching non-existant project') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://test.api.swaggerhub.com' })) .nock('https://test.api.swaggerhub.com/projects', api => api .get(`/${validIdentifier}`) .reply(200) @@ -83,7 +83,7 @@ describe('swaggerhub errors on project:get', () => { .it('no content returned from swaggerhub') test - .stub(config, 'isURLValid', () => false) + .stub(config, 'isURLValid', stub => stub.returns(false)) .command(['project:get', 'testowner/testproject']) .catch(ctx => expect(ctx.message).to.equal('Please verify that the configured SwaggerHub URL is correct.') diff --git a/test/commands/project/list.test.js b/test/commands/project/list.test.js index 8cbce084..9fb1f134 100644 --- a/test/commands/project/list.test.js +++ b/test/commands/project/list.test.js @@ -23,7 +23,7 @@ const projectsResponse = { describe('valid project:list', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, { reqheaders: { accept: 'application/json' } }, projects => projects .get('/') .reply(200, { 'projects': [] }) @@ -35,7 +35,7 @@ describe('valid project:list', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, { reqheaders: { accept: 'application/json' } }, projects => projects .get('/') .reply(200, projectsResponse) @@ -48,7 +48,7 @@ describe('valid project:list', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, { reqheaders: { accept: 'application/json' } }, projects => projects .get(`/${validOrgName}`) .reply(200, projectsResponse) @@ -60,10 +60,3 @@ describe('valid project:list', () => { expect(ctx.stdout).to.contains('test_project_2') }) }) - -describe('invalid project:list command issues', () => { - test - .command(['project:list', 'totallydefinitelyabsolutelytoolonginvalidorgname']) - .exit(2) - .it('runs project:list with an invalid org name') -}) diff --git a/test/commands/project/member/list.test.js b/test/commands/project/member/list.test.js index d5f0271c..66e159c4 100644 --- a/test/commands/project/member/list.test.js +++ b/test/commands/project/member/list.test.js @@ -17,7 +17,7 @@ const membersResponse = { describe('valid project:member:list', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, { reqheaders: { accept: 'application/json' } }, projects => projects .get(`/${validIdentifier}/members`) .reply(200, { members: [] }) @@ -29,7 +29,7 @@ describe('valid project:member:list', () => { }) test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, { reqheaders: { accept: 'application/json' } }, projects => projects .get(`/${validIdentifier}/members`) .reply(200, membersResponse) @@ -55,7 +55,7 @@ describe('invalid project:list command issues', () => { describe('invalid project:list', () => { test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: shubUrl })) + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/projects`, { reqheaders: { accept: 'application/json' } }, projects => projects .get(`/${validIdentifier}/members`) .reply(404, membersResponse) diff --git a/test/support/config.test.js b/test/support/config.test.js index 62642fa0..30533b1e 100644 --- a/test/support/config.test.js +++ b/test/support/config.test.js @@ -34,19 +34,15 @@ describe('config ', () => { }) test - .stub(fse, 'readJSONSync', () => { - throw new Error('Failed to read') - }) + .stub(fse, 'readJSONSync', stub => stub.throws(new Error('Failed to read'))) .do(setConfig) .catch(err => expect(err.message).to.match(/failed to read/i)) .it('should throw an error if it fails to read the file.') test - .stub(fse, 'readJSONSync', () => ({})) - .stub(fse, 'writeJSONSync', () => { - throw new Error('Failed to write') - }) + .stub(fse, 'readJSONSync', stub => stub.returns({})) + .stub(fse, 'writeJSONSync', stub => stub.throws(new Error('Failed to write'))) .do(setConfig) .catch(err => expect(err.message).to.match(/failed to write/i)) .it('should throw an error if it fails to write the file')