Skip to content

Commit

Permalink
refactoring for better test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsonizer committed Nov 1, 2016
1 parent 4af5348 commit c1aa510
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 83 deletions.
29 changes: 15 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

var shell = require('gulp-shell');
var mocha = require('gulp-mocha');
var watch = require('gulp-watch');
Expand All @@ -11,21 +10,23 @@ var cfgRoot = './cfg/';
var tstRoot = './test/';
var buildDir = './build/';

gulp.task('lint', function(){
return gulp.src([
srcRoot + '*.js',
cfgRoot + '*.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
//.pipe(jshint.reporter('fail')); //there is an issue with this reporter: skipping
gulp.task('lint', function() {
return gulp.src([
srcRoot + '*.js',
cfgRoot + '*.js'
])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
//.pipe(jshint.reporter('fail')); //there is an issue with this reporter: skipping
});

gulp.task('build', function(){
return gulp.src([
srcRoot + '*.js',
cfgRoot + '*.js'])

.pipe(gulp.dest(buildDir));
gulp.task('build', function() {
return gulp.src([
srcRoot + '*.js',
cfgRoot + '*.js'
])

.pipe(gulp.dest(buildDir));
});

gulp.task('test', function() {
Expand Down
5 changes: 5 additions & 0 deletions src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ services.fetch = function(url, oauthservice, opts) {
services.parse_xml = function(xml) {
return XmlService.parse(xml);
};

// this block is for when running in node outside of GAS
if (typeof exports !== 'undefined') {
exports.services = services;
}
182 changes: 113 additions & 69 deletions test/backblasts_tests.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,124 @@
var assert = require("chai").assert;
var bb = require("../src/backblasts.js").BackblastChecker;
var sinon = require("sinon");
var bb = require("../src/backblasts.js").backblasts;

// Global Scope = :(
services = require("../src/services.js").services;

describe('Backblasts Additional Data', function() {
describe('getAdditionalData', function() {

function mockDocument() {
return {
getRootElement: function() {
return {
getChild: function() {
return {
getChildren: function() {
return {};
}
};
}
};
}
};
}

describe('Backblasts Data', function() {
var cfg = {};
describe('checkForUpdates', function() {
it('should parse out workout dates', function() {
var content = "<li><strong>When:</strong>01/01/2016</li>";
var result = bb.getAdditionalData(content, []);

assert(result.date === "01/01/2016", "Should parse out date");
});
var fetch = sinon.stub(services, 'fetch');
fetch.returns("<li><strong>When:</strong>01/01/2016</li>");

it('should parse out todays date if workout date not found', function() {
var content = "<li><strong></li>";
var result = bb.getAdditionalData(content, []);
var date = new Date(result.date);
var today = new Date();
var parse_xml = sinon.stub(services, 'parse_xml');
var doc = {
getRootElement: function() {
return {
getChild: function() {
console.log("called getChild");
return {
getChildren: sinon.stub()
};
}
};
}
};
doc.getRootElement().getChild().getChildren.returns([{}]);
parse_xml.returns(doc);

assert(date.toLocaleDateString() == today.toLocaleDateString(), "Should be equal to today");
});
it('should parse out pax count and list', function() {
var content = "<li><strong>The PAX:</strong>Wingman</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 1, "Should parse out pax list");
assert(result.paxList.indexOf("wingman") != -1, "Should parse out pax list");
var result = bb.checkForUpdates(
cfg,
function() {
return new Date().toString();
},
function(newDate) {
// check date here
},
function(rowValues) {
// check Row Values here
});
assert(result.date === "01/01/2016", "Should parse out date");
});
/*
it('should parse out todays date if workout date not found', function() {
var content = "<li><strong></li>";
var result = bb.getAdditionalData(content, []);
var date = new Date(result.date);
var today = new Date();
it('should parse out pax count', function() {
var content = "The PAX:</strong> The Once-ler, Waterfoot, Vida, Chin Music, Crayola, Bullwinkle (FNG), Hannibal, Knight Rider, MAD, Pele, Adobe, Smash, Balk, Fireman Ed, Marge, Lambeau, Torpedo, Goonie (QIC) </li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxList.length === 18, "Should find the number of Pax");
});
it('should parse out QIC', function() {
var content = "<li><strong>QIC:</strong>Gears</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 1, "Should parse out pax list");
assert(result.paxList.indexOf("gears") != -1, "Should parse out pax list");
});
it('should handle QIC in pax list and QIC field', function() {
var content = "<li><strong>QIC:</strong>Gears</li>" +
"<li><strong>The PAX:</strong>Wingman, Gears</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 2, "Should parse out pax list");
assert(result.paxList.indexOf("gears") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("wingman") != -1, "Should capture non-QIC as a PAX");
});
it('should handle multiple in QIC field with and', function() {
var content = "<li><strong>QIC:</strong>Gears and Old Bay</li>" +
"<li><strong>The PAX:</strong>Wingman, Gears, Old Bay</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 3, "Should parse out pax list");
assert(result.paxList.indexOf("gears") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("oldbay") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("wingman") != -1, "Should capture non-QIC as a PAX");
});
it('should handle multiple in QIC field with commas', function() {
var content = "<li><strong>QIC:</strong>Zima, Bolt, Bing</li>" +
"<li><strong>The PAX:</strong>Wingman, Gears, Old Bay</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 6, "Should parse out pax list");
assert(result.paxList.indexOf("zima") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("bolt") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("bing") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("wingman") != -1, "Should capture non-QIC as a PAX");
assert(result.paxList.indexOf("gears") != -1, "Should capture non-QIC as a PAX");
assert(result.paxList.indexOf("oldbay") != -1, "Should capture non-QIC as a PAX");
});
it('should handle handle common acronyms', function() {
var content = "<li><strong>QIC:</strong>Gears(YHC)</li>" +
"<li><strong>The PAX:</strong>Wingman (Respect), Bolt(QIC), Sharkbait (2.0)</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 4, "Should parse out pax list");
assert(result.paxList.indexOf("bolt") != -1, "Should contain bolt");
assert(result.paxList.indexOf("wingman") != -1, "Should contain wingman");
assert(result.paxList.indexOf("gears") != -1, "Should contain gears");
assert(result.paxList.indexOf("sharkbait") != -1, "Should contain sharkbait");
});
assert(date.toLocaleDateString() == today.toLocaleDateString(), "Should be equal to today");
}); it('should parse out pax count and list', function() {
var content = "<li><strong>The PAX:</strong>Wingman</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 1, "Should parse out pax list");
assert(result.paxList.indexOf("wingman") != -1, "Should parse out pax list");
});
it('should parse out pax count', function() {
var content = "The PAX:</strong> The Once-ler, Waterfoot, Vida, Chin Music, Crayola, Bullwinkle (FNG), Hannibal, Knight Rider, MAD, Pele, Adobe, Smash, Balk, Fireman Ed, Marge, Lambeau, Torpedo, Goonie (QIC) </li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxList.length === 18, "Should find the number of Pax");
}); it('should parse out QIC', function() {
var content = "<li><strong>QIC:</strong>Gears</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 1, "Should parse out pax list");
assert(result.paxList.indexOf("gears") != -1, "Should parse out pax list");
}); it('should handle QIC in pax list and QIC field', function() {
var content = "<li><strong>QIC:</strong>Gears</li>" +
"<li><strong>The PAX:</strong>Wingman, Gears</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 2, "Should parse out pax list");
assert(result.paxList.indexOf("gears") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("wingman") != -1, "Should capture non-QIC as a PAX");
}); it('should handle multiple in QIC field with and', function() {
var content = "<li><strong>QIC:</strong>Gears and Old Bay</li>" +
"<li><strong>The PAX:</strong>Wingman, Gears, Old Bay</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 3, "Should parse out pax list");
assert(result.paxList.indexOf("gears") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("oldbay") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("wingman") != -1, "Should capture non-QIC as a PAX");
}); it('should handle multiple in QIC field with commas', function() {
var content = "<li><strong>QIC:</strong>Zima, Bolt, Bing</li>" +
"<li><strong>The PAX:</strong>Wingman, Gears, Old Bay</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 6, "Should parse out pax list");
assert(result.paxList.indexOf("zima") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("bolt") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("bing") != -1, "Should capture QIC as a PAX");
assert(result.paxList.indexOf("wingman") != -1, "Should capture non-QIC as a PAX");
assert(result.paxList.indexOf("gears") != -1, "Should capture non-QIC as a PAX");
assert(result.paxList.indexOf("oldbay") != -1, "Should capture non-QIC as a PAX");
}); it('should handle handle common acronyms', function() {
var content = "<li><strong>QIC:</strong>Gears(YHC)</li>" +
"<li><strong>The PAX:</strong>Wingman (Respect), Bolt(QIC), Sharkbait (2.0)</li>";
var result = bb.getAdditionalData(content, []);
assert(result.paxCount == 4, "Should parse out pax list");
assert(result.paxList.indexOf("bolt") != -1, "Should contain bolt");
assert(result.paxList.indexOf("wingman") != -1, "Should contain wingman");
assert(result.paxList.indexOf("gears") != -1, "Should contain gears");
assert(result.paxList.indexOf("sharkbait") != -1, "Should contain sharkbait");
});
*/
});
});

0 comments on commit c1aa510

Please sign in to comment.