Skip to content

Commit

Permalink
MA-945 #time 40m added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 committed Sep 17, 2014
1 parent edb6976 commit 72f12dd
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
xunit.xml
test/reports/*
20 changes: 19 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ module.exports = function(grunt) {
// Pretty timing on grunt commands
gruntTimer(grunt);

var config = {
binPath: './node_modules/.bin'
}
// Configure existing grunt tasks and create custom ones
grunt.initConfig({
config: config,

jshint: {
files: [
'index.js',
Expand All @@ -20,14 +25,27 @@ module.exports = function(grunt) {
reporter: require('jshint-stylish'),
jshintrc: './.jshintrc'
}
},

shell: {
test: {
command : '<%= config.binPath %>/istanbul cover --report lcov --dir test/reports/ <%= config.binPath %>/_mocha test/spec -- --reporter xunit-file',
options : {
stdout : true,
failOnError : true
}
}
}
});

// grunt lint - leverages grunt-contrib-jshint command, lints our code
grunt.registerTask('lint', [ 'jshint' ]);

// grunt test - runs linting and then our unit tests
grunt.registerTask('test', [ 'lint' ])
grunt.registerTask('test', [
'lint',
'shell:test'
]);

// register default grunt command as grunt test
grunt.registerTask('default', [ 'test' ]);
Expand Down
3 changes: 2 additions & 1 deletion lib/transmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var request = require('request');

var Transmission = function(options) {
options = options || {};
this.baseUrl = '/api/v1/Transmissions';
this.openTracking = true;
this.clickTracking = true;
Expand Down Expand Up @@ -243,7 +244,7 @@ Transmission.prototype.setHTMLContent = function(html) {
* @param plaintext string Plain Text Content to be used when the Transmission is sent
*/
Transmission.prototype.setTextContent = function(plaintext) {
this.model.text = plaintext;
this.model.content.text = plaintext;
return this;
};

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"matchdep": "0.3.0",
"xunit-file": "0.0.5",
"mocha": "^1.21.4",
"istanbul": "^0.3.2"
"istanbul": "^0.3.2",
"grunt-shell": "^1.1.1",
"chai": "^1.9.1"
},
"dependencies": {
"request": "2.42.0"
Expand Down
100 changes: 100 additions & 0 deletions test/spec/transmissions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
var chai = require('chai')
, expect = chai.expect;

describe('This is a test', function() {
var transmission = require('../../lib/transmission');


it('should allow for setting values on construction', function() {
var sdk = new transmission({ campaign: 'camp'});
expect(sdk.model.campaign_id).to.equal('camp');
});

it('should instantiate model props to undef', function() {
var sdk = new transmission();
expect(sdk.model.campaign_id).to.be.undefined;
expect(sdk.model.metadata).to.be.undefined;
expect(sdk.model.substitution_data).to.be.undefined;
expect(sdk.model.description).to.be.undefined;
expect(sdk.model.return_path).to.be.undefined;
expect(sdk.model.content.reply_to).to.be.undefined;
expect(sdk.model.content.subject).to.be.undefined;
expect(sdk.model.content.from).to.be.undefined;
expect(sdk.model.content.html).to.be.undefined;
expect(sdk.model.content.text).to.be.undefined;
expect(sdk.model.content.email_rfc822).to.be.undefined;
expect(sdk.model.content.headers).to.be.undefined;
expect(sdk.model.recipients).to.be.undefined;
expect(sdk.model.list_name).to.be.undefined;
expect(sdk.model.content.template_id).to.be.undefined;
});

it('should allow to set campaign by convenience method', function() {
var sdk = new transmission();
sdk.setCampaign('camp');
expect(sdk.model.campaign_id).to.equal('camp');
});

it('should allow to set metadata by convenience method', function() {
var sdk = new transmission();
sdk.setMetadata('meta');
expect(sdk.model.metadata).to.equal('meta');
});

it('should allow to set substitution data by convenience method', function() {
var sdk = new transmission();
sdk.setSubstitutionData('meta');
expect(sdk.model.substitution_data).to.equal('meta');
});

it('should allow to set description by convenience method', function() {
var sdk = new transmission();
sdk.setDescription('desc');
expect(sdk.model.description).to.equal('desc');
});

it('should allow to set return path by convenience method', function() {
var sdk = new transmission();
sdk.setReturnPath('return_path');
expect(sdk.model.return_path).to.equal('return_path');
});

it('should allow to set reply to by convenience method', function() {
var sdk = new transmission();
sdk.setReplyTo('reply_to');
expect(sdk.model.content.reply_to).to.equal('reply_to');
});

it('should allow to set subject by convenience method', function() {
var sdk = new transmission();
sdk.setSubject('subj');
expect(sdk.model.content.subject).to.equal('subj');
});

it('should allow to set from by convenience method', function() {
var sdk = new transmission();
sdk.setFrom('from');
expect(sdk.model.content.from).to.equal('from');
});

it('should allow to set html part by convenience method', function() {
var sdk = new transmission();
sdk.setHTMLContent('<p>html</p>');
expect(sdk.model.content.html).to.equal('<p>html</p>');
});

it('should allow to set text part by convenience method', function() {
var sdk = new transmission();
sdk.setTextContent('text part');
expect(sdk.model.content.text).to.equal('text part');
});

it('should allow for chaining of convenience methods', function() {
var sdk = new transmission();
sdk.setCampaign('camp').setContentHeaders('foo').setRfc822Content('bar');
expect(sdk.model.campaign_id).to.equal('camp');
expect(sdk.model.content.email_rfc822).to.equal('bar');
expect(sdk.model.content.headers).to.equal('foo');
});

});

0 comments on commit 72f12dd

Please sign in to comment.