Skip to content

Commit

Permalink
fix PATCH perspective without filter array throws error bug
Browse files Browse the repository at this point in the history
  • Loading branch information
annyhe committed Apr 14, 2017
1 parent 9ac3525 commit 69223cc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 0 additions & 1 deletion api/v1/controllers/perspectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ module.exports = {
* @param {Function} next - The next middleware function in the stack
*/
patchPerspective(req, res, next) {
helper.validateFilterAndThrowError(req.body);
doPatch(req, res, next, helper);
},

Expand Down
6 changes: 6 additions & 0 deletions api/v1/helpers/verbs/doPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const event = u.realtimeEvents;
const httpStatus = require('../../constants').httpStatus;
const constants = require('../../../../cache/sampleStore').constants;
const redisModelSample = require('../../../../cache/models/samples');
const helper = require('../nouns/perspectives');

/**
* Updates a record and sends the udpated record back in the json response
Expand Down Expand Up @@ -68,6 +69,11 @@ function doPatch(req, res, next, props) {

patchPromise
.then((retVal) => {
if (props.modelName === 'Perspective') {
helper.validateFilterAndThrowError(retVal.get());

}

resultObj.dbTime = new Date() - resultObj.reqStartTime;
u.logAPI(req, resultObj, retVal);

Expand Down
29 changes: 27 additions & 2 deletions tests/api/v1/perspectives/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ describe(`api: PATCH ${path}`, () => {
after(u.forceDelete);
after(tu.forceDeleteUser);

it('update filter types to include ', (done) => {
api.patch(`${path}/${perspectiveId}`)
.set('Authorization', token)
.send({
aspectFilterType: 'INCLUDE',
aspectTagFilterType: 'INCLUDE',
subjectTagFilterType: 'INCLUDE',
statusFilterType: 'INCLUDE',
})
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
done(err);
}

expect(res.body.aspectFilterType).to.equal('INCLUDE');
expect(res.body.aspectTagFilterType).to.equal('INCLUDE');
expect(res.body.subjectTagFilterType).to.equal('INCLUDE');
expect(res.body.statusFilterType).to.equal('INCLUDE');
done();
});
});

it('patch rootSubject', (done) => {
api.patch(`${path}/${perspectiveId}`)
.set('Authorization', token)
Expand Down Expand Up @@ -86,8 +109,10 @@ describe(`api: PATCH ${path}`, () => {
it('cannot patch filter with include = []', (done) => {
api.patch(`${path}/${perspectiveId}`)
.set('Authorization', token)
.send({ subjectTagFilter: [],
aspectFilterType: 'INCLUDE', })
.send({
subjectTagFilter: [],
subjectTagFilterType: 'INCLUDE',
})
.expect(constants.httpStatus.BAD_REQUEST)
.end((err, res) => {
if (err) {
Expand Down

0 comments on commit 69223cc

Please sign in to comment.