diff --git a/__tests__/cmds/__snapshots__/openapi.test.js.snap b/__tests__/cmds/__snapshots__/openapi.test.js.snap index d298cc141..5ac7da20e 100644 --- a/__tests__/cmds/__snapshots__/openapi.test.js.snap +++ b/__tests__/cmds/__snapshots__/openapi.test.js.snap @@ -14,7 +14,7 @@ REQUIRED must have required property 'name' 29 | }] `; -exports[`rdme openapi should bundle and upload the expected content 1`] = ` +exports[`rdme openapi upload should bundle and upload the expected content 1`] = ` Object { "components": Object { "securitySchemes": Object { @@ -250,7 +250,7 @@ Object { } `; -exports[`rdme openapi should use specified working directory and upload the expected content 1`] = ` +exports[`rdme openapi upload should use specified working directory and upload the expected content 1`] = ` Object { "components": Object { "securitySchemes": Object { diff --git a/__tests__/cmds/openapi.test.js b/__tests__/cmds/openapi.test.js index 3b4dd81e3..cf56519c8 100644 --- a/__tests__/cmds/openapi.test.js +++ b/__tests__/cmds/openapi.test.js @@ -138,6 +138,77 @@ describe('rdme openapi', () => { fs.unlinkSync('./swagger.json'); return mock.done(); }); + + it('should bundle and upload the expected content', async () => { + let requestBody = null; + const registryUUID = getRandomRegistryId(); + const mock = getApiNock() + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, { version: '1.0.0' }) + .post('/api/v1/api-registry', body => { + requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1); + requestBody = JSON.parse(requestBody); + + return body.match('form-data; name="spec"'); + }) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .get('/api/v1/api-specification') + .basicAuth({ user: key }) + .reply(200, []) + .post('/api/v1/api-specification', { registryUUID }) + .basicAuth({ user: key }) + .reply(201, { _id: 1 }, { location: exampleRefLocation }); + + const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; + + await expect(openapi.run({ spec, key, version })).resolves.toBe(successfulUpload(spec)); + + expect(console.info).toHaveBeenCalledTimes(0); + + expect(requestBody).toMatchSnapshot(); + + return mock.done(); + }); + + it('should use specified working directory and upload the expected content', async () => { + let requestBody = null; + const registryUUID = getRandomRegistryId(); + const mock = getApiNock() + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, { version: '1.0.0' }) + .post('/api/v1/api-registry', body => { + requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1); + requestBody = JSON.parse(requestBody); + + return body.match('form-data; name="spec"'); + }) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .get('/api/v1/api-specification') + .basicAuth({ user: key }) + .reply(200, []) + .post('/api/v1/api-specification', { registryUUID }) + .basicAuth({ user: key }) + .reply(201, { _id: 1 }, { location: exampleRefLocation }); + + const spec = 'petstore.json'; + + await expect( + openapi.run({ + spec, + key, + version, + workingDirectory: './__tests__/__fixtures__/relative-ref-oas', + }) + ).resolves.toBe(successfulUpload(spec)); + + expect(console.info).toHaveBeenCalledTimes(0); + + expect(requestBody).toMatchSnapshot(); + + return mock.done(); + }); }); describe('updates / resyncs', () => { @@ -261,77 +332,6 @@ describe('rdme openapi', () => { }); }); - it('should bundle and upload the expected content', async () => { - let requestBody = null; - const registryUUID = getRandomRegistryId(); - const mock = getApiNock() - .get(`/api/v1/version/${version}`) - .basicAuth({ user: key }) - .reply(200, { version: '1.0.0' }) - .post('/api/v1/api-registry', body => { - requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1); - requestBody = JSON.parse(requestBody); - - return body.match('form-data; name="spec"'); - }) - .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) - .get('/api/v1/api-specification') - .basicAuth({ user: key }) - .reply(200, []) - .post('/api/v1/api-specification', { registryUUID }) - .basicAuth({ user: key }) - .reply(201, { _id: 1 }, { location: exampleRefLocation }); - - const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; - - await expect(openapi.run({ spec, key, version })).resolves.toBe(successfulUpload(spec)); - - expect(console.info).toHaveBeenCalledTimes(0); - - expect(requestBody).toMatchSnapshot(); - - return mock.done(); - }); - - it('should use specified working directory and upload the expected content', async () => { - let requestBody = null; - const registryUUID = getRandomRegistryId(); - const mock = getApiNock() - .get(`/api/v1/version/${version}`) - .basicAuth({ user: key }) - .reply(200, { version: '1.0.0' }) - .post('/api/v1/api-registry', body => { - requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1); - requestBody = JSON.parse(requestBody); - - return body.match('form-data; name="spec"'); - }) - .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) - .get('/api/v1/api-specification') - .basicAuth({ user: key }) - .reply(200, []) - .post('/api/v1/api-specification', { registryUUID }) - .basicAuth({ user: key }) - .reply(201, { _id: 1 }, { location: exampleRefLocation }); - - const spec = 'petstore.json'; - - await expect( - openapi.run({ - spec, - key, - version, - workingDirectory: './__tests__/__fixtures__/relative-ref-oas', - }) - ).resolves.toBe(successfulUpload(spec)); - - expect(console.info).toHaveBeenCalledTimes(0); - - expect(requestBody).toMatchSnapshot(); - - return mock.done(); - }); - describe('error handling', () => { it('should error if no api key provided', () => { return expect(