Skip to content

Commit

Permalink
Merge pull request #12 from joelnet/develop
Browse files Browse the repository at this point in the history
add username to registration
  • Loading branch information
joelnet committed Jun 13, 2017
2 parents c149c3d + 85cc287 commit d531c9c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
26 changes: 23 additions & 3 deletions actions/user-registration/__tests__/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('user-registration', () => {
.catch(err => expect(err).toBe('[400] "username" is required'))
})

test('invalid username returns [400] "username" must be a valid email', () => {
test('email returns [400] "email" is required', () => {
expect.assertions(1)

const request = {
Expand All @@ -60,7 +60,23 @@ describe('user-registration', () => {
}

return userRegistration(request, actions)
.catch(err => expect(err).toBe('[400] "username" must be a valid email'))
.catch(err => expect(err).toBe('[400] "email" is required'))
})

test('invalid email returns [400] "email" must be a valid email', () => {
expect.assertions(1)

const request = {
pathParameters: { realm: 'realm' },
body: querystring.stringify({
client_id: 'client_id',
username: 'username',
email: 'invalid',
})
}

return userRegistration(request, actions)
.catch(err => expect(err).toBe('[400] "email" must be a valid email'))
})

test('no password returns [400] "password" is required', () => {
Expand All @@ -71,6 +87,7 @@ describe('user-registration', () => {
body: querystring.stringify({
client_id: 'client_id',
username: 'test@test.com',
email: 'test@test.com',
})
}

Expand All @@ -86,6 +103,7 @@ describe('user-registration', () => {
body: querystring.stringify({
client_id: 'client_id',
username: 'test@test.com',
email: 'test@test.com',
password: 'password'
})
}
Expand All @@ -106,6 +124,7 @@ describe('user-registration', () => {
body: querystring.stringify({
client_id: 'client_id',
username: 'test@test.com',
email: 'test@test.com',
password: 'password'
})
}
Expand All @@ -125,7 +144,8 @@ describe('user-registration', () => {
pathParameters: { realm: 'realm' },
body: querystring.stringify({
client_id: 'client_id',
username: 'test2@test.com',
username: 'username',
email: 'test2@test.com',
password: 'password'
})
}
Expand Down
33 changes: 25 additions & 8 deletions actions/user-registration/__tests__/request.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,39 @@ describe('userRegistrationRequest', () => {
const data = {
pathParameters: { realm: 'realm' },
body: querystring.encode({
client_id: 'client_id'
client_id: 'client_id',
})
}
return validate(I)(data)
.catch(error => expect(error).toBe('[400] "username" is required'))
})

test('invalid username returns [400] "username" must be a valid email', () => {
test('no email returns [400] "email" is required', () => {
expect.assertions(1)
const data = {
pathParameters: { realm: 'realm' },
body: querystring.encode({
client_id: 'client_id',
username: 'invalid'
username: 'username',
})
}
return validate(I)(data)
.catch(error => expect(error).toBe('[400] "username" must be a valid email'))
.catch(error => expect(error).toBe('[400] "email" is required'))
})

test('invalid email returns [400] "email" must be a valid email', () => {
expect.assertions(1)
const data = {
pathParameters: { realm: 'realm' },
body: querystring.encode({
client_id: 'client_id',
username: 'username',
email: 'invalid',
password: 'password',
})
}
return validate(I)(data)
.catch(error => expect(error).toBe('[400] "email" must be a valid email'))
})

test('no password returns [400] "password" is required', () => {
Expand All @@ -50,7 +65,8 @@ describe('userRegistrationRequest', () => {
pathParameters: { realm: 'realm' },
body: querystring.encode({
client_id: 'client_id',
username: 'email@address.com'
username: 'email@address.com',
email: 'test@test.com',
})
}
return validate(I)(data)
Expand All @@ -63,12 +79,13 @@ describe('userRegistrationRequest', () => {
pathParameters: { realm: 'realm' },
body: querystring.encode({
client_id: 'client_id',
username: 'email@address.com',
password: 'password'
username: 'username',
email: 'test@test.com',
password: 'password',
})
}
return validate(request => {
expect(request).toEqual({ realm: 'realm', client_id: 'client_id', username: 'email@address.com', password: 'password' })
expect(request).toEqual({ realm: 'realm', client_id: 'client_id', username: 'username', email: 'test@test.com', password: 'password' })
})(data)
})
})
3 changes: 2 additions & 1 deletion actions/user-registration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const exceptionMapper = require('../../lib/exceptionMapper')

const toUserModel = (state) => ({
userId: `${state.props.realm}:${state.props.username}`,
emailAddress: state.props.username,
username: state.props.username,
emailAddress: state.props.email,
password: state.props.password,
realm: state.props.realm,
roles: [],
Expand Down
3 changes: 2 additions & 1 deletion actions/user-registration/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const getRequest = event =>
const schema = Joi.object().keys({
realm: Joi.string().required(),
client_id: Joi.string().required(),
username: Joi.string().email().required(),
username: Joi.string().required(),
email: Joi.string().email().required(),
password: Joi.string().required(),
redirect_uri: Joi.string()
})
Expand Down
1 change: 1 addition & 0 deletions services/storage/dynamodb/create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const docClient = require('./doc-client')

const schema = Joi.object().keys({
userId: Joi.string().regex(/^[^:]+:[^:]+:[^:]+$/).required(),
username: Joi.string().required(),
emailAddress: Joi.string().email().required(),
password: Joi.string().required(),
realm: Joi.string().regex(/^[^:]+:[^:]+$/).required(),
Expand Down

0 comments on commit d531c9c

Please sign in to comment.