Skip to content

Commit

Permalink
fix(users): return user session on user create
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Joseph committed Oct 20, 2016
1 parent b39747b commit e552d12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/plugins/features/users/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports.create = function (payload, request) {

return Knex.transaction((transacting) => {
return new User().save(payload, { transacting })
.then((user) => {
.tap((user) => {
return new Dex().save({
user_id: user.id,
title,
Expand Down
17 changes: 14 additions & 3 deletions test/plugins/features/users/controller.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const JWT = require('jsonwebtoken');
const Sinon = require('sinon');

const Controller = require('../../../../src/plugins/features/users/controller');
Expand Down Expand Up @@ -85,16 +86,26 @@ describe('user controller', () => {
const password = 'test';

return Controller.create({ username, password }, request)
.then((session) => {
expect(session.token).to.be.a('string');
})
.then(() => new User().where('username', username).fetch())
.then((user) => {
expect(user.get('password')).to.not.eql(password);
expect(user.get('password')).to.have.length(60);
});
});

it('returns a session with a user token', () => {
const username = 'test';

return Controller.create({ username, password: 'test' }, request)
.then((session) => {
expect(session.token).to.be.a('string');

const user = JWT.decode(session.token);

expect(user.username).to.eql(username);
});
});

it('saves last login date', () => {
const username = 'test';

Expand Down

0 comments on commit e552d12

Please sign in to comment.