Skip to content

Commit

Permalink
add error messages, remove TODO comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkvon committed Mar 27, 2018
1 parent acf84fb commit 9fa25d2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ app.use('/messages', require('./routes/messages'));
app.use('/account', require('./routes/account'));
app.use('/contacts', require('./routes/contacts'));
app.use('/ideas', require('./routes/ideas'));
// vote for ideas, ... TODO to be generalized for not only ideas
// vote for ideas, ...
app.use('/ideas', require('./routes/votes'));
app.use('/comments', require('./routes/votes'));

Expand Down
15 changes: 13 additions & 2 deletions controllers/votes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@ async function post(req, res, next) {
switch (e.code) {
// duplicate vote
case 409: {
return res.status(409).end();
return res.status(409).json({
errors: [{
status: 409,
detail: 'duplicate vote'
}]
});
}
// missing idea
case 404: {
return res.status(404).end();
return res.status(404).json({
errors: [{
status: 404,
detail: `${primarys.slice(0, -1)} doesn't exist`
}]
});

}
default: {
return next(e);
Expand Down
18 changes: 16 additions & 2 deletions test/votes.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,31 @@ function voteTestFactory(primary, only=false) {

voteBody.data.attributes.value = 1;

await agent
const response = await agent
.post(`/${primarys}/${existentPrimary.id}/votes`)
.send(voteBody)
.expect(409);

should(response.body).deepEqual({
errors: [{
status: 409,
detail: 'duplicate vote'
}]
});
});

it(`[${primary} doesn't exist] 404`, async () => {
await agent
const response = await agent
.post(`/${primarys}/1111111/votes`)
.send(voteBody)
.expect(404);

should(response.body).deepEqual({
errors: [{
status: 404,
detail: `${primary} doesn't exist`
}]
});
});
});

Expand Down

0 comments on commit 9fa25d2

Please sign in to comment.