Permalink
Browse files

test: mock based testing

  • Loading branch information...
1 parent 74ec34c commit 34eea44dac9ae62fbe51d9456a09d21bea63ec36 @rauchg rauchg committed Feb 12, 2013
Showing with 36 additions and 9 deletions.
  1. +36 −9 test/index.js
View
@@ -3,18 +3,48 @@
* Module dependencies
*/
-var mandrill = require('../')
- , config = require('./config')
- , expect = require('expect.js');
+var mandrill = require('../');
+var expect = require('expect.js');
/**
* Create Mandill-send instance
*/
-var email = mandrill(config.key);
+var email = mandrill('some random key');
-describe('send a simple email', function(){
- it('expect `null` error response', function(done){
+describe('mandrill-send', function(){
+ it('should work', function(done){
+ // mock
+ var req = {};
+ req.post = function(_url){
+ req.url = _url;
+ return req;
+ };
+ req.send = function(data){
+ req.data = data;
+ return req;
+ };
+ req.end = function(fn){
+ expect(req.url).to.be('https://mandrillapp.com/api/1.0/messages/send.json');
+ expect(req.data).to.eql({
+ key: 'some random key',
+ message: {
+ from_name: 'From',
+ from_email: 'from@email.com',
+ to: [
+ { email: 'to@email.com' },
+ { name: 'The other guy', email: 'the.other.guy@email.net' }
+ ],
+ subject: 'Testing signup',
+ tags: ['signup', 'welcome']
+ }
+ });
+ done();
+ };
+
+ // set mock
+ mandrill.request = req;
+ // send email
email({
from: 'From <from@email.com>',
to: [
@@ -23,9 +53,6 @@ describe('send a simple email', function(){
],
subject: 'Testing signup',
tags: ['signup', 'welcome']
- }, function(err){
- expect(err).to.equal(null);
- done();
});
});
});

0 comments on commit 34eea44

Please sign in to comment.