Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option argument to listAllSubscribesToCampaign #24

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The following methods are currently available on the client instance. You can fi
| Fetch a campaign | `client.fetchCampaign(campaignId, callback)` |
| Activate a campaign | `client.activateCampaign(campaignId, callback)` |
| Pause a campaign | `client.pauseCampaign(campaignId, callback)` |
| List specific campaign's subscribers | `client.listAllSubscribesToCampaign(campaignId, callback)` |
| List specific campaign's subscribers | `client.listAllSubscribesToCampaign(campaignId, options = {}, callback)` |
| Subscribe to a campaign | `client.subscribeToCampaign(campaignId, payload, callback)` |

### Campaign subscriptions
Expand Down
5 changes: 3 additions & 2 deletions lib/campaigns.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ module.exports = {
* List all subscribers subscribed to a campaign
*
* @param {object} campaignId - Required. The campaign id
* @param {object} options - An object with status and sort details
* @param {callback} callback - An optional callback
* @returns {promise}
*/
listAllSubscribesToCampaign(campaignId, callback) {
return this.get(`v2/${this.accountId}/campaigns/${campaignId}/subscribers`, {}, callback);
listAllSubscribesToCampaign(campaignId, options = {}, callback) {
return this.get(`v2/${this.accountId}/campaigns/${campaignId}/subscribers`, { qs: options }, callback);
},
/**
* Subscribe someone to a campaign
Expand Down
30 changes: 27 additions & 3 deletions spec/lib/campaigns_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ describe('Campaigns with callback', () => {
it('should list all subscribers to a campaign and call request with get', (done) => {
expect(typeof client.listAllSubscribesToCampaign).toEqual('function');

client.listAllSubscribesToCampaign(campaignId, (error, response) => {
client.listAllSubscribesToCampaign(campaignId, {}, (error, response) => {
expect(response.statusCode).toBe(200);
expect(client.request.callCount).toBe(1);
});
done();
});

it('should list all active subscribers to a campaign and call request with get', (done) => {
expect(typeof client.listAllSubscribesToCampaign).toEqual('function');

client.listAllSubscribesToCampaign(campaignId, { status: 'active' }, (error, response) => {
expect(response.statusCode).toBe(200);
expect(client.request.callCount).toBe(1);
});
Expand Down Expand Up @@ -155,15 +165,29 @@ describe('Campaigns with Promise', () => {
it('should list all subscribers to a campaign', (done) => {
expect(typeof client.listAllSubscribesToCampaign).toEqual('function');

client.listAllSubscribesToCampaign(campaignId)
client.listAllSubscribesToCampaign(campaignId, {})
.then((response) => {
expect(response.statusCode).toBe(200);
expect(client.request.callCount).toBe(1);
})
.catch(failTest);
done();

expect(client.get).toHaveBeenCalledWith('v2/9999999/campaigns/4444444/subscribers', { qs: {} }, undefined);
});

it('should list all active subscribers to a campaign', (done) => {
expect(typeof client.listAllSubscribesToCampaign).toEqual('function');

client.listAllSubscribesToCampaign(campaignId, { status: 'active' })
.then((response) => {
expect(response.statusCode).toBe(200);
expect(client.request.callCount).toBe(1);
})
.catch(failTest);
done();

expect(client.get).toHaveBeenCalledWith('v2/9999999/campaigns/4444444/subscribers', {}, undefined);
expect(client.get).toHaveBeenCalledWith('v2/9999999/campaigns/4444444/subscribers', { qs: { status: 'active' } }, undefined);
});

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