Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed May 2, 2018
1 parent d4e312d commit e102789
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
32 changes: 19 additions & 13 deletions lib/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,29 @@ exports.run = function({ args, opts }) {
if (err.statusCode === 400) {
console.log(err.error);
return Promise.reject();
};
}

return Promise.reject(err);
}

function createDoc(slug, file, err) {
if (err.statusCode !== 404) return Promise.reject(err.error);

return request.post(`${config.host}/api/v1/docs`, {
json: { slug, body: file.content, ...file.data },
...options,
}).catch(validationErrors);
return request
.post(`${config.host}/api/v1/docs`, {
json: { slug, body: file.content, ...file.data },
...options,
})
.catch(validationErrors);
}

function updateDoc(slug, file, existingDoc) {
return request.put(`${config.host}/api/v1/docs/${slug}`, {
json: Object.assign(existingDoc, { body: file.content, ...file.data }),
...options,
}).catch(validationErrors);
return request
.put(`${config.host}/api/v1/docs/${slug}`, {
json: Object.assign(existingDoc, { body: file.content, ...file.data }),
...options,
})
.catch(validationErrors);
}

return Promise.all(
Expand All @@ -68,10 +72,12 @@ exports.run = function({ args, opts }) {
// Stripping the markdown extension from the filename
const slug = filename.replace(path.extname(filename), '');

return request.get(`${config.host}/api/v1/docs/${slug}`, {
json: true,
...options,
}).then(updateDoc.bind(null, slug, file), createDoc.bind(null, slug, file));
return request
.get(`${config.host}/api/v1/docs/${slug}`, {
json: true,
...options,
})
.then(updateDoc.bind(null, slug, file), createDoc.bind(null, slug, file));
}),
);
};
4 changes: 3 additions & 1 deletion lib/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ exports.run = function({ args, opts }) {
}

if (!args[0]) {
return Promise.reject(new Error('No swagger file provided. Usage `rdme swagger <swagger-file>`'));
return Promise.reject(
new Error('No swagger file provided. Usage `rdme swagger <swagger-file>`'),
);
}

function success(data) {
Expand Down
18 changes: 8 additions & 10 deletions test/swagger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@ const swagger = require('../cli').bind(null, 'swagger');
const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';

describe('swagger command', () => {
beforeAll(() => nock.disableNetConnect());
afterAll(() => nock.cleanAll());

it('should error if no api key provided', () =>
swagger(['./test/fixtures/swagger.json'], {}).catch(err => {
assert.equal(err.message, 'No api key provided. Please use --key');
})
);
}));

it('should error if no file provided', () =>
swagger([], { key }).catch(err => {
assert.equal(err.message, 'No swagger file provided. Usage `rdme swagger <swagger-file>`');
})
);
}));

it('should POST to the swagger api if no id provided', () => {
const mock = nock(config.host)
.post('/api/v1/swagger', body => body.match('form-data; name="swagger"'))
.basicAuth({ user: key })
.reply(201);

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

it('should PUT to the swagger api if id is provided', () => {
Expand All @@ -38,8 +36,7 @@ describe('swagger command', () => {
.basicAuth({ user: key })
.reply(201);

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

it('should still work with `token`', () => {
Expand All @@ -49,7 +46,8 @@ describe('swagger command', () => {
.basicAuth({ user: key })
.reply(201);

return swagger(['./test/fixtures/swagger.json'], { token: `${key}-${id}` })
.then(() => mock.done());
return swagger(['./test/fixtures/swagger.json'], { token: `${key}-${id}` }).then(() =>
mock.done(),
);
});
});

0 comments on commit e102789

Please sign in to comment.