Skip to content

Commit

Permalink
Feature/standardize entitiy create output connect #311 (#343)
Browse files Browse the repository at this point in the history
* user\app\cred create same format

* tests

* rm unused config-dir prop
  • Loading branch information
DrMegavolt authored and kevinswiber committed Jul 26, 2017
1 parent 84b4604 commit 059837b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 20 deletions.
4 changes: 0 additions & 4 deletions bin/eg-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ module.exports = class EgGenerator extends Generator {
return yargs
.boolean(['no-color', 'q'])
.describe('no-color', 'Disable color in prompts')
.string('config-dir')
.describe('config-dir', 'Directory for express-gateway configuration')
.nargs('config-dir', 1)
.describe('q', 'Only show major pieces of output')
.group(['config-dir'], 'Configure:')
.group(['no-color', 'q'], 'Options:')
.alias('q', 'quiet')
.help('h');
Expand Down
1 change: 1 addition & 0 deletions bin/generators/apps/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = class extends eg.Generator {
.then(newApp => {
if (!argv.q) {
this.log.ok(`Created ${newApp.id}`);
this.stdout(JSON.stringify(newApp, null, 2));
} else {
this.stdout(newApp.id);
}
Expand Down
3 changes: 2 additions & 1 deletion bin/generators/credentials/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ module.exports = class extends eg.Generator {
_output (credential, options) {
let argv = this.argv;
if (!argv.q) {
this.log.ok(`Created \n ${JSON.stringify(credential, null, 2)}`);
this.log.ok(`Created ${credential.id || credential.keyId}`);
this.stdout(JSON.stringify(credential, null, 2));
} else {
if (argv.type === 'key-auth') {
this.stdout(`${credential.keyId}:${credential.keySecret}`);
Expand Down
3 changes: 2 additions & 1 deletion bin/generators/users/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ module.exports = class extends eg.Generator {
return this._insert(user)
.then(newUser => {
if (!argv.q) {
this.log.ok(`Created ${newUser.username}`);
this.log.ok(`Created ${newUser.id}`);
this.stdout(JSON.stringify(newUser, null, 2));
} else {
this.stdout(newUser.id);
}
Expand Down
11 changes: 9 additions & 2 deletions test/cli/apps/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ describe('eg apps create', () => {

it('creates an app from prompts with username', done => {
env.hijack(namespace, generator => {
let output = null;
let output, text;

generator.once('run', () => {
generator.log.error = message => {
done(new Error(message));
};
generator.log.ok = message => {
text = message;
};
generator.stdout = message => {
output = message;
};

Expand All @@ -58,7 +61,11 @@ describe('eg apps create', () => {
assert.equal(app.name, 'appy');
assert.equal(app.redirectUri, 'http://localhost:3000/cb');

assert.equal(output, `Created ${app.id}`);
assert.equal(text, `Created ${app.id}`);

let stdoutApp = JSON.parse(output);
assert.equal(stdoutApp.name, 'appy');
assert.equal(stdoutApp.redirectUri, 'http://localhost:3000/cb');
done();
});
});
Expand Down
20 changes: 13 additions & 7 deletions test/cli/credentials/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,26 @@ describe('eg credentials create', () => {
it('creates a credential from prompts', done => {
env.hijack(namespace, generator => {
let output = null;
let text = null;

generator.once('run', () => {
generator.log.error = message => {
done(new Error(message));
};
generator.log.ok = message => {
text = message;
};
generator.stdout = message => {
output = message;
};

helpers.mockPrompt(generator, {});
});

generator.once('end', () => {
assert.ok(output.indexOf('Created ') === 0);
let loggedCred = JSON.parse(output.replace('Created ', ''));
let loggedCred = JSON.parse(output);
assert.equal(text, 'Created ' + loggedCred.keyId);

return adminHelper.admin.credentials.info(loggedCred.keyId, 'key-auth')
.then(cred => {
assert.ok(cred.keyId);
Expand All @@ -68,16 +73,17 @@ describe('eg credentials create', () => {

env.hijack(namespace, generator => {
let output = null;

let text = null;
generator.once('run', () => {
generator.log.error = message => {
done(new Error(message));
};
generator.log = message => {
generator.stdout = message => {
output = message;
};

generator.log.ok = message => {
output = message;
text = message;
};

generator.stdin = new PassThrough();
Expand All @@ -86,8 +92,8 @@ describe('eg credentials create', () => {
});

generator.once('end', () => {
assert.ok(output.indexOf('Created ') === 0);
let loggedCred = JSON.parse(output.replace('Created ', ''));
let loggedCred = JSON.parse(output);
assert.equal(text, 'Created ' + loggedCred.keyId);
return adminHelper.admin.credentials.info(loggedCred.keyId, 'key-auth')
.then(cred => {
assert.ok(cred.keyId);
Expand Down
28 changes: 23 additions & 5 deletions test/cli/users/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ describe('eg users create', () => {

it('creates a user from prompts', done => {
env.hijack(namespace, generator => {
let output = null;
let output, text;

generator.once('run', () => {
generator.log.error = message => {
done(new Error(message));
};
generator.log.ok = message => {
text = message;
};
generator.stdout = message => {
output = message;
};

Expand All @@ -45,16 +48,21 @@ describe('eg users create', () => {
});

generator.once('end', () => {
let stdOutUser = JSON.parse(output);
return adminHelper.admin.users.info(username)
.then(user => {
assert.equal(user.username, username);
assert.equal(user.firstname, 'La');
assert.equal(user.lastname, 'Deeda');

assert.equal(output, 'Created ' + username);
assert.equal(text, 'Created ' + user.id);

assert.equal(stdOutUser.username, username);
assert.equal(stdOutUser.firstname, 'La');
assert.equal(stdOutUser.lastname, 'Deeda');

done();
});
}).catch(done);
});
});

Expand All @@ -64,25 +72,35 @@ describe('eg users create', () => {
it('creates a user from properties', done => {
env.hijack(namespace, generator => {
let output = null;
let text = null;

generator.once('run', () => {
generator.log.error = message => {
done(new Error(message));
};
generator.log.ok = message => {
text = message;
};
generator.stdout = message => {
output = message;
};
});

generator.once('end', () => {
let stdOutUser = JSON.parse(output);
return adminHelper.admin.users.info(username)
.then(user => {
assert.equal(user.username, username);
assert.equal(user.firstname, 'La');
assert.equal(user.lastname, 'Deeda');
assert.equal(output, 'Created ' + username);
assert.equal(text, 'Created ' + user.id);

assert.equal(stdOutUser.username, username);
assert.equal(stdOutUser.firstname, 'La');
assert.equal(stdOutUser.lastname, 'Deeda');

done();
});
}).catch(done);
});
});

Expand Down

0 comments on commit 059837b

Please sign in to comment.