Skip to content

Commit

Permalink
✅ Test question tree structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardstanislas committed Apr 13, 2021
1 parent efff203 commit aed2925
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["node_modules", "dist"],
};
32 changes: 32 additions & 0 deletions src/infrastructure/config/question-tree.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Question } from "../../domain/support/question-tree";
import { questionTree } from ".";

const checkType = (questionTree: any): questionTree is Question => {
if (!questionTree.title) {
return false;
}
if (!questionTree.choices) {
return false;
}
if (!(questionTree.choices instanceof Array)) {
return false;
}
return questionTree.choices.reduce((acc: boolean, choice: any) => {
if (!choice.id) {
return false;
}
if (!choice.label) {
return false;
}
if (!choice.link) {
return false;
}
return acc && (choice.link.content || checkType(choice.link));
}, true);
};

describe("The question tree", () => {
it("must be valid", () => {
expect(checkType(questionTree)).toBeTruthy();
});
});

0 comments on commit aed2925

Please sign in to comment.