-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from nick13jaremek/feature/mailgun-and-helper-…
…unit-tests Added unit tests for mailgun transport and helper functions.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require('./../global_conf'); | ||
|
||
var expect = require('chai').expect; | ||
var sinon = require('sinon'); | ||
var proxyquire = require('proxyquire'); | ||
var loadFixtures = require('./../../scripts/load_fixtures'); | ||
var mailgunTransport; | ||
var requestMock = {}; | ||
|
||
var logSpy = { | ||
info: '', | ||
error: '' | ||
}; | ||
|
||
describe('Mailgun Transport: ', function() { | ||
|
||
before(function(done) { | ||
|
||
requestMock = function(options, callback) { | ||
return callback(null, 'done'); | ||
}; | ||
|
||
mailgunTransport = proxyquire('./../../lib/transport/mailgun', { | ||
'request': requestMock, | ||
'../util/logger': logSpy | ||
}); | ||
return done(); | ||
}); | ||
|
||
beforeEach(function(done) { | ||
logSpy.info = sinon.spy(); | ||
logSpy.error = sinon.spy(); | ||
loadFixtures(done); | ||
}); | ||
|
||
afterEach(function(done) { | ||
logSpy.info.reset(); | ||
logSpy.error.reset(); | ||
return done(); | ||
}); | ||
|
||
it('sends emails via Mailgun', function(done) { | ||
|
||
var emails = ['first@target.com', 'second@target.com', 'third@target.com']; | ||
var emailBody = { | ||
from: 'origin@target.com', | ||
subject: 'Test subject', | ||
message: 'This is a sample text to act as a message for this email test.' | ||
}; | ||
|
||
mailgunTransport.send(emails, emailBody, function(error, result) { | ||
expect(error).to.equal(null); | ||
expect(result).to.equal('done'); | ||
return done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var helper = require('./../../lib/util/helper'); | ||
var expect = require('chai').expect; | ||
|
||
var VALID_EMAIL = 'mac@into.sh'; | ||
var INVALID_EMAIL = 'bla@bla@bla.com'; | ||
var VALID_PHONE_NUMNER = '12345678912345'; | ||
var INVALID_PHONE_NUMBER = '001122334455667788'; | ||
|
||
describe('Helper: ', function() { | ||
|
||
it('verifies a VALID email', function(done) { | ||
var check = helper.isEmail(VALID_EMAIL); | ||
expect(check).to.equal(true); | ||
return done(); | ||
}); | ||
|
||
it('verifies an INVALID email', function(done) { | ||
var check = helper.isEmail(INVALID_EMAIL); | ||
expect(check).to.equal(false); | ||
return done(); | ||
}); | ||
|
||
it('verifies a VALID phone number', function(done) { | ||
|
||
var check = helper.isPhoneNumber(VALID_PHONE_NUMNER); | ||
expect(check).to.equal(true); | ||
return done(); | ||
}); | ||
|
||
it('verifies an INVALID phone number', function(done) { | ||
var check = helper.isPhoneNumber(INVALID_PHONE_NUMBER); | ||
expect(check).to.equal(false); | ||
return done(); | ||
}); | ||
}); |