Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Oct 1, 2018
1 parent c00f52d commit 8927368
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function(cmd, args, opts = {}) {
[command, subcommand] = cmd.split(':');
}

const optsWithStoredKey = Object.assign({}, { key: configStore.get('apiKey') }, opts)
const optsWithStoredKey = Object.assign({}, { key: configStore.get('apiKey') }, opts);

try {
return load(opts.help ? 'help' : command, subcommand).run({ args, opts: optsWithStoredKey });
Expand Down
2 changes: 1 addition & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
// eslint-disable-next-line global-require
cli: require('../package.json').name,
host: 'https://dash.readme.io',
hub: 'https://{project}.readme.io'
hub: 'https://{project}.readme.io',
};
23 changes: 13 additions & 10 deletions lib/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getCredentials() {

return resolve({ email, password });
});
})
});
});
}

Expand Down Expand Up @@ -48,12 +48,15 @@ exports.run = async function({ opts }) {
return Promise.reject(err);
}

return request.post(`${config.host}/api/v1/login`, {
json: { email, password, project },
}).then((res) => {
configStore.set('apiKey', res.apiKey);
configStore.set('email', email);
configStore.set('project', project);
return `Successfully logged in as ${email.green} in the ${project.blue} project`;
}).catch(badRequest);
}
return request
.post(`${config.host}/api/v1/login`, {
json: { email, password, project },
})
.then(res => {
configStore.set('apiKey', res.apiKey);
configStore.set('email', email);
configStore.set('project', project);
return `Successfully logged in as ${email.green} in the ${project.blue} project`;
})
.catch(badRequest);
};
4 changes: 2 additions & 2 deletions lib/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.weight = 1;

const configStore = require('../lib/configstore');

exports.run = function ({ opts }) {
exports.run = function({ opts }) {
const project = configStore.get('project');

if (!project) {
Expand All @@ -17,4 +17,4 @@ exports.run = function ({ opts }) {
return (opts.mockOpen || open)(config.hub.replace('{project}', project), {
wait: false,
}).then(() => null);
}
};
8 changes: 4 additions & 4 deletions test/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ describe('login command', () => {
beforeAll(() => nock.disableNetConnect());
afterAll(() => nock.cleanAll());

it('should error if no project provided', (done) =>
it('should error if no project provided', done =>
login([], {}).catch(err => {
assert.equal(err.message, 'No project subdomain provided. Please use --project');
return done();
}));

it('should error if email is invalid', (done) =>
it('should error if email is invalid', done =>
login([], { project: 'subdomain', email: 'this-is-not-an-email' }).catch(err => {
assert.equal(err.message, 'You must provide a valid email address.');
return done();
Expand All @@ -40,7 +40,7 @@ describe('login command', () => {
});
});

it('should error if invalid credentials are given', (done) => {
it('should error if invalid credentials are given', done => {
const email = 'dom@readme.io';
const password = '123456';
const project = 'subdomain';
Expand All @@ -52,7 +52,7 @@ describe('login command', () => {
error: 'Bad Request',
});

return login([], { email, password, project }).catch((err) => {
return login([], { email, password, project }).catch(err => {
mock.done();
assert.equal(err.error, 'Bad Request');
assert.equal(err.description, 'Invalid email/password');
Expand Down
6 changes: 3 additions & 3 deletions test/open.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const configStore = require('../lib/configstore');
const open = require('../cli').bind(null, 'open');

describe('open command', () => {
it('should error if no project provided', (done) => {
it('should error if no project provided', done => {
configStore.delete('project');

open([], {}).catch(err => {
assert.equal(err.message, `Please login using ${config.cli} login`);
return done();
})
});
});

it('should open the project', (done) => {
it('should open the project', done => {
configStore.set('project', 'subdomain');

function mockOpen(url) {
Expand Down

0 comments on commit 8927368

Please sign in to comment.