Skip to content

Commit

Permalink
Update tests to fix breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CalemRoelofsSB committed Apr 19, 2024
1 parent 98179c4 commit 59c8684
Show file tree
Hide file tree
Showing 34 changed files with 315 additions and 296 deletions.
38 changes: 19 additions & 19 deletions test/commands/api/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"}')
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions test/commands/api/delete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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}"}`)
Expand Down
26 changes: 13 additions & 13 deletions test/commands/api/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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' })
Expand All @@ -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' })
Expand All @@ -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))
Expand All @@ -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' })
Expand All @@ -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)
Expand All @@ -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' })
Expand All @@ -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' })
Expand All @@ -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' })
Expand All @@ -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)
Expand All @@ -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.')
Expand Down
Loading

0 comments on commit 59c8684

Please sign in to comment.