Skip to content

Commit

Permalink
fix: allow service criteria with mongodb keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Jun 19, 2019
1 parent 27b79ee commit 5318c5a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lib/campaign.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

const _ = require('lodash');
const { getString } = require('@lykmapipo/env');
const { stringify, parse } = require('@lykmapipo/common');
const {
model,
Schema,
Expand Down Expand Up @@ -206,6 +207,8 @@ const CampaignSchema = new Schema(
type: Mixed,
default: {},
fake: true,
set: data => stringify(data),
get: data => parse(data),
},

/**
Expand Down
23 changes: 13 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@
"mongoose": ">=5.6.0"
},
"dependencies": {
"@lykmapipo/common": ">=0.22.0",
"@lykmapipo/env": ">=0.9.1",
"@lykmapipo/express-common": ">=0.17.7",
"@lykmapipo/express-rest-actions": ">=0.6.4",
"@lykmapipo/kue-common": ">=0.3.4",
"@lykmapipo/mongoose-common": ">=0.25.3",
"@lykmapipo/mongoose-common": ">=0.25.4",
"@lykmapipo/mongoose-exportable": ">=0.3.4",
"@lykmapipo/phone": ">=0.5.0",
"@lykmapipo/tz-ega-sms": ">=0.5.3",
Expand Down
16 changes: 16 additions & 0 deletions test/integration/campaign.post.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ describe('Campaign Static Post', () => {
});
});

it('should be able to post with criteria', done => {
const campaign = Campaign.fake();
campaign.criteria = {
_id: { $in: ['5cffb7692e65f7001a2d5b02', '5cffb7692e65f7001a2d5b1d'] },
group: { $in: [] },
role: { $in: [] },
location: { $in: [] },
};
Campaign.post(campaign, (error, created) => {
expect(error).to.not.exist;
expect(created).to.exist;
expect(created._id).to.eql(campaign._id);
done(error, created);
});
});

after(done => {
Campaign.deleteMany(done);
});
Expand Down

0 comments on commit 5318c5a

Please sign in to comment.