forked from alexa-js/alexa-app-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-utils.js
83 lines (71 loc) · 2.7 KB
/
test-utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*jshint expr: true*/
"use strict";
var chai = require("chai");
var expect = chai.expect;
chai.config.includeStack = true;
var utils = require("../utils");
describe("Utils", function() {
describe("#isValidFile", function() {
it("verifies that 'README.md' does exists and is a file", function() {
expect(utils.isValidFile('README.md')).to.be.true;
});
it("verifies that 'RANDOM.md' does not exists", function() {
expect(utils.isValidFile('RANDOM.md')).to.be.false;
});
it("verifies that 'examples' is not a file", function() {
expect(utils.isValidFile('examples')).to.be.false;
});
});
describe("#isValidDirectory", function() {
it("verifies that 'examples' does exists and is a directory", function() {
expect(utils.isValidDirectory('examples')).to.be.true;
});
it("verifies that 'random' does not exists", function() {
expect(utils.isValidDirectory('random')).to.be.false;
});
it("verifies that 'README.md' is not a directory", function() {
expect(utils.isValidDirectory('README.md')).to.be.false;
});
});
describe("#readFile", function() {
it("successfully reads 'example.txt'", function() {
expect(utils.readFile('test/example.txt')).to.equal("The quick brown fox jumps over the lazy dog");
});
it("throws an error when trying to read 'example.text'", function() {
expect(function() {
utils.readFile('test/example.text');
}).to.throw(Error);
});
});
describe("#readJsonFile", function() {
it("successfully reads 'example.json'", function() {
expect(utils.readJsonFile('test/example.json')).to.deep.equal({
"pangram": "The quick brown fox jumps over the lazy dog"
});
});
it("throws an error when trying to read 'example.jason'", function() {
expect(function() {
utils.readJsonFile('test/example.jason');
}).to.throw(Error);
});
});
describe("#normalizeApiPath", function() {
var tests = [
{ original: "alexa", final: "/alexa" },
{ original: "/alexa", final: "/alexa" },
{ original: "//alexa", final: "/alexa" },
{ original: "///alexa", final: "/alexa" },
{ original: "alexa/", final: "/alexa/" },
{ original: "alexa//", final: "/alexa/" },
{ original: "alexa///", final: "/alexa/" },
{ original: "/alexa/", final: "/alexa/" },
{ original: "//alexa//", final: "/alexa/" },
{ original: "///alexa///", final: "/alexa/" },
];
tests.forEach(function(test) {
it('correctly normalizes ' + test.original + ' into ' + test.final, function() {
expect(utils.normalizeApiPath(test.original)).to.equal(test.final);
});
});
});
});