Skip to content

Commit 25db007

Browse files
committed
Bulk Unit Testing:
1. Testbed covering individual version files 2. Major swagger testbed updates - WIP
1 parent b2a7c05 commit 25db007

File tree

8 files changed

+267
-68
lines changed

8 files changed

+267
-68
lines changed

lib/swagger.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ exports.run = async function({ args, opts }) {
104104

105105
versionCleaned = await request.post(`${config.host}/api/v1/version`, options);
106106
} else {
107-
// console.log(e)
108107
throw new Error('Error occurred while retrieving swagger version.');
109108
}
110109
}

lib/versions/create.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,8 @@ exports.weight = 4;
99
exports.action = 'versions:create';
1010

1111
exports.run = async function({ opts }) {
12-
let { key } = opts;
1312
let versionList;
14-
const { version, codename, fork, main, beta, isPublic } = opts;
15-
16-
if (!key && opts.token) {
17-
console.warn(
18-
'Using `rdme` with --token has been deprecated. Please use --key and --id instead',
19-
);
20-
[key] = opts.token.split('-');
21-
}
13+
const { key, version, codename, fork, main, beta, isPublic } = opts;
2214

2315
if (!key) {
2416
return Promise.reject(new Error('No api key provided. Please use --key'));

lib/versions/delete.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ exports.weight = 4;
77
exports.action = 'versions:delete';
88

99
exports.run = async function({ opts }) {
10-
let { key } = opts;
11-
const { version } = opts;
12-
13-
if (!key && opts.token) {
14-
console.warn(
15-
'Using `rdme` with --token has been deprecated. Please use --key and --id instead',
16-
);
17-
[key] = opts.token.split('-');
18-
}
10+
const { key, version } = opts;
1911

2012
if (!key) {
2113
return Promise.reject(new Error('No api key provided. Please use --key'));

lib/versions/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ exports.category = 'services';
66
exports.weight = 3;
77

88
exports.run = function({ opts }) {
9-
let { key } = opts;
10-
11-
if (!key && opts.token) {
12-
console.warn(
13-
'Using `rdme` with --token has been deprecated. Please use --key and --id instead',
14-
);
15-
[key] = opts.token.split('-');
16-
}
9+
const { key } = opts;
1710

1811
if (!key) {
1912
return Promise.reject(new Error('No api key provided. Please use --key'));

lib/versions/update.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@ exports.weight = 4;
99
exports.action = 'versions:update';
1010

1111
exports.run = async function({ opts }) {
12-
let { key } = opts;
13-
let versionList;
14-
const { version, codename, fork, newVersion, main, beta, isPublic, deprecated } = opts;
15-
16-
if (!key && opts.token) {
17-
console.warn(
18-
'Using `rdme` with --token has been deprecated. Please use --key and --id instead.',
19-
);
20-
[key] = opts.token.split('-');
21-
}
12+
const { key, version, codename, newVersion, main, beta, isPublic, deprecated } = opts;
2213

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

33-
if (!fork) {
34-
versionList = await request
35-
.get(`${config.host}/api/v1/version`, {
36-
json: true,
37-
auth: { user: key },
38-
})
39-
.catch(err => Promise.reject(new Error(err)));
40-
}
41-
42-
const promptResponse = await prompt(promptOpts.createVersionPrompt(versionList, opts, true));
24+
const promptResponse = await prompt(promptOpts.createVersionPrompt(null, opts, true));
4325
const options = {
4426
json: {
4527
codename: codename || '',

lib/versions/versionId.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ exports.weight = 4;
77
exports.action = 'versions:versionId';
88

99
exports.run = function({ opts }) {
10-
let { key } = opts;
11-
const { version } = opts;
12-
13-
if (!key && opts.token) {
14-
console.warn(
15-
'Using `rdme` with --token has been deprecated. Please use --key and --id instead',
16-
);
17-
[key] = opts.token.split('-');
18-
}
10+
const { key, version } = opts;
1911

2012
if (!key) {
2113
return Promise.reject(new Error('No api key provided. Please use --key'));

test/swagger.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const nock = require('nock');
22
const config = require('config');
33
const fs = require('fs');
4-
const Enquirer = require('enquirer');
5-
// const promptHandler = require('../lib/prompts');
4+
const promptHandler = require('../lib/prompts');
65

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

98
const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
109
const version = '1.0.0';
10+
jest.mock('../lib/prompts');
1111

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

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

84-
nock(config.host)
83+
const mock = nock(config.host)
8584
.get(`/api/v1/version/${version}`)
8685
.basicAuth({ user: key })
87-
.reply(400);
88-
89-
const mock = nock(config.host)
86+
.reply(400)
9087
.get('/api/v1/version')
9188
.basicAuth({ user: key })
92-
.reply(200, [{ version: '1.0.0' }]);
89+
.reply(200, [{ version: '1.0.1' }])
90+
.post('/api/v1/version')
91+
.basicAuth({ user: key })
92+
.reply(200, { version: '1.0.1' });
9393

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

0 commit comments

Comments
 (0)