Skip to content

Commit

Permalink
merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
avigoldman committed Dec 19, 2016
2 parents a4c141a + 0db0a1a commit 4c82900
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ module.exports = function(client) {
get: function(id, options, callback) {
options = options || {};

if (typeof options === 'function') {
callback = options;
options = {};
}

if (!id) {
return Promise.reject(new Error('template id is required')).asCallback(callback);
}
Expand Down
11 changes: 6 additions & 5 deletions lib/transmissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@ module.exports = function(client) {
* @returns {Promise}
*/
send: function(transmission, options, callback) {
if (!transmission || typeof transmission !== 'object') {
return Promise.reject(new Error('transmission object is required')).asCallback(callback);
}

const modifiedTransmission = _.cloneDeep(transmission);

// Handle optional options argument
if (typeof options === 'function') {
callback = options;
options = {};
}

if (!transmission || typeof transmission !== 'object') {
return Promise.reject(new Error('transmission object is required')).asCallback(callback);
}

const modifiedTransmission = _.cloneDeep(transmission);

// format the payload if we are given an array of recipients
if (_.has(modifiedTransmission, 'recipients') &&
_.isArray(modifiedTransmission.recipients) &&
Expand Down
9 changes: 9 additions & 0 deletions test/spec/templates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ describe('Templates Library', function() {
expect(client.get.firstCall.args[0].qs).to.deep.equal({draft: true});
});
});

it('should work given just an id and callback', function() {
var id = 'test';

return templates.get(id, function() {
expect(client.get.firstCall.args[0].uri).to.contain(id);
expect(client.get.firstCall.args[0].qs).to.deep.equal({});
});
});
});

describe('create Method', function() {
Expand Down

0 comments on commit 4c82900

Please sign in to comment.