Skip to content

Commit 0db0a1a

Browse files
avigoldmanaydrian
authored andcommitted
Option fix (#195)
* made options optional in template get * moved optional option check before the transmission check * added test around templates
1 parent 00b0e35 commit 0db0a1a

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lib/templates.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ module.exports = function(client) {
2929
get: function(id, options, callback) {
3030
options = options || {};
3131

32+
if (typeof options === 'function') {
33+
callback = options;
34+
options = {};
35+
}
36+
3237
if (!id) {
3338
return Promise.reject(new Error('template id is required')).asCallback(callback);
3439
}

lib/transmissions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ module.exports = function(client) {
5959
* @returns {Promise}
6060
*/
6161
send: function(transmission, options, callback) {
62-
if (!transmission || typeof transmission !== 'object') {
63-
return Promise.reject(new Error('transmission object is required')).asCallback(callback);
64-
}
6562

6663
// Handle optional options argument
6764
if (typeof options === 'function') {
6865
callback = options;
6966
options = {};
7067
}
7168

69+
if (!transmission || typeof transmission !== 'object') {
70+
return Promise.reject(new Error('transmission object is required')).asCallback(callback);
71+
}
72+
7273
const reqOpts = {
7374
uri: api,
7475
json: transmission,

test/spec/templates.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ describe('Templates Library', function() {
5858
expect(client.get.firstCall.args[0].qs).to.deep.equal({draft: true});
5959
});
6060
});
61+
62+
it('should work given just an id and callback', function() {
63+
var id = 'test';
64+
65+
return templates.get(id, function() {
66+
expect(client.get.firstCall.args[0].uri).to.contain(id);
67+
expect(client.get.firstCall.args[0].qs).to.deep.equal({});
68+
});
69+
});
6170
});
6271

6372
describe('create Method', function() {

0 commit comments

Comments
 (0)