diff --git a/CHANGELOG.md b/CHANGELOG.md index 1230f8d..4a2e1aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### 2.3.2 (Next) +* [#34](https://github.com/alexa-js/alexa-app-server/pull/34): Added tests for fail cases and schemas/utterances - [@tejashah88](https://github.com/tejashah88). +* [#34](https://github.com/alexa-js/alexa-app-server/pull/34): Fixed bug while trying to retrieve schema/utterances with GET request - [@tejashah88](https://github.com/tejashah88). +* [#34](https://github.com/alexa-js/alexa-app-server/pull/34): Updated messages that display an error to be displayed by `self.error` - [@tejashah88](https://github.com/tejashah88). +* [#34](https://github.com/alexa-js/alexa-app-server/pull/34): Optimized some tests to not always start a new server instance after every test - [@tejashah88](https://github.com/tejashah88). * [#33](https://github.com/alexa-js/alexa-app-server/pull/33): Updated dependencies - [@tejashah88](https://github.com/tejashah88). * [#33](https://github.com/alexa-js/alexa-app-server/pull/33): Fix: expressjs deprecation warning - [@tejashah88](https://github.com/tejashah88). * [#32](https://github.com/alexa-js/alexa-app-server/pull/32): Added tests for request verification, HTTPS support, and POST-based routes - [@tejashah88](https://github.com/tejashah88). diff --git a/index.js b/index.js index 481dda2..1aa5b78 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,9 @@ var appServer = function(config) { console.log(msg); } }; - self.error = function(msg) { console.log(msg); }; + self.error = function(msg) { + console.error(msg); + }; // Configure hotswap to watch for changes and swap out module code var hotswapCallback = function(filename) { @@ -28,7 +30,7 @@ var appServer = function(config) { }; var errorCallback = function(e) { - self.log("-----\nhotswap error: " + e + "\n-----\n"); + self.error("-----\nhotswap error: " + e + "\n-----\n"); }; hotswap.on('swap', hotswapCallback); @@ -44,17 +46,17 @@ var appServer = function(config) { app_directories(app_dir).forEach(function(dir) { var package_json = path.join(app_dir, dir, "/package.json"); if (!fs.existsSync(package_json) || !fs.statSync(package_json).isFile()) { - self.log(" package.json not found in directory " + dir); + self.error(" package.json not found in directory " + dir); return; } var pkg = JSON.parse(fs.readFileSync(package_json, 'utf8')); if (!pkg || !pkg.main || !pkg.name) { - self.log(" Failed to load " + package_json); + self.error(" Failed to load " + package_json); return; } var main = fs.realpathSync(path.join(app_dir, dir, pkg.main)); if (!fs.existsSync(main) || !fs.statSync(main).isFile()) { - self.log(" main file not found for app [" + pkg.name + "]: " + main); + self.error(" main file not found for app [" + pkg.name + "]: " + main); return; } try { @@ -62,7 +64,7 @@ var appServer = function(config) { self.apps[pkg.name] = pkg; self.apps[pkg.name].exports = app; if (typeof app.express != "function") { - self.log(" App [" + pkg.name + "] is not an instance of alexa-app"); + self.error(" App [" + pkg.name + "] is not an instance of alexa-app"); return; } @@ -104,9 +106,9 @@ var appServer = function(config) { // Configure GET requests to run a debugger UI if (false !== config.debug) { self.express.get(endpoint, function(req, res) { - if (typeof req.params['schema'] != "undefined") { + if (typeof req.query['schema'] != "undefined") { res.set('Content-Type', 'text/plain').send(app.schema()); - } else if (typeof req.params['utterances'] != "undefined") { + } else if (typeof req.query['utterances'] != "undefined") { res.set('Content-Type', 'text/plain').send(app.utterances()); } else { res.render('test', { "app": app, "schema": app.schema(), "customSlotTypes": (app.customSlotTypes ? app.customSlotTypes() : ""), "utterances": app.utterances(), "intents": app.intents }); @@ -116,7 +118,7 @@ var appServer = function(config) { self.log(" Loaded app [" + pkg.name + "] at endpoint: " + endpoint); } catch (e) { - self.log("Error loading app [" + main + "]: " + e); + self.error("Error loading app [" + main + "]: " + e); } }); return self.apps; @@ -217,19 +219,19 @@ var appServer = function(config) { self.httpsInstance = https.createServer(credentials, self.express).listen(config.httpsPort); //create the HTTPS server self.log("Listening on HTTPS port " + config.httpsPort); } catch (error) { - self.log("Failed to listen via HTTPS Error: " + error); + self.error("Failed to listen via HTTPS Error: " + error); } } else { - self.log("Failed to load privateKey or certificate from /sslcert. HTTPS will not be enabled"); + self.error("Failed to load privateKey or certificate from /sslcert. HTTPS will not be enabled"); } } else { - self.log("privateKey: '" + config.privateKey + "' or certificate: '" + config.certificate + "' do not exist in /sslcert. HTTPS will not be enabled"); + self.error("privateKey: '" + config.privateKey + "' or certificate: '" + config.certificate + "' do not exist in /sslcert. HTTPS will not be enabled"); } } else { - self.log("privatekey, httpsPort, or certificate paramater not set in config. HTTPS will not be enabled"); + self.error("privatekey, httpsPort, or certificate paramater not set in config. HTTPS will not be enabled"); } diff --git a/invalid_examples/apps/bad_app_bad_json/index.js b/invalid_examples/apps/bad_app_bad_json/index.js new file mode 100644 index 0000000..e749709 --- /dev/null +++ b/invalid_examples/apps/bad_app_bad_json/index.js @@ -0,0 +1,11 @@ +var alexa = require('alexa-app'); + +// Allow this module to be reloaded by hotswap when changed +module.change_code = 1; + +// Define an alexa-app +var app = new alexa.app('bad_app_bad_json'); +app.launch(function(req,res) { + res.say("This app should not load!"); +}); +module.exports = app; diff --git a/invalid_examples/apps/bad_app_bad_json/package.json b/invalid_examples/apps/bad_app_bad_json/package.json new file mode 100644 index 0000000..ba6f359 --- /dev/null +++ b/invalid_examples/apps/bad_app_bad_json/package.json @@ -0,0 +1,12 @@ +{ + "version": "1.0.0", + "description": "A sample Alexa app", + "author": "Matt Kruse (http://mattkruse.com/)", + "license": "ISC", + "alexa": { + "applicationId":"amzn1.echo-sdk-ams.app.999999-d0ed-9999-ad00-999999d00ebe" + }, + "dependencies": { + "alexa-app": "^2.1.0" + } +} diff --git a/invalid_examples/apps/bad_app_bad_request_json/index.js b/invalid_examples/apps/bad_app_bad_request_json/index.js new file mode 100644 index 0000000..5332bd2 --- /dev/null +++ b/invalid_examples/apps/bad_app_bad_request_json/index.js @@ -0,0 +1,11 @@ +var alexa = require('alexa-app'); + +// Allow this module to be reloaded by hotswap when changed +module.change_code = 1; + +// Define an alexa-app +var app = new alexa.app('bad_app_bad_request'); +app.launch(function(req,res) { + res.say("This app should not load!"); +}); +module.exports = app; diff --git a/invalid_examples/apps/bad_app_bad_request_json/package.json b/invalid_examples/apps/bad_app_bad_request_json/package.json new file mode 100644 index 0000000..77f0d2d --- /dev/null +++ b/invalid_examples/apps/bad_app_bad_request_json/package.json @@ -0,0 +1,14 @@ +{ + "name": "bad_app_bad_request", + "version": "1.0.0", + "description": "A sample Alexa app", + "main": "index.js", + "author": "Matt Kruse (http://mattkruse.com/)", + "license": "ISC", + "alexa": { + "applicationId":"amzn1.echo-sdk-ams.app.999999-d0ed-9999-ad00-999999d00ebe" + }, + "dependencies": { + "alexa-app": "^2.1.0" + } +} diff --git a/invalid_examples/apps/bad_app_no_json/index.js b/invalid_examples/apps/bad_app_no_json/index.js new file mode 100644 index 0000000..e84700e --- /dev/null +++ b/invalid_examples/apps/bad_app_no_json/index.js @@ -0,0 +1,11 @@ +var alexa = require('alexa-app'); + +// Allow this module to be reloaded by hotswap when changed +module.change_code = 1; + +// Define an alexa-app +var app = new alexa.app('bad_app_no_json'); +app.launch(function(req,res) { + res.say("This app should not load!"); +}); +module.exports = app; diff --git a/invalid_examples/apps/bad_app_not_alexa_app/index.js b/invalid_examples/apps/bad_app_not_alexa_app/index.js new file mode 100644 index 0000000..c9216af --- /dev/null +++ b/invalid_examples/apps/bad_app_not_alexa_app/index.js @@ -0,0 +1,11 @@ +var alexa = require('alexa-app'); + +// Allow this module to be reloaded by hotswap when changed +module.change_code = 1; + +// Define an alexa-app +var app = new alexa.app('bad_app_not_alexa_app'); +app.launch(function(req,res) { + res.say("This app should not load!"); +}); +module.exports = {}; diff --git a/invalid_examples/apps/bad_app_not_alexa_app/package.json b/invalid_examples/apps/bad_app_not_alexa_app/package.json new file mode 100644 index 0000000..5aeb715 --- /dev/null +++ b/invalid_examples/apps/bad_app_not_alexa_app/package.json @@ -0,0 +1,14 @@ +{ + "name": "bad_app_not_alexa_app", + "version": "1.0.0", + "description": "A sample Alexa app", + "main": "index.js", + "author": "Matt Kruse (http://mattkruse.com/)", + "license": "ISC", + "alexa": { + "applicationId":"amzn1.echo-sdk-ams.app.999999-d0ed-9999-ad00-999999d00ebe" + }, + "dependencies": { + "alexa-app": "^2.1.0" + } +} diff --git a/invalid_examples/public_html/index.html b/invalid_examples/public_html/index.html new file mode 100644 index 0000000..f0bbb5a --- /dev/null +++ b/invalid_examples/public_html/index.html @@ -0,0 +1,5 @@ + + + alexa-app-server is running + + diff --git a/invalid_examples/server.js b/invalid_examples/server.js new file mode 100644 index 0000000..dfe7e3a --- /dev/null +++ b/invalid_examples/server.js @@ -0,0 +1,14 @@ +var AlexaAppServer = require("../index.js"); +AlexaAppServer.start( { + port:8080 + // Use preRequest to load user data on each request and add it to the request json. + // In reality, this data would come from a db or files, etc. + ,preRequest: function(json,req,res) { + console.log("preRequest fired"); + json.userDetails = { "name":"Bob Smith" }; + } + // Add a dummy attribute to the response + ,postRequest: function(json,req,res) { + json.dummy = "text"; + } +} ); diff --git a/invalid_examples/server/login.js b/invalid_examples/server/login.js new file mode 100644 index 0000000..1653b29 --- /dev/null +++ b/invalid_examples/server/login.js @@ -0,0 +1,5 @@ +module.exports = function(express,alexaAppServerObject) { + express.use('/login',function(req,res) { + res.send("Imagine this is a dynamic server-side login action"); + }); +}; diff --git a/invalid_examples/sslcert/cert.cer b/invalid_examples/sslcert/cert.cer new file mode 100644 index 0000000..203618f --- /dev/null +++ b/invalid_examples/sslcert/cert.cer @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICsDCCAhmgAwIBAgIJAK0FG9fi8e69MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV +BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX +aWRnaXRzIFB0eSBMdGQwHhcNMTcwMTEzMjM0MzE0WhcNMTgwMTEzMjM0MzE0WjBF +MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50 +ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB +gQDVIqwTKz6mm/i588dB/fz11IAgsgi/Cu9RvgE8H6ps7Le2kf9RAA857sPJtoCJ +GeZwNqlV1EYUH8/RGHAuWALoe6RDBW7kFdW9J1b3IbrjGqEr3hdPNa6MgoukH/Mz +QAbBCE4F9hoRRa6p4G2vnxi3nzUEA0ND4GHUscLvNWbWdwIDAQABo4GnMIGkMB0G +A1UdDgQWBBRfaLJKSAWD773NxNzTRWz/0jx0KTB1BgNVHSMEbjBsgBRfaLJKSAWD +773NxNzTRWz/0jx0KaFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUt +U3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAK0FG9fi +8e69MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAuUqQCqkjZFykLx3J +u1hzmFP8qR49chLQgqArS2JwkTqqUfj5tPn0b6DWxedfAINa8sbc/+pebSTgLcHe ++7N61aZaQuAz0N48c+jaHu8AOMIbDxRkTtjz7KXQL5dHLzXV70EUcNtNtFBxM4L7 +Zp4V5VmyPwS+tli292hEOTDRQGE= +-----END CERTIFICATE----- diff --git a/invalid_examples/sslcert/private-key.pem b/invalid_examples/sslcert/private-key.pem new file mode 100644 index 0000000..3c7a507 --- /dev/null +++ b/invalid_examples/sslcert/private-key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQDVIqwTKz6mm/i588dB/fz11IAgsgi/Cu9RvgE8H6ps7Le2kf9R +AA857sPJtoCJGeZwNqlV1EYUH8/RGHAuWALoe6RDBW7kFdW9J1b3IbrjGqEr3hdP +Na6MgoukH/MzQAbBCE4F9hoRRa6p4G2vnxi3nzUEA0ND4GHUscLvNWbWdwIDAQAB +AoGAftLb26gu5osG7PePSMhuvoUNHOdzZuKF13kdWP5qtdgB1WR4rWVAqjNWU3AC +ehJsWbdc+dKPRKhNS9mj3x/F0iSGOUvVwBRU7SvfuJLSp+z0Pk4gh+aJz/6R3Rh+ +xiUyeqFJksS4k1qKCIXehXAGoTW/XLRDUVG+hATHbC73gMECQQD0FeHOBFW51dXr +eM0IY3VW9s1JdYMYt+jgb/Jg7DU/aJ48+LoVkk2/hieI3sQff3wBIf8hN7vgo0Ny +MPu23VAXAkEA34oJADoum4MdAy7i8Q9Ap6c5Kp1cBaJ75tcuhHBlWWZiQy6QmZqi +8yDQpTKWMb+Z+YP5Kul7vhK6KeC0/XdIoQJBAPLpjA2BlucY/ooXcMV2ZeKkP+1p +e4xwCtzBzE/VA7EVJtW7G0Y4khOXKWU3fatzLi/aa5PdaabIFGligj+cxQUCQQCG +i7i7MEnZRGN0BQaHfVy3DEm2Qpyer5vP53iSMmxuENfYA/D440BtAjVTGU2Zh++P +ZUXV9E6MqwzuI9gML33BAkAHWuxlPZmjmOj0DYV50yT0w8WZiaWeUpl6h/pEOtEq +M1F+ioph2YJrWeEY4GbOsXnbm+CEoN8mfiAhFZvTyykW +-----END RSA PRIVATE KEY----- diff --git a/test/sample-launch-req.json b/test/sample-launch-req.json new file mode 100644 index 0000000..753148f --- /dev/null +++ b/test/sample-launch-req.json @@ -0,0 +1,19 @@ +{ + "version": "1.0", + "session": { + "new": true, + "sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef", + "application": { + "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe" + }, + "attributes": {}, + "user": { + "userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2" + } + }, + "request": { + "type": "LaunchRequest", + "requestId": "amzn1.echo-api.request.9cdaa4db-f20e-4c58-8d01-c75322d6c423", + "timestamp": "2015-05-13T12:34:56Z" + } +} \ No newline at end of file diff --git a/test/sample-schema.txt b/test/sample-schema.txt new file mode 100644 index 0000000..1d208aa --- /dev/null +++ b/test/sample-schema.txt @@ -0,0 +1,26 @@ +{ + "intents": [ + { + "intent": "NameIntent", + "slots": [ + { + "name": "NAME", + "type": "LITERAL" + }, + { + "name": "AGE", + "type": "NUMBER" + } + ] + }, + { + "intent": "AgeIntent", + "slots": [ + { + "name": "AGE", + "type": "NUMBER" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/sample-utterances.txt b/test/sample-utterances.txt new file mode 100644 index 0000000..188d966 --- /dev/null +++ b/test/sample-utterances.txt @@ -0,0 +1,200 @@ +NameIntent My name is {matt|NAME} and I am {one|AGE} years old +NameIntent my name's {bob|NAME} and I am {two|AGE} years old +NameIntent My name is {bill|NAME} and I am {three|AGE} +NameIntent my name's {jake|NAME} and I am {four|AGE} +NameIntent My name is {nancy|NAME} and I am {five|AGE} years old +NameIntent my name's {mary|NAME} and I am {six|AGE} years old +NameIntent My name is {jane|NAME} and I am {seven|AGE} +NameIntent My name is {matt|NAME} and I am {eight|AGE} years old +NameIntent my name's {bob|NAME} and I am {nine|AGE} years old +NameIntent My name is {bill|NAME} and I am {ten|AGE} +NameIntent my name's {jake|NAME} and I am {eleven|AGE} +NameIntent My name is {nancy|NAME} and I am {twelve|AGE} years old +NameIntent my name's {mary|NAME} and I am {thirteen|AGE} years old +NameIntent My name is {jane|NAME} and I am {fourteen|AGE} +NameIntent My name is {matt|NAME} and I am {fifteen|AGE} years old +NameIntent my name's {bob|NAME} and I am {sixteen|AGE} years old +NameIntent My name is {bill|NAME} and I am {seventeen|AGE} +NameIntent my name's {jake|NAME} and I am {eighteen|AGE} +NameIntent My name is {nancy|NAME} and I am {nineteen|AGE} years old +NameIntent my name's {mary|NAME} and I am {twenty|AGE} years old +NameIntent My name is {jane|NAME} and I am {twenty one|AGE} +NameIntent My name is {matt|NAME} and I am {twenty two|AGE} years old +NameIntent my name's {bob|NAME} and I am {twenty three|AGE} years old +NameIntent My name is {bill|NAME} and I am {twenty four|AGE} +NameIntent my name's {jake|NAME} and I am {twenty five|AGE} +NameIntent My name is {nancy|NAME} and I am {twenty six|AGE} years old +NameIntent my name's {mary|NAME} and I am {twenty seven|AGE} years old +NameIntent My name is {jane|NAME} and I am {twenty eight|AGE} +NameIntent My name is {matt|NAME} and I am {twenty nine|AGE} years old +NameIntent my name's {bob|NAME} and I am {thirty|AGE} years old +NameIntent My name is {bill|NAME} and I am {thirty one|AGE} +NameIntent my name's {jake|NAME} and I am {thirty two|AGE} +NameIntent My name is {nancy|NAME} and I am {thirty three|AGE} years old +NameIntent my name's {mary|NAME} and I am {thirty four|AGE} years old +NameIntent My name is {jane|NAME} and I am {thirty five|AGE} +NameIntent My name is {matt|NAME} and I am {thirty six|AGE} years old +NameIntent my name's {bob|NAME} and I am {thirty seven|AGE} years old +NameIntent My name is {bill|NAME} and I am {thirty eight|AGE} +NameIntent my name's {jake|NAME} and I am {thirty nine|AGE} +NameIntent My name is {nancy|NAME} and I am {forty|AGE} years old +NameIntent my name's {mary|NAME} and I am {forty one|AGE} years old +NameIntent My name is {jane|NAME} and I am {forty two|AGE} +NameIntent My name is {matt|NAME} and I am {forty three|AGE} years old +NameIntent my name's {bob|NAME} and I am {forty four|AGE} years old +NameIntent My name is {bill|NAME} and I am {forty five|AGE} +NameIntent my name's {jake|NAME} and I am {forty six|AGE} +NameIntent My name is {nancy|NAME} and I am {forty seven|AGE} years old +NameIntent my name's {mary|NAME} and I am {forty eight|AGE} years old +NameIntent My name is {jane|NAME} and I am {forty nine|AGE} +NameIntent My name is {matt|NAME} and I am {fifty|AGE} years old +NameIntent my name's {bob|NAME} and I am {fifty one|AGE} years old +NameIntent My name is {bill|NAME} and I am {fifty two|AGE} +NameIntent my name's {jake|NAME} and I am {fifty three|AGE} +NameIntent My name is {nancy|NAME} and I am {fifty four|AGE} years old +NameIntent my name's {mary|NAME} and I am {fifty five|AGE} years old +NameIntent My name is {jane|NAME} and I am {fifty six|AGE} +NameIntent My name is {matt|NAME} and I am {fifty seven|AGE} years old +NameIntent my name's {bob|NAME} and I am {fifty eight|AGE} years old +NameIntent My name is {bill|NAME} and I am {fifty nine|AGE} +NameIntent my name's {jake|NAME} and I am {sixty|AGE} +NameIntent My name is {nancy|NAME} and I am {sixty one|AGE} years old +NameIntent my name's {mary|NAME} and I am {sixty two|AGE} years old +NameIntent My name is {jane|NAME} and I am {sixty three|AGE} +NameIntent My name is {matt|NAME} and I am {sixty four|AGE} years old +NameIntent my name's {bob|NAME} and I am {sixty five|AGE} years old +NameIntent My name is {bill|NAME} and I am {sixty six|AGE} +NameIntent my name's {jake|NAME} and I am {sixty seven|AGE} +NameIntent My name is {nancy|NAME} and I am {sixty eight|AGE} years old +NameIntent my name's {mary|NAME} and I am {sixty nine|AGE} years old +NameIntent My name is {jane|NAME} and I am {seventy|AGE} +NameIntent My name is {matt|NAME} and I am {seventy one|AGE} years old +NameIntent my name's {bob|NAME} and I am {seventy two|AGE} years old +NameIntent My name is {bill|NAME} and I am {seventy three|AGE} +NameIntent my name's {jake|NAME} and I am {seventy four|AGE} +NameIntent My name is {nancy|NAME} and I am {seventy five|AGE} years old +NameIntent my name's {mary|NAME} and I am {seventy six|AGE} years old +NameIntent My name is {jane|NAME} and I am {seventy seven|AGE} +NameIntent My name is {matt|NAME} and I am {seventy eight|AGE} years old +NameIntent my name's {bob|NAME} and I am {seventy nine|AGE} years old +NameIntent My name is {bill|NAME} and I am {eighty|AGE} +NameIntent my name's {jake|NAME} and I am {eighty one|AGE} +NameIntent My name is {nancy|NAME} and I am {eighty two|AGE} years old +NameIntent my name's {mary|NAME} and I am {eighty three|AGE} years old +NameIntent My name is {jane|NAME} and I am {eighty four|AGE} +NameIntent My name is {matt|NAME} and I am {eighty five|AGE} years old +NameIntent my name's {bob|NAME} and I am {eighty six|AGE} years old +NameIntent My name is {bill|NAME} and I am {eighty seven|AGE} +NameIntent my name's {jake|NAME} and I am {eighty eight|AGE} +NameIntent My name is {nancy|NAME} and I am {eighty nine|AGE} years old +NameIntent my name's {mary|NAME} and I am {ninety|AGE} years old +NameIntent My name is {jane|NAME} and I am {ninety one|AGE} +NameIntent My name is {matt|NAME} and I am {ninety two|AGE} years old +NameIntent my name's {bob|NAME} and I am {ninety three|AGE} years old +NameIntent My name is {bill|NAME} and I am {ninety four|AGE} +NameIntent my name's {jake|NAME} and I am {ninety five|AGE} +NameIntent My name is {nancy|NAME} and I am {ninety six|AGE} years old +NameIntent my name's {mary|NAME} and I am {ninety seven|AGE} years old +NameIntent My name is {jane|NAME} and I am {ninety eight|AGE} +NameIntent My name is {matt|NAME} and I am {ninety nine|AGE} years old +NameIntent my name's {bob|NAME} and I am {one hundred|AGE} years old +AgeIntent My age is {one|AGE} +AgeIntent My age is {two|AGE} +AgeIntent My age is {three|AGE} +AgeIntent My age is {four|AGE} +AgeIntent My age is {five|AGE} +AgeIntent My age is {six|AGE} +AgeIntent My age is {seven|AGE} +AgeIntent My age is {eight|AGE} +AgeIntent My age is {nine|AGE} +AgeIntent My age is {ten|AGE} +AgeIntent My age is {eleven|AGE} +AgeIntent My age is {twelve|AGE} +AgeIntent My age is {thirteen|AGE} +AgeIntent My age is {fourteen|AGE} +AgeIntent My age is {fifteen|AGE} +AgeIntent My age is {sixteen|AGE} +AgeIntent My age is {seventeen|AGE} +AgeIntent My age is {eighteen|AGE} +AgeIntent My age is {nineteen|AGE} +AgeIntent My age is {twenty|AGE} +AgeIntent My age is {twenty one|AGE} +AgeIntent My age is {twenty two|AGE} +AgeIntent My age is {twenty three|AGE} +AgeIntent My age is {twenty four|AGE} +AgeIntent My age is {twenty five|AGE} +AgeIntent My age is {twenty six|AGE} +AgeIntent My age is {twenty seven|AGE} +AgeIntent My age is {twenty eight|AGE} +AgeIntent My age is {twenty nine|AGE} +AgeIntent My age is {thirty|AGE} +AgeIntent My age is {thirty one|AGE} +AgeIntent My age is {thirty two|AGE} +AgeIntent My age is {thirty three|AGE} +AgeIntent My age is {thirty four|AGE} +AgeIntent My age is {thirty five|AGE} +AgeIntent My age is {thirty six|AGE} +AgeIntent My age is {thirty seven|AGE} +AgeIntent My age is {thirty eight|AGE} +AgeIntent My age is {thirty nine|AGE} +AgeIntent My age is {forty|AGE} +AgeIntent My age is {forty one|AGE} +AgeIntent My age is {forty two|AGE} +AgeIntent My age is {forty three|AGE} +AgeIntent My age is {forty four|AGE} +AgeIntent My age is {forty five|AGE} +AgeIntent My age is {forty six|AGE} +AgeIntent My age is {forty seven|AGE} +AgeIntent My age is {forty eight|AGE} +AgeIntent My age is {forty nine|AGE} +AgeIntent My age is {fifty|AGE} +AgeIntent My age is {fifty one|AGE} +AgeIntent My age is {fifty two|AGE} +AgeIntent My age is {fifty three|AGE} +AgeIntent My age is {fifty four|AGE} +AgeIntent My age is {fifty five|AGE} +AgeIntent My age is {fifty six|AGE} +AgeIntent My age is {fifty seven|AGE} +AgeIntent My age is {fifty eight|AGE} +AgeIntent My age is {fifty nine|AGE} +AgeIntent My age is {sixty|AGE} +AgeIntent My age is {sixty one|AGE} +AgeIntent My age is {sixty two|AGE} +AgeIntent My age is {sixty three|AGE} +AgeIntent My age is {sixty four|AGE} +AgeIntent My age is {sixty five|AGE} +AgeIntent My age is {sixty six|AGE} +AgeIntent My age is {sixty seven|AGE} +AgeIntent My age is {sixty eight|AGE} +AgeIntent My age is {sixty nine|AGE} +AgeIntent My age is {seventy|AGE} +AgeIntent My age is {seventy one|AGE} +AgeIntent My age is {seventy two|AGE} +AgeIntent My age is {seventy three|AGE} +AgeIntent My age is {seventy four|AGE} +AgeIntent My age is {seventy five|AGE} +AgeIntent My age is {seventy six|AGE} +AgeIntent My age is {seventy seven|AGE} +AgeIntent My age is {seventy eight|AGE} +AgeIntent My age is {seventy nine|AGE} +AgeIntent My age is {eighty|AGE} +AgeIntent My age is {eighty one|AGE} +AgeIntent My age is {eighty two|AGE} +AgeIntent My age is {eighty three|AGE} +AgeIntent My age is {eighty four|AGE} +AgeIntent My age is {eighty five|AGE} +AgeIntent My age is {eighty six|AGE} +AgeIntent My age is {eighty seven|AGE} +AgeIntent My age is {eighty eight|AGE} +AgeIntent My age is {eighty nine|AGE} +AgeIntent My age is {ninety|AGE} +AgeIntent My age is {ninety one|AGE} +AgeIntent My age is {ninety two|AGE} +AgeIntent My age is {ninety three|AGE} +AgeIntent My age is {ninety four|AGE} +AgeIntent My age is {ninety five|AGE} +AgeIntent My age is {ninety six|AGE} +AgeIntent My age is {ninety seven|AGE} +AgeIntent My age is {ninety eight|AGE} +AgeIntent My age is {ninety nine|AGE} +AgeIntent My age is {one hundred|AGE} \ No newline at end of file diff --git a/test/test-examples-server-app-loading-fail-checks.js b/test/test-examples-server-app-loading-fail-checks.js new file mode 100644 index 0000000..f078ba5 --- /dev/null +++ b/test/test-examples-server-app-loading-fail-checks.js @@ -0,0 +1,30 @@ +/*jshint expr: true*/ +"use strict"; +var chai = require("chai"); +var expect = chai.expect; +chai.config.includeStack = true; +var request = require("supertest-as-promised"); + +describe("Alexa App Server with Examples & App loading fail checking", function() { + var testServer; + + before(function() { + testServer = require("../index").start({ + port: 3000, + server_root: 'invalid_examples' + }); + }); + + after(function() { + testServer.stop(); + }); + + it("starts an express instance", function() { + return request(testServer.express) + .get('/') + .expect(200).then(function(response) { + expect(response.text).to.contain("alexa-app-server is running"); + } + ); + }); +}); \ No newline at end of file diff --git a/test/test-examples-server-https-fail-checks.js b/test/test-examples-server-https-fail-checks.js new file mode 100644 index 0000000..68fad7b --- /dev/null +++ b/test/test-examples-server-https-fail-checks.js @@ -0,0 +1,65 @@ +/*jshint expr: true*/ +"use strict"; +var chai = require("chai"); +var expect = chai.expect; +chai.config.includeStack = true; +var request = require("supertest-as-promised"); + +describe("Alexa App Server with Examples & HTTPS fail checking", function() { + var testServer; + + afterEach(function() { + testServer.stop(); + }); + + it("fails to mount due to missing HTTPS parameters", function() { + testServer = require("../index").start({ + port: 3000, + server_root: 'invalid_examples', + httpsEnabled: true + }); + + return request(testServer.express) + .get('/') + .expect(200).then(function(response) { + expect(response.text).to.contain("alexa-app-server is running"); + } + ); + }); + + it("fails to mount due to invalid credential files", function() { + testServer = require("../index").start({ + port: 3000, + server_root: 'invalid_examples', + httpsEnabled: true, + httpsPort: 6000, + privateKey: 'pr1vat3-k3y.p3m', + certificate: 'c3rt.c3r' + }); + + return request(testServer.express) + .get('/') + .expect(200).then(function(response) { + expect(response.text).to.contain("alexa-app-server is running"); + } + ); + }); + + it("fails to mount due to invalid port", function() { + testServer = require("../index").start({ + port: 3000, + server_root: 'invalid_examples', + httpsEnabled: true, + httpsPort: -1, + privateKey: 'private-key.pem', + certificate: 'cert.cer' + }); + + return request(testServer.express) + .get('/') + .expect(200).then(function(response) { + expect(response.text).to.contain("alexa-app-server is running"); + } + ); + }); +}); \ No newline at end of file diff --git a/test/test-examples-server-https-support.js b/test/test-examples-server-https-support.js index dfe8b75..1fd665e 100644 --- a/test/test-examples-server-https-support.js +++ b/test/test-examples-server-https-support.js @@ -8,7 +8,7 @@ var request = require("supertest-as-promised"); describe("Alexa App Server with Examples & HTTPS support", function() { var testServer; - beforeEach(function() { + before(function() { testServer = require("../index").start({ port: 3000, server_root: 'examples', @@ -19,34 +19,25 @@ describe("Alexa App Server with Examples & HTTPS support", function() { }); }); - afterEach(function() { + after(function() { testServer.stop(); }); - it("starts an express instance", function() { - return request(testServer.express) - .get('/') - .expect(200).then(function(response) { - expect(response.text).to.contain("alexa-app-server is running"); - } - ); - }); - it("mounts hello world app", function() { return request(testServer.express) .get('/alexa/helloworld') - .expect(200) + .expect(200); }); it("mounts number_guessing_game", function() { return request(testServer.express) .get('/alexa/guessinggame') - .expect(200) + .expect(200); }); it("404s on an invalid app", function() { return request(testServer.express) .get('/alexa/invalid') - .expect(404) + .expect(404); }); }); \ No newline at end of file diff --git a/test/test-examples-server-pre-post-functions.js b/test/test-examples-server-pre-post-functions.js new file mode 100644 index 0000000..a971fd7 --- /dev/null +++ b/test/test-examples-server-pre-post-functions.js @@ -0,0 +1,41 @@ +/*jshint expr: true*/ +"use strict"; +var chai = require("chai"); +var expect = chai.expect; +chai.config.includeStack = true; +var request = require("supertest-as-promised"); +var fs = require('fs'); + +describe("Alexa App Server with Examples & Pre/Post functions", function() { + var testServer; + + var sampleLaunchReq = JSON.parse(fs.readFileSync("test/sample-launch-req.json", 'utf8')); + + before(function() { + testServer = require("../index").start({ + port: 3000, + server_root: 'examples', + pre: function(appServer) { console.log("pre function fired!"); }, + post: function(appServer) { console.log("post function fired!"); }, + preRequest: function(json,request,response) { console.log("preRequest function fired!"); }, + postRequest : function(json,request,response) { console.log("postRequest function fired!"); } + }); + }); + + after(function() { + testServer.stop(); + }); + + it("mounts hello world app (GET)", function() { + return request(testServer.express) + .get('/alexa/helloworld') + .expect(200); + }); + + it("mounts hello world app (POST)", function() { + return request(testServer.express) + .post('/alexa/helloworld') + .send(sampleLaunchReq) + .expect(200); + }); +}); \ No newline at end of file diff --git a/test/test-examples-server-verification.js b/test/test-examples-server-verification.js index 0ca56d9..81a2497 100644 --- a/test/test-examples-server-verification.js +++ b/test/test-examples-server-verification.js @@ -8,7 +8,7 @@ var request = require("supertest-as-promised"); describe("Alexa App Server with Examples & Verification", function() { var testServer; - beforeEach(function() { + before(function() { testServer = require("../index").start({ port: 3000, server_root: 'examples', @@ -16,34 +16,25 @@ describe("Alexa App Server with Examples & Verification", function() { }); }); - afterEach(function() { + after(function() { testServer.stop(); }); - it("starts an express instance", function() { - return request(testServer.express) - .get('/') - .expect(200).then(function(response) { - expect(response.text).to.contain("alexa-app-server is running"); - } - ); - }); - it("mounts hello world app", function() { return request(testServer.express) .get('/alexa/helloworld') - .expect(200) + .expect(200); }); it("mounts number_guessing_game", function() { return request(testServer.express) .get('/alexa/guessinggame') - .expect(200) + .expect(200); }); it("404s on an invalid app", function() { return request(testServer.express) .get('/alexa/invalid') - .expect(404) + .expect(404); }); }); \ No newline at end of file diff --git a/test/test-examples-server.js b/test/test-examples-server.js index 7f5b62d..5f2ee88 100644 --- a/test/test-examples-server.js +++ b/test/test-examples-server.js @@ -4,38 +4,23 @@ var chai = require("chai"); var expect = chai.expect; chai.config.includeStack = true; var request = require("supertest-as-promised"); +var fs = require('fs'); describe("Alexa App Server with Examples", function() { var testServer; - var sampleLaunchReq = { - "version": "1.0", - "session": { - "new": true, - "sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef", - "application": { - "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe" - }, - "attributes": {}, - "user": { - "userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2" - } - }, - "request": { - "type": "LaunchRequest", - "requestId": "amzn1.echo-api.request.9cdaa4db-f20e-4c58-8d01-c75322d6c423", - "timestamp": "2015-05-13T12:34:56Z" - } - }; + var sampleLaunchReq = JSON.parse(fs.readFileSync("test/sample-launch-req.json", 'utf8')); + var sampleUtterances = fs.readFileSync("test/sample-utterances.txt", 'utf8'); + var sampleSchema = fs.readFileSync("test/sample-schema.txt", 'utf8'); - beforeEach(function() { + before(function() { testServer = require("../index").start({ port: 3000, server_root: 'examples' }); }); - afterEach(function() { + after(function() { testServer.stop(); }); @@ -51,39 +36,57 @@ describe("Alexa App Server with Examples", function() { it("mounts hello world app (GET)", function() { return request(testServer.express) .get('/alexa/helloworld') - .expect(200) + .expect(200); }); it("mounts hello world app (POST)", function() { return request(testServer.express) .post('/alexa/helloworld') .send(sampleLaunchReq) - .expect(200) + .expect(200); }); it("mounts number_guessing_game (GET)", function() { return request(testServer.express) .get('/alexa/guessinggame') - .expect(200) + .expect(200); }); it("mounts number_guessing_game (POST)", function() { return request(testServer.express) .post('/alexa/guessinggame') .send(sampleLaunchReq) - .expect(200) + .expect(200); }); it("404s on an invalid app (GET)", function() { return request(testServer.express) .get('/alexa/invalid') - .expect(404) + .expect(404); }); it("404s on an invalid app (POST)", function() { return request(testServer.express) .post('/alexa/invalid') .send(sampleLaunchReq) - .expect(404) + .expect(404); + }); + + it("returns the schema of the hello world app", function() { + return request(testServer.express) + .get('/alexa/helloworld?schema') + .expect(200).then(function(res) { + expect(res.text).to.equal.sampleSchema; + } + ); + }); + + it("returns the utterances of the hello world app", function() { + return request(testServer.express) + .get('/alexa/helloworld?utterances') + .expect(200).then(function(res) { + expect(res.text).to.equal.sampleUtterances; + } + ); }); }); diff --git a/test/test-server.js b/test/test-server.js index 176bfd0..cdebc17 100644 --- a/test/test-server.js +++ b/test/test-server.js @@ -8,13 +8,13 @@ var request = require("supertest-as-promised"); describe("Alexa App Server", function() { var testServer; - beforeEach(function() { + before(function() { testServer = require("../index").start({ port: 3000 }); }); - afterEach(function() { + after(function() { testServer.stop(); });