Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error on nonalphanumeric namespace #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/chatskills.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
},
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
},
Expand Down
23 changes: 23 additions & 0 deletions test/addapp.test.js
Original file line number Diff line number Diff line change
@@ -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();
});