Skip to content

Commit

Permalink
feat: add campaign channel
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Jun 15, 2019
1 parent fa62688 commit f0088af
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
33 changes: 31 additions & 2 deletions lib/campaign.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const {
FORM_WARNING,
FORM_ANNOUNCEMENT,
FORM_REMINDER,
FORMS
FORMS,
CHANNEL_SMS,
CHANNEL_EMAIL,
CHANNEL_PUSH,
CHANNELS
} = require('./common');


Expand Down Expand Up @@ -115,7 +119,26 @@ const CampaignSchema = new Schema({
index: true,
searchable: true,
fake: { generator: 'lorem', type: 'sentence' }
}
},

/**
* @name channels
* @description Allowed channels to be used to send a campaign
* e.g SMS, EMAIL etc.
* @type {Object}
* @since 0.1.0
* @version 1.0.0
* @instance
*/
channels: {
type: [String],
enum: CHANNELS,
default: [CHANNEL_SMS],
index: true,
searchable: true,
taggable: true,
fake: true
},
}, SCHEMA_OPTIONS);


Expand All @@ -137,6 +160,12 @@ CampaignSchema.statics.FORM_REMINDER = FORM_REMINDER;
CampaignSchema.statics.FORMS = FORMS;


CampaignSchema.statics.CHANNEL_SMS = CHANNEL_SMS;
CampaignSchema.statics.CHANNEL_EMAIL = CHANNEL_EMAIL;
CampaignSchema.statics.CHANNEL_PUSH = CHANNEL_PUSH;
CampaignSchema.statics.CHANNELS = CHANNELS;


/*
*------------------------------------------------------------------------------
* Plugins
Expand Down
16 changes: 16 additions & 0 deletions test/unit/campaign.schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,20 @@ describe('Campaign Schema', () => {
expect(message.options.searchable).to.be.true;
expect(message.options.fake).to.exist;
});

it('should have channels field', () => {
const channels = Campaign.path('channels');

expect(channels).to.exist;
expect(channels).to.be.an.instanceof(SchemaTypes.Array);
expect(channels.instance).to.be.equal('Array');
expect(channels).to.be.an('object');
expect(channels.options.enum).to.exist;
expect(channels.options.enum).to.be.eql(Campaign.CHANNELS);
expect(channels.options.default).to.exist;
expect(channels.options.index).to.be.true;
expect(channels.options.searchable).to.be.true;
expect(channels.options.taggable).to.be.true;
expect(channels.options.fake).to.exist;
});
});

0 comments on commit f0088af

Please sign in to comment.