Skip to content

Commit

Permalink
Bulk Unit Testing:
Browse files Browse the repository at this point in the history
1. Testbed covering individual version files
2. Major swagger testbed updates - WIP
  • Loading branch information
gratcliff committed Jul 15, 2019
1 parent b2a7c05 commit 25db007
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 68 deletions.
1 change: 0 additions & 1 deletion lib/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ exports.run = async function({ args, opts }) {

versionCleaned = await request.post(`${config.host}/api/v1/version`, options);
} else {
// console.log(e)
throw new Error('Error occurred while retrieving swagger version.');
}
}
Expand Down
10 changes: 1 addition & 9 deletions lib/versions/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@ exports.weight = 4;
exports.action = 'versions:create';

exports.run = async function({ opts }) {
let { key } = opts;
let versionList;
const { version, codename, fork, main, beta, isPublic } = opts;

if (!key && opts.token) {
console.warn(
'Using `rdme` with --token has been deprecated. Please use --key and --id instead',
);
[key] = opts.token.split('-');
}
const { key, version, codename, fork, main, beta, isPublic } = opts;

if (!key) {
return Promise.reject(new Error('No api key provided. Please use --key'));
Expand Down
10 changes: 1 addition & 9 deletions lib/versions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ exports.weight = 4;
exports.action = 'versions:delete';

exports.run = async function({ opts }) {
let { key } = opts;
const { version } = opts;

if (!key && opts.token) {
console.warn(
'Using `rdme` with --token has been deprecated. Please use --key and --id instead',
);
[key] = opts.token.split('-');
}
const { key, version } = opts;

if (!key) {
return Promise.reject(new Error('No api key provided. Please use --key'));
Expand Down
9 changes: 1 addition & 8 deletions lib/versions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ exports.category = 'services';
exports.weight = 3;

exports.run = function({ opts }) {
let { key } = opts;

if (!key && opts.token) {
console.warn(
'Using `rdme` with --token has been deprecated. Please use --key and --id instead',
);
[key] = opts.token.split('-');
}
const { key } = opts;

if (!key) {
return Promise.reject(new Error('No api key provided. Please use --key'));
Expand Down
22 changes: 2 additions & 20 deletions lib/versions/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ exports.weight = 4;
exports.action = 'versions:update';

exports.run = async function({ opts }) {
let { key } = opts;
let versionList;
const { version, codename, fork, newVersion, main, beta, isPublic, deprecated } = opts;

if (!key && opts.token) {
console.warn(
'Using `rdme` with --token has been deprecated. Please use --key and --id instead.',
);
[key] = opts.token.split('-');
}
const { key, version, codename, newVersion, main, beta, isPublic, deprecated } = opts;

if (!key) {
return Promise.reject(new Error('No api key provided. Please use --key'));
Expand All @@ -30,16 +21,7 @@ exports.run = async function({ opts }) {
);
}

if (!fork) {
versionList = await request
.get(`${config.host}/api/v1/version`, {
json: true,
auth: { user: key },
})
.catch(err => Promise.reject(new Error(err)));
}

const promptResponse = await prompt(promptOpts.createVersionPrompt(versionList, opts, true));
const promptResponse = await prompt(promptOpts.createVersionPrompt(null, opts, true));
const options = {
json: {
codename: codename || '',
Expand Down
10 changes: 1 addition & 9 deletions lib/versions/versionId.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ exports.weight = 4;
exports.action = 'versions:versionId';

exports.run = function({ opts }) {
let { key } = opts;
const { version } = opts;

if (!key && opts.token) {
console.warn(
'Using `rdme` with --token has been deprecated. Please use --key and --id instead',
);
[key] = opts.token.split('-');
}
const { key, version } = opts;

if (!key) {
return Promise.reject(new Error('No api key provided. Please use --key'));
Expand Down
24 changes: 12 additions & 12 deletions test/swagger.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const nock = require('nock');
const config = require('config');
const fs = require('fs');
const Enquirer = require('enquirer');
// const promptHandler = require('../lib/prompts');
const promptHandler = require('../lib/prompts');

const swagger = require('../cli').bind(null, 'swagger');

const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
const version = '1.0.0';
jest.mock('../lib/prompts');

describe('swagger command', () => {
beforeAll(() => nock.disableNetConnect());
Expand Down Expand Up @@ -74,22 +74,22 @@ describe('swagger command', () => {
return swagger(['./test/fixtures/swagger.json'], { key, version }).then(() => mock.done());
});

xit('should request a version list if version is not found', async () => {
const enquirer = new Enquirer({ show: false });
enquirer.on('prompt', async prompt => {
await prompt.keypress(null, { name: 'down' });
await prompt.submit();
it('should request a version list if version is not found', () => {
promptHandler.generatePrompts.mockResolvedValue({
option: 'create',
versionSelection: '1.0.1',
});

nock(config.host)
const mock = nock(config.host)
.get(`/api/v1/version/${version}`)
.basicAuth({ user: key })
.reply(400);

const mock = nock(config.host)
.reply(400)
.get('/api/v1/version')
.basicAuth({ user: key })
.reply(200, [{ version: '1.0.0' }]);
.reply(200, [{ version: '1.0.1' }])
.post('/api/v1/version')
.basicAuth({ user: key })
.reply(200, { version: '1.0.1' });

return swagger(['./test/fixtures/swagger.json'], { key, version }).then(() => mock.done());
});
Expand Down
Loading

0 comments on commit 25db007

Please sign in to comment.