Skip to content

Commit

Permalink
feat: add campaign audiendences
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Jun 15, 2019
1 parent c9683ad commit 5c15dae
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
32 changes: 31 additions & 1 deletion lib/campaign.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ const {
CHANNEL_SMS,
CHANNEL_EMAIL,
CHANNEL_PUSH,
CHANNELS
CHANNELS,
AUDIENCE_REPORTERS,
AUDIENCE_CUSTOMERS,
AUDIENCE_SUBSCRIBERS,
AUDIENCE_EMPLOYEES,
AUDIENCES,
} = require('./common');


Expand Down Expand Up @@ -126,6 +131,24 @@ const CampaignSchema = new Schema({
fake: { generator: 'lorem', type: 'sentence' }
},

/**
* @name audiences
* @description Target audiences for a campaign
* e.g SMS, EMAIL etc.
* @type {Object}
* @since 0.1.0
* @version 1.0.0
* @instance
*/
audiences: {
type: [String],
enum: AUDIENCES,
index: true,
searchable: true,
taggable: true,
fake: true
},

/**
* @name channels
* @description Allowed channels to be used to send a campaign
Expand Down Expand Up @@ -214,6 +237,13 @@ CampaignSchema.statics.CHANNEL_PUSH = CHANNEL_PUSH;
CampaignSchema.statics.CHANNELS = CHANNELS;


CampaignSchema.statics.AUDIENCE_REPORTERS = AUDIENCE_REPORTERS;
CampaignSchema.statics.AUDIENCE_CUSTOMERS = AUDIENCE_CUSTOMERS;
CampaignSchema.statics.AUDIENCE_SUBSCRIBERS = AUDIENCE_SUBSCRIBERS;
CampaignSchema.statics.AUDIENCE_EMPLOYEES = AUDIENCE_EMPLOYEES;
CampaignSchema.statics.AUDIENCES = AUDIENCES;


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

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

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

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

Expand Down

0 comments on commit 5c15dae

Please sign in to comment.