Skip to content

Commit 8ea9bb1

Browse files
committed
Added option argument to listAllSubscribesToCampaign
1 parent 9e25b5f commit 8ea9bb1

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The following methods are currently available on the client instance. You can fi
8787
| Fetch a campaign | `client.fetchCampaign(campaignId, callback)` |
8888
| Activate a campaign | `client.activateCampaign(campaignId, callback)` |
8989
| Pause a campaign | `client.pauseCampaign(campaignId, callback)` |
90-
| List specific campaign's subscribers | `client.listAllSubscribesToCampaign(campaignId, callback)` |
90+
| List specific campaign's subscribers | `client.listAllSubscribesToCampaign(campaignId, options = {}, callback)` |
9191
| Subscribe to a campaign | `client.subscribeToCampaign(campaignId, payload, callback)` |
9292

9393
### Campaign subscriptions

lib/campaigns.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ module.exports = {
4444
* List all subscribers subscribed to a campaign
4545
*
4646
* @param {object} campaignId - Required. The campaign id
47+
* @param {object} options - An object with status and sort details
4748
* @param {callback} callback - An optional callback
4849
* @returns {promise}
4950
*/
50-
listAllSubscribesToCampaign(campaignId, callback) {
51-
return this.get(`v2/${this.accountId}/campaigns/${campaignId}/subscribers`, {}, callback);
51+
listAllSubscribesToCampaign(campaignId, options = {}, callback) {
52+
return this.get(`v2/${this.accountId}/campaigns/${campaignId}/subscribers`, { qs: options }, callback);
5253
},
5354
/**
5455
* Subscribe someone to a campaign

spec/lib/campaigns_spec.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@ describe('Campaigns with callback', () => {
5656
it('should list all subscribers to a campaign and call request with get', (done) => {
5757
expect(typeof client.listAllSubscribesToCampaign).toEqual('function');
5858

59-
client.listAllSubscribesToCampaign(campaignId, (error, response) => {
59+
client.listAllSubscribesToCampaign(campaignId, {}, (error, response) => {
60+
expect(response.statusCode).toBe(200);
61+
expect(client.request.callCount).toBe(1);
62+
});
63+
done();
64+
});
65+
66+
it('should list all active subscribers to a campaign and call request with get', (done) => {
67+
expect(typeof client.listAllSubscribesToCampaign).toEqual('function');
68+
69+
client.listAllSubscribesToCampaign(campaignId, { status: 'active' }, (error, response) => {
6070
expect(response.statusCode).toBe(200);
6171
expect(client.request.callCount).toBe(1);
6272
});
@@ -155,15 +165,29 @@ describe('Campaigns with Promise', () => {
155165
it('should list all subscribers to a campaign', (done) => {
156166
expect(typeof client.listAllSubscribesToCampaign).toEqual('function');
157167

158-
client.listAllSubscribesToCampaign(campaignId)
168+
client.listAllSubscribesToCampaign(campaignId, {})
169+
.then((response) => {
170+
expect(response.statusCode).toBe(200);
171+
expect(client.request.callCount).toBe(1);
172+
})
173+
.catch(failTest);
174+
done();
175+
176+
expect(client.get).toHaveBeenCalledWith('v2/9999999/campaigns/4444444/subscribers', { qs: {} }, undefined);
177+
});
178+
179+
it('should list all active subscribers to a campaign', (done) => {
180+
expect(typeof client.listAllSubscribesToCampaign).toEqual('function');
181+
182+
client.listAllSubscribesToCampaign(campaignId, { status: 'active' })
159183
.then((response) => {
160184
expect(response.statusCode).toBe(200);
161185
expect(client.request.callCount).toBe(1);
162186
})
163187
.catch(failTest);
164188
done();
165189

166-
expect(client.get).toHaveBeenCalledWith('v2/9999999/campaigns/4444444/subscribers', {}, undefined);
190+
expect(client.get).toHaveBeenCalledWith('v2/9999999/campaigns/4444444/subscribers', { qs: { status: 'active' } }, undefined);
167191
});
168192

169193
it('should list all subscribers to a campaign', (done) => {

0 commit comments

Comments
 (0)