HTML and CSS Reference
In-Depth Information
The test resolves the promise returned by waitForMessagesSince , and
expects the resolving data to be wrapped in a cometClient friendly object and
passed to the resolve method along with a 200 status. Listing 14.76 shows the
required code to pass the test.
Listing 14.76 Responding from get
get: function () {
var id = this.request.headers["x-access-token"]
||
0;
var wait = this.chatRoom.waitForMessagesSince(id);
wait.then(function (msgs) {
this.respond(200, { message: msgs });
}.bind(this));
}
14.6.2.4 Updating the Token
Along with the messages, the get method needs to embed a token in its response.
The token will automatically be picked up by cometClient and sent with the
X-Access-Token header on subsequent requests. Listing 14.77 expects the token
to be passed along with the message.
Listing 14.77 Expecting a token embedded in the response
"should include token in response": function (test) {
this.controller.respond = stub();
this.waitForMessagesPromise.resolve([{id:24}, {id:25}]);
this.controller.get();
process.nextTick(function () {
test.same(this.controller.respond.args[1].token, 25);
test.done();
}.bind(this));
}
Passing the test involves passing the id of the last message as the token as seen
in Listing 14.78.
Listing 14.78 Embedding the token
get: function () {
/* ... */
wait.then(function (messages) {
 
Search WWH ::




Custom Search