Permalink
Please sign in to comment.
Showing
with
199 additions
and 33 deletions.
- +1 −0 CHANGELOG.md
- +5 −4 README.md
- +42 −0 UPGRADING.md
- +0 −1 example/express.js
- +16 −14 index.js
- +1 −1 package.json
- +3 −0 test/example.json
- +1 −0 test/example.txt
- +17 −13 test/test_alexa_integration_express.js
- +83 −0 test/test_utils.js
- +30 −0 utils.js
42
UPGRADING.md
| @@ -0,0 +1,3 @@ | ||
| +{ | ||
| + "pangram": "The quick brown fox jumps over the lazy dog" | ||
| +} |
| @@ -0,0 +1 @@ | ||
| +The quick brown fox jumps over the lazy dog |
| @@ -0,0 +1,83 @@ | ||
| +"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 'example' does exists and is a directory", function() { | ||
| + expect(utils.isValidDirectory('example')).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/" }, | ||
| + { original: "///api///alexa///", final: "/api/alexa/" } | ||
| + ]; | ||
| + | ||
| + tests.forEach(function(test) { | ||
| + it('correctly normalizes ' + test.original + ' into ' + test.final, function() { | ||
| + expect(utils.normalizeApiPath(test.original)).to.equal(test.final); | ||
| + }); | ||
| + }); | ||
| + }); | ||
| +}); |
| @@ -0,0 +1,30 @@ | ||
| +var fs = require('fs'); | ||
| +var path = require('path'); | ||
| + | ||
| +var isValidDirectory = function(dir) { | ||
| + return fs.existsSync(dir) && fs.statSync(dir).isDirectory(); | ||
| +}; | ||
| + | ||
| +var isValidFile = function(file) { | ||
| + return fs.existsSync(file) && fs.statSync(file).isFile(); | ||
| +}; | ||
| + | ||
| +var readFile = function(file) { | ||
| + return fs.readFileSync(file, 'utf8'); | ||
| +}; | ||
| + | ||
| +var readJsonFile = function(file) { | ||
| + return JSON.parse(readFile(file)); | ||
| +}; | ||
| + | ||
| +var normalizeApiPath = function(apiPath) { | ||
| + return path.posix.normalize(path.posix.join('/', apiPath)); | ||
| +}; | ||
| + | ||
| +module.exports = { | ||
| + isValidDirectory : isValidDirectory, | ||
| + isValidFile : isValidFile, | ||
| + readFile : readFile, | ||
| + readJsonFile : readJsonFile, | ||
| + normalizeApiPath : normalizeApiPath | ||
| +}; |
0 comments on commit
b30997f