Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Test components
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Perata committed Nov 20, 2017
1 parent 17cdff8 commit cc8a2b2
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/bin/bst-intend-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,28 @@ describe("bst-intend", function() {
NodeUtil.load("../../bin/bst-intend.js");
});

it("Speaks after cleaning session", function(done) {
process.argv = command("node bst-intend.js Hello --newSession");
mockery.registerMock("../lib/client/bst-virtual-alexa", {
BSTVirtualAlexa: function () {
this.start = function () {
};
let sessionRemoved = false;
this.deleteSession = function () {
sessionRemoved = true;
};

this.intended = function () {
assert(sessionRemoved);
done();
};

}
});

NodeUtil.load("../../bin/bst-intend.js");
});

it("Has no interaction model", function(done) {
process.argv = command("node bst-intend.js HelloIntend");

Expand Down
22 changes: 22 additions & 0 deletions test/bin/bst-utter-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ describe("bst-utter", function() {
NodeUtil.load("../../bin/bst-utter.js");
});

it("Speaks after cleaning session", function(done) {
process.argv = command("node bst-utter.js Hello --newSession");
mockery.registerMock("../lib/client/bst-virtual-alexa", {
BSTVirtualAlexa: function () {
this.start = function () {
};
let sessionRemoved = false;
this.deleteSession = function () {
sessionRemoved = true;
};

this.spoken = function (utterance: string, callback: any) {
assert(sessionRemoved);
done();
};

}
});

NodeUtil.load("../../bin/bst-utter.js");
});

it("Speaks One Word With Verbose", function(done) {
process.argv = command("node bst-utter.js Hello");
mockery.registerMock("../lib/client/bst-virtual-alexa", {
Expand Down
108 changes: 107 additions & 1 deletion test/client/bst-virtual-alexa-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ let globalModule = {
},
updateApplicationID: function (id) {
applicationID = id;
}
},
loadSession: function () {
return null;
},
saveSession: function () {

},
deleteSession: function () {

},
};
},
running : function() {
Expand Down Expand Up @@ -266,4 +275,101 @@ describe("BSTVirtualAlexa", async function() {
});
});
});

describe("Manages Session", function () {
let session;
let oldSession;
beforeEach(function () {
process.chdir("test/resources");

globalModule.Global.config = function () {
return {
configuration: {
lambdaDeploy: {},
},
save: function () {

},
applicationID: function() {
return applicationID;
},
updateApplicationID: function (id) {
applicationID = id;
},
loadSession: function () {
oldSession = Object.assign({}, session);
},
saveSession: function () {
session = {
id: "sessionId",
attributes: {
"STATE": "_TEST_STATE",
}
};
},
deleteSession: function () {
session = null;
},
};
};

mockery.enable({useCleanCache: true});
mockery.warnOnUnregistered(false);
mockery.registerMock("../core/global", globalModule);
BSTVirtualAlexa = require("../../lib/client/bst-virtual-alexa").BSTVirtualAlexa;

lambdaServer = new LambdaServer("exampleProject/ExampleLambda.js", 10000);
lambdaServer.start();
});

afterEach(function () {
process.chdir("../..");
lambdaServer.stop();
mockery.deregisterAll();
mockery.disable();
});

it("Saves on launch", function (done) {
alexa = new BSTVirtualAlexa("http://localhost:10000");
alexa.start();

alexa.launched(function (error: any, response: any) {
assert.deepEqual(session, {
id: "sessionId",
attributes: {
"STATE": "_TEST_STATE",
}
});
done();
});

});

it("Loads on intent", function (done) {
alexa = new BSTVirtualAlexa("http://localhost:10000");
alexa.start();

alexa.intended(null, null, function (error: any, response: any) {
assert.deepEqual(oldSession, {
id: "sessionId",
attributes: {
"STATE": "_TEST_STATE",
}
});
done();
});

});


it("Removes on delete", function () {
alexa = new BSTVirtualAlexa("http://localhost:10000");
alexa.start();

alexa.deleteSession();
assert.equal(session, null);

});

});
});

0 comments on commit cc8a2b2

Please sign in to comment.