Skip to content

Commit

Permalink
fix(bodies): not listing deleted bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Mar 23, 2020
1 parent d2ebb90 commit ed18ebe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion middlewares/bodies.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { sequelize } = require('../lib/sequelize');

exports.listAllBodies = async (req, res) => {
const result = await Body.findAndCountAll({
where: helpers.filterBy(req.query.query, constants.FIELDS_TO_QUERY.BODY),
where: { status: 'active' },
...helpers.getPagination(req.query),
order: helpers.getSorting(req.query)
});
Expand Down
20 changes: 20 additions & 0 deletions test/api/bodies-listing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,24 @@ describe('Bodies list', () => {
expect(res.body.data.length).toEqual(1);
expect(res.body.data[0].id).toEqual(firstBody.id);
});

test('should filter deleted bodies', async () => {
const user = await generator.createUser();
const token = await generator.createAccessToken({}, user);

await generator.createBody({ status: 'deleted' });

const res = await request({
uri: '/bodies',
method: 'GET',
headers: { 'X-Auth-Token': token.value }
});

expect(res.statusCode).toEqual(200);
expect(res.body.success).toEqual(true);
expect(res.body).toHaveProperty('data');
expect(res.body).toHaveProperty('meta');
expect(res.body).not.toHaveProperty('errors');
expect(res.body.data.length).toEqual(0);
});
});

0 comments on commit ed18ebe

Please sign in to comment.