Skip to content

Commit

Permalink
Merge pull request #43 from aydrian/ISSUE-42
Browse files Browse the repository at this point in the history
ISSUE-42: Modified sendingDomains.vefify and updated the unit tests and examples.
  • Loading branch information
aydrian committed May 7, 2015
2 parents 70eab70 + c3543a7 commit bc93efb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 53 deletions.
7 changes: 5 additions & 2 deletions examples/sendingDomains/verify_sendingDomain_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);
, client = new SparkPost(key)
, options = {
domainName: 'example1.com'
};

client.sendingDomains.verify('example1.com', function(err, res) {
client.sendingDomains.verify(options, function(err, res) {
if (err) {
console.log(err);
} else {
Expand Down
12 changes: 6 additions & 6 deletions examples/sendingDomains/verify_sendingDomain_dkim_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);
, client = new SparkPost(key)
, options = {
domainName: 'example1.com'
, verifySPF: false
};

var options = {
verifySPF: false
};

client.sendingDomains.verify('example1.com', options, function(err, res) {
client.sendingDomains.verify(options, function(err, res) {
if (err) {
console.log(err);
} else {
Expand Down
12 changes: 6 additions & 6 deletions examples/sendingDomains/verify_sendingDomain_spf_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);
, client = new SparkPost(key)
, options = {
domainName: 'example1.com'
, verifyDKIM: false
};

var options = {
verifyDKIM: false
};

client.sendingDomains.verify('example1.com', options, function(err, res) {
client.sendingDomains.verify(options, function(err, res) {
if (err) {
console.log(err);
} else {
Expand Down
37 changes: 10 additions & 27 deletions lib/sendingDomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,40 +105,23 @@ module.exports = function (client) {
};
client.put(options, callback);
},
verify: function (domainName, options, callback) {
var cb = callback;
var payload = {
dkim_verify: true,
spf_verify: true
};
verify: function (options, callback) {
options = options || {};

if(typeof domainName === 'object') {
cb = options;
options = domainName;
domainName = null;
} else if(typeof domainName === 'function') {
cb = domainName;
options = null;
domainName = null;
}
if(!domainName) {
cb(new Error('domainName is required'));
if(!options.domainName) {
callback(new Error('domainName is required'));
return;
}

if(options && typeof options !== 'function') {
payload.dkim_verify = options.verifyDKIM !== false;
payload.spf_verify = options.verifySPF !== false;
} else {
cb = options;
}

var reqOpts = {
uri: api + '/' + domainName + '/verify',
json: payload
uri: api + '/' + options.domainName + '/verify',
json: {
dkim_verify: options.verifyDKIM !== false,
spf_verify: options.verifySPF !== false
}
};

client.post(reqOpts, cb);
client.post(reqOpts, callback);
}
};
};
25 changes: 13 additions & 12 deletions test/spec/sendingDomains.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,30 @@ describe('Sending Domains Library', function() {

describe('verify Method', function() {
it('should call client post method with the appropriate uri', function(done) {
sendingDomains.verify('test', function() {
expect(client.post.firstCall.args[0].uri).to.equal('sending-domains/test/verify');
done();
});
});
var options = {
domainName: 'test'
};

it('should throw an error if domainName is null', function(done) {
sendingDomains.verify(null, function(err) {
expect(err.message).to.equal('domainName is required');
expect(client.post).not.to.have.been.called;
sendingDomains.verify(options, function() {
expect(client.post.firstCall.args[0].uri).to.equal('sending-domains/test/verify');
done();
});
});

it('should throw an error if domainName is missing', function(done) {
sendingDomains.verify(function(err) {
sendingDomains.verify(null, function(err) {
expect(err.message).to.equal('domainName is required');
expect(client.post).not.to.have.been.called;
done();
});
});

it('should default verifyDKIM and verifySPF to be true', function(done) {
sendingDomains.verify('test', {}, function() {
var options = {
domainName: 'test'
};

sendingDomains.verify(options, function() {
expect(client.post.firstCall.args[0].json.dkim_verify).to.be.true;
expect(client.post.firstCall.args[0].json.spf_verify).to.be.true;
done();
Expand All @@ -160,11 +160,12 @@ describe('Sending Domains Library', function() {

it('should allow a user to set verifyDKIM and verifySPF', function(done){
var options = {
domainName: 'test',
verifyDKIM: false,
verifySPF: false
};

sendingDomains.verify('test', options, function() {
sendingDomains.verify(options, function() {
expect(client.post.firstCall.args[0].json.dkim_verify).to.be.false;
expect(client.post.firstCall.args[0].json.spf_verify).to.be.false;
done();
Expand Down

0 comments on commit bc93efb

Please sign in to comment.