Skip to content

Commit

Permalink
Adding tests for session attribute get/set deep properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcrites committed Jan 11, 2017
1 parent 5988ce9 commit 95426d3
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/test_alexa_app_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,66 @@ describe("Alexa", function() {
)
]);
});

it("does not update session properties without explicit set", function() {
testApp.pre = function(req, res, type) {
var session = req.getSession();
session.set("foo", true);
session.set("bar", {qaz: "woah"});
};

testApp.intent("airportInfoIntent", {}, function(req, res) {
res.say("message").shouldEndSession(false);
var session = req.getSession();
var bar = session.get("bar");
bar.qaz = "not woah";
return true;
});

var subject = testApp.request(mockRequest).then(function(response) {
return response.sessionAttributes;
});

return Promise.all([
expect(subject).to.eventually.become({
foo: true,
bar: {
qaz: "woah"
}
})
]);
});

it("updates session properties with explicit set", function() {
testApp.pre = function(req, res, type) {
var session = req.getSession();
session.set("foo", true);
session.set("bar", {qaz: "woah"});
};

testApp.intent("airportInfoIntent", {}, function(req, res) {
res.say("message").shouldEndSession(false);
var session = req.getSession();
var bar = session.get("bar");
bar.qaz = "not woah";
session.set("bar", bar);
session.set("foo", false);
return true;
});

var subject = testApp.request(mockRequest).then(function(response) {
return response.sessionAttributes;
});

return Promise.all([
expect(subject).to.eventually.become({
foo: false,
bar: {
qaz: "not woah"
}
})
]);
});
});
});

Expand Down

0 comments on commit 95426d3

Please sign in to comment.