diff --git a/app.js b/app.js index 51f2672..839067a 100644 --- a/app.js +++ b/app.js @@ -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')); diff --git a/controllers/votes.js b/controllers/votes.js index 0743163..195808a 100644 --- a/controllers/votes.js +++ b/controllers/votes.js @@ -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); diff --git a/test/votes.js b/test/votes.js index 24f99c0..7a46337 100644 --- a/test/votes.js +++ b/test/votes.js @@ -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` + }] + }); }); });