diff --git a/lib/chatskills.js b/lib/chatskills.js index cfa7ede..f8a78a1 100644 --- a/lib/chatskills.js +++ b/lib/chatskills.js @@ -104,6 +104,9 @@ var ChatSkillsManager = { add: function(namespace) { // Add a new skill (app namespace). + if (/[^A-Z0-9a-z]/.test(namespace)) { + throw new Error('a skill name may only contain alphanumeric characters'); + } this.apps[namespace] = new alexa.app(namespace); return this.apps[namespace]; }, diff --git a/package.json b/package.json index dd78b0c..bb8d4d7 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,16 @@ "url": "git://github.com/primaryobjects/chatskills.git" }, "main": "./lib", + "scripts": { + "test": "node test/*.test.js" + }, "dependencies": { "readline-sync": "*", "alexa-app": "*" }, + "devDependencies": { + "tape": "^4.6.3" + }, "engines": { "node": "*" }, diff --git a/test/addapp.test.js b/test/addapp.test.js new file mode 100644 index 0000000..bd15da6 --- /dev/null +++ b/test/addapp.test.js @@ -0,0 +1,23 @@ +var test = require('tape'); +var chatskills = require('../lib/chatskills'); + +test("app/skill creation with `app` succeeds", function(t) { + t.doesNotThrow(function() { chatskills.app('hello') }, Error); + t.end(); +}); + +test("app/skill creation with `app` returns a value", function(t) { + var hello = chatskills.app('hello'); + t.ok(hello); + t.end(); +}); + +test("app/skill creation with `app` fails with error when namespace is non-alphanumeric", function(t) { + t.throws(function() { chatskills.app('hel lo') }, Error); + t.throws(function() { chatskills.app('hel lo') }, /skill.*characters/); + t.throws(function() { chatskills.app('hel_lo') }, Error); + t.throws(function() { chatskills.app('hel_lo') }, /skill.*characters/); + t.throws(function() { chatskills.app('hel-lo') }, Error); + t.throws(function() { chatskills.app('hel-lo') }, /skill.*characters/); + t.end(); +});