Skip to content

Commit

Permalink
feat: accounts.add({}) (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonyangme authored and gr2m committed Oct 16, 2016
1 parent bd11905 commit 1597def
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/accounts/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ function addAccount (state, properties, options) {
if (!options) {
options = {}
}

if (properties.username === '') {
return Promise.reject(errors.USERNAME_EMPTY)
}

var accountKey = 'org.couchdb.user:' + properties.username
var accountId = properties.id || uuid.v4()

Expand Down
6 changes: 6 additions & 0 deletions lib/utils/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ module.exports.USERNAME_EXISTS = hoodieError({
message: 'An account with that username already exists',
status: 409
})

module.exports.USERNAME_EMPTY = hoodieError({
name: 'Bad Request',
message: 'username must be set',
status: 400
})
2 changes: 1 addition & 1 deletion test/unit/accounts/add-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var test = require('tap').test
var addAccount = require('../../../lib/accounts/add')

test('addAccount', function (group) {
group.test('with empty username', {skip: true}, function (t) {
group.test('with empty username', function (t) {
t.plan(3)

var state = {
Expand Down

0 comments on commit 1597def

Please sign in to comment.