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

Test fixes and an actual test for firing pre/post events. #43

Merged
merged 3 commits into from
Jan 28, 2017
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Changelog

### 2.3.2 (Next)

* [#43](https://github.com/alexa-js/alexa-app-server/pull/43): Test fixes and an actual test for firing pre/post events. - [@dblock](https://github.com/dblock).
* [#36](https://github.com/alexa-js/alexa-app-server/pull/36): Added option to specify host address to bind servers to - [@tejashah88](https://github.com/tejashah88).
* [#35](https://github.com/alexa-js/alexa-app-server/pull/35): Error occurs when `verify` and `debug` are both set to true - [@tejashah88](https://github.com/tejashah88).
* [#34](https://github.com/alexa-js/alexa-app-server/pull/34): Added tests for fail cases and schemas/utterances - [@tejashah88](https://github.com/tejashah88).
Expand Down
16 changes: 1 addition & 15 deletions test/test-examples-server-app-loading-fail-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ describe("Alexa App Server with Examples & App loading fail checking", function(
.get('/')
.expect(200).then(function(response) {
expect(response.text).to.contain("alexa-app-server is running");
}
);
});

it("should throw an error when 'debug' and 'verify' are enabled", function() {
var fn = function() {
testServer = alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
debug: true,
verify: true
});
};

expect(fn).to.throw(Error);
});
});
});
22 changes: 22 additions & 0 deletions test/test-examples-server-debug-verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*jshint expr: true*/
"use strict";
var chai = require("chai");
var expect = chai.expect;
chai.config.includeStack = true;
var request = require("supertest-as-promised");
var alexaAppServer = require("../index");

describe("Alexa App Server with Examples & App loading fail checking", function() {
it("throws an error when 'debug' and 'verify' are enabled", function() {
var fn = function() {
alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
debug: true,
verify: true
});
};

expect(fn).to.throw(Error);
});
});
45 changes: 33 additions & 12 deletions test/test-examples-server-pre-post-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@ var alexaAppServer = require("../index");

describe("Alexa App Server with Examples & Pre/Post functions", function() {
var testServer;
var fired;

var sampleLaunchReq = JSON.parse(fs.readFileSync("test/sample-launch-req.json", 'utf8'));

before(function() {
fired = {};
testServer = alexaAppServer.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!"); }
pre: function(appServer) {
fired.pre = true;
},
post: function(appServer) {
fired.post = true;
},
preRequest: function(json, request, response) {
fired.preRequest = true;
},
postRequest: function(json, request, response) {
fired.postRequest = true;
}
});
});

Expand All @@ -28,15 +38,26 @@ describe("Alexa App Server with Examples & Pre/Post functions", function() {
});

it("mounts hello world app (GET)", function() {
return request(testServer.express)
.get('/alexa/helloworld')
.expect(200);
return request(testServer.express)
.get('/alexa/helloworld')
.expect(200).then(function(response) {
expect(fired.pre).to.equal(true);
expect(fired.post).to.equal(true);
// only called for actual Alexa requests
expect(fired.preRequest).to.equal(undefined);
expect(fired.postRequest).to.equal(undefined);
});
});

it("mounts hello world app (POST)", function() {
return request(testServer.express)
.post('/alexa/helloworld')
.send(sampleLaunchReq)
.expect(200);
return request(testServer.express)
.post('/alexa/helloworld')
.send(sampleLaunchReq)
.expect(200).then(function(response) {
expect(fired.pre).to.equal(true);
expect(fired.post).to.equal(true);
expect(fired.preRequest).to.equal(true);
expect(fired.postRequest).to.equal(true);
});
});
});
});