Skip to content
This repository has been archived by the owner on Mar 16, 2020. It is now read-only.

Commit

Permalink
test that dependencies actually exist (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jseppi committed Dec 29, 2016
1 parent 3f2d198 commit 6c9ee2d
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions spec/backend/checklistSpec.js
Expand Up @@ -4,21 +4,54 @@ var path = require('path');

var checklistsDir = path.join('checklists');

describe('checklists are valid', function () {
it('all have a "dayZero" item', function (done) {
fs.readdir(checklistsDir, function (err, files) {
files.forEach(function (file) {
var chklist = JSON.parse(
fs.readFileSync(path.join(checklistsDir, file), 'utf8')
);
expect(chklist.checklistName).toBeDefined();
expect(chklist.checklistDescription).toBeDefined();
expect(chklist.items).toBeDefined();
expect(chklist.items instanceof Object).toBeTruthy();
expect(chklist.items.dayZero).toBeDefined();
expect(chklist.items.dayZero.daysToComplete).toBe(0);
expect(chklist.items.dayZero.dependsOn instanceof Array).toBeTruthy();
expect(chklist.items.dayZero.dependsOn.length).toBe(0);
function forEachChecklist(fn) {
fs.readdir(checklistsDir, function (err, files) {
files.forEach(function (file) {
var chklist = JSON.parse(
fs.readFileSync(path.join(checklistsDir, file), 'utf8')
);
fn(chklist, file);
});
});
}


forEachChecklist(function (chklist, file) {
describe('Valid ' + file, function () {
it('has a "dayZero" item', function (done) {
expect(chklist.checklistName).toBeDefined();
expect(chklist.checklistDescription).toBeDefined();
expect(chklist.items).toBeDefined();
expect(chklist.items instanceof Object).toBeTruthy();
expect(chklist.items.dayZero).toBeDefined();
expect(chklist.items.dayZero.daysToComplete).toBe(0);
expect(chklist.items.dayZero.dependsOn instanceof Array).toBeTruthy();
expect(chklist.items.dayZero.dependsOn.length).toBe(0);
done();
});

it('has dependencies that exist', function (done) {
var itemNames = Object.keys(chklist.items);
itemNames.forEach(function (name) {
var item = chklist.items[name];
if (item.prompt) {
item.possibleResponses.forEach(function (response) {
var responseItemNames = Object.keys(response.items);
responseItemNames.forEach(function (responseItemName) {
var responseItem = response.items[responseItemName];
responseItem.dependsOn.forEach(function (dependency) {
expect([].concat(itemNames).concat(responseItemNames))
.toContain(dependency);
});
});
});
}
if (item.dependsOn) {
expect(item.dependsOn instanceof Array).toBeTruthy();
item.dependsOn.forEach(function (dependency) {
expect(itemNames).toContain(dependency);
});
}
});
done();
});
Expand Down

0 comments on commit 6c9ee2d

Please sign in to comment.