Skip to content

Commit

Permalink
fix: PATCH /accounts/{id} if account not found (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
minrwhite authored and gr2m committed Oct 22, 2016
1 parent a619d15 commit e8fa83b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
9 changes: 8 additions & 1 deletion routes/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ function accountRoutes (server, options, next) {
include: request.query.include,
admin: true
}, account)
})
},
function (error) {
if (error.status === 404) {
throw errors.ACCOUNT_ID_NOT_FOUND
}

throw error
})

.then(function (json) {
reply(json).code(201)
Expand Down
6 changes: 6 additions & 0 deletions routes/utils/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ module.exports.NO_PROFILE_ACCOUNT = hoodieError({
status: 404
})

module.exports.ACCOUNT_ID_NOT_FOUND = hoodieError({
name: 'Not Found',
message: 'Account Id Not Found',
status: 404
})

module.exports.accountIdConflict = function (id) {
return hoodieError({
name: 'Conflict',
Expand Down
36 changes: 34 additions & 2 deletions tests/integration/routes/accounts/patch-accounts-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,40 @@ getServer(function (error, server) {
t.end()
})

group.test('Not found', {todo: true}, function (t) {
t.end()
group.test('Not found', function (t) {
var couchdb = nock('http://localhost:5984')
.get('/_users/_design/byId/_view/byId')
.query({
key: '"xyz1234"',
include_docs: true
})
.reply(200, {
total_rows: 1,
offset: 0,
rows: []
})

server.inject({
method: 'PATCH',
url: '/accounts/xyz1234',
headers: routeOptions.headers,
payload: {
data: {
type: 'account',
id: 'xyz1234',
attributes: {
password: 'newsecret'
}
}
}
}, function (response) {
t.is(couchdb.pendingMocks()[0], undefined, 'all mocks satisfied')
t.is(response.statusCode, 404, 'returns 404 status')
t.is(response.result.errors.length, 1, 'returns one error')
t.is(response.result.errors[0].title, 'Not Found', 'returns "Not Found" error')
t.is(response.result.errors[0].detail, 'Account Id Not Found', 'returns "Account Id Not Found" message')
t.end()
})
})

group.test('data.type & data.id don’t match existing document', function (t) {
Expand Down

0 comments on commit e8fa83b

Please sign in to comment.