Skip to content

Commit

Permalink
Merge d86573e into 359a479
Browse files Browse the repository at this point in the history
  • Loading branch information
ewandennis committed Feb 15, 2016
2 parents 359a479 + d86573e commit e5a88a7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/messageEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var api = 'message-events';

/*
* "Class" declaration, Message Events API exposes one function:
* - search: retrieves list of message events according to given params
*/
module.exports = function (client) {
return {
search: function(parameters, callback) {
var options = {
uri: api
, qs: parameters
};
client.get(options, callback);
}
};
};
1 change: 1 addition & 0 deletions lib/sparkpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var SparkPost = function(apiKey, options) {
this.templates = require('./templates')(this);
this.transmissions = require('./transmissions')(this);
this.webhooks = require('./webhooks')(this);
this.messageEvents = require('./messageEvents')(this);
};

SparkPost.prototype.request = function( options, callback ) {
Expand Down
45 changes: 45 additions & 0 deletions test/spec/messageEvents.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var chai = require('chai')
, expect = chai.expect
, sinon = require('sinon')
, sinonChai = require('sinon-chai');

chai.use(sinonChai);

describe('Message Events Library', function() {
var client, templates;

beforeEach(function() {
client = {
get: sinon.stub().yields()
};

messageEvents = require('../../lib/messageEvents')(client);
});

describe('search Method', function() {
it('should call client get method with the appropriate parameters', function(done) {
var options = {
bounce_classes: [10, 50],
campaign_ids: 'test_campaign',
events: ['bounce'],
friendly_froms: ['bob@example.com'],
from: '2015-11-14T16:15',
message_ids: ['0e0d94b7-9085-4e3c-ab30-e3f2cd9c273e'],
page: 1,
per_page: 5,
reason: '%5.2.0%',
recipients: ['jim@example.com'],
template_ids: ['newsletter_template'],
timezone: 'America/New_York',
to: '2016-11-14T16:15',
transmission_ids: ['65832150921904138']
};
messageEvents.search(options, function(err, data) {
Object.keys(options).forEach(function(key) {
expect(client.get.firstCall.args[0].qs).to.have.property(key).and.equal(options[key]);
});
done();
});
});
});
});

0 comments on commit e5a88a7

Please sign in to comment.