Skip to content

Commit

Permalink
Added additional test case for template details fetching.
Browse files Browse the repository at this point in the history
  • Loading branch information
nick13jaremek committed Apr 28, 2016
1 parent 87ba64a commit 61359e1
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions test/platforms/template.js
Expand Up @@ -7,6 +7,7 @@ const templatePlatform = require('./../../lib/platforms/template');
let fsStub = {};

const VALID_MJML = '<mj-body><mj-section><mj-column><mj-text>Hello World</mj-text></mj-column></mj-section></mj-body>';
const VALID_HTML = '<html><body><h1>Hello World</h1></body></html>';
const INVALID_MJML = '<mj-blablabla></mj-blablabla>';
const READ_FILE_LIST = ['template-1.mjml', 'template-2.mjml', 'template-3.mjml'];
const FILE_LIST = [{name: 'template-1', type: 'mjml'}, {name: 'template-2', type: 'mjml'}, {name: 'template-3', type: 'mjml'}];
Expand All @@ -19,7 +20,6 @@ describe('Template email', function() {
fsStub.readdir = sinon.stub(fs, 'readdir');
fsStub.readdir.yields(null, READ_FILE_LIST);
fsStub.readFileSync = sinon.stub(fs, 'readFileSync');
fsStub.readFileSync.returns(VALID_MJML);
return done();
});

Expand Down Expand Up @@ -103,10 +103,13 @@ describe('Template email', function() {
});
});

it('returns the details associated to an HTML template', function(done) {
it('returns the details associated to an MJML template', function(done) {

const templateName = 'template';
const templateType = 'mjml';

fsStub.readFileSync.returns(VALID_MJML);

templatePlatform.getTemplateDetails(templateName, templateType, function(err, details) {
expect(err).to.equal(null);
expect(details).to.have.property('content');
Expand All @@ -117,6 +120,23 @@ describe('Template email', function() {
});
});

it('returns the details associated to an MJML template', function(done) {

const templateName = 'template';
const templateType = 'mjml';

fsStub.readFileSync.returns(VALID_HTML);

templatePlatform.getTemplateDetails(templateName, templateType, function(err, details) {
expect(err).to.equal(null);
expect(details).to.have.property('content');
expect(details.content).to.equal(VALID_HTML);
expect(details).to.have.property('placeholders');
expect(details.placeholders).to.deep.equal([]);
return done();
});
});

it('fails because of not found HTML template', function(done) {
const templateName = 'no-file';
const templateType = 'mjml';
Expand Down

0 comments on commit 61359e1

Please sign in to comment.