Permalink
Browse files

Merge pull request #1 from LearnBoost/add/tests

Add/tests
  • Loading branch information...
rauchg committed Feb 12, 2013
2 parents bc2e8f8 + b985729 commit 3f383bcc72ce37a0d12965be621c9c11bcf1a41f
Showing with 98 additions and 17 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 .travis.yml
  3. +10 −0 Makefile
  4. +2 −0 Readme.md
  5. +18 −17 index.js
  6. +5 −0 package.json
  7. +58 −0 test/index.js
View
@@ -1 +1,3 @@
node_modules
+test/config.js
+npm-debug.log
View
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - 0.8
View
@@ -0,0 +1,10 @@
+
+test:
+ @./node_modules/.bin/mocha \
+ --require should \
+ --timeout 10s \
+ --slow 3s \
+ --bail \
+ --reporter spec
+
+.PHONY: test
View
@@ -1,6 +1,8 @@
# mandrill
+[![Build Status](https://secure.travis-ci.org/LearnBoost/mandrill-send.png)](http://travis-ci.org/LearnBoost/mandrill-send)
+
Dead-simple mandrill API implementation. Only sends emails.
## How to use
View
@@ -62,10 +62,10 @@ function create(key){
}
send(key, opts, fn);
- };
+ }
return email;
-};
+}
/**
* Sends a message through the mandrill API.
@@ -77,20 +77,21 @@ function create(key){
function send(key, message, fn){
debug('sending message %j with api key "%s"', message, key);
+ var url = 'https://mandrillapp.com/api/1.0/messages/send.json';
exports.request
- .post('https://mandrillapp.com/api/1.0/messages/send.json')
- .send({ key: key, message: message })
- .end(function(err, res){
- if (err) return fn(err);
- if (res.ok) {
- fn(null, res.body.return);
- } else {
- var err = new Error('Mandrill response status ' + res.status);
- err.data = res.body;
- fn(err);
- }
- });
-};
+ .post(url)
+ .send({ key: key, message: message })
+ .end(function(err, res){
+ if (err) return fn(err);
+ if (res.ok) {
+ fn(null, res.body.return);
+ } else {
+ var err = new Error('Mandrill response status ' + res.status);
+ err.data = res.body;
+ fn(err);
+ }
+ });
+}
/**
* Parses "A B <c@d.com>" into mandrill {email,name} format.
@@ -107,7 +108,7 @@ function parse(email){
} else {
return { email: email };
}
-};
+}
/**
* Placeholder callback.
@@ -118,4 +119,4 @@ function parse(email){
function empty (err) {
if (err) return console.error(err.stack || err);
-};
+}
View
@@ -5,5 +5,10 @@
"dependencies": {
"superagent": "0.12.4",
"debug": "*"
+ },
+ "devDependencies": {
+ "mocha": "*",
+ "should": "*",
+ "expect.js": "*"
}
}
View
@@ -0,0 +1,58 @@
+
+/**
+ * Module dependencies
+ */
+
+var mandrill = require('../');
+var expect = require('expect.js');
+
+/**
+ * Create Mandill-send instance
+ */
+var email = mandrill('some random key');
+
+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: [
+ 'to@email.com',
+ { name: 'The other guy', email: 'the.other.guy@email.net' }
+ ],
+ subject: 'Testing signup',
+ tags: ['signup', 'welcome']
+ });
+ });
+});

0 comments on commit 3f383bc

Please sign in to comment.