HTML and CSS Reference
In-Depth Information
testCase(exports, "chatRoomController.post", {
/* ... */
"should close connection": function (test) {
var data = { data: { user: "cjno", message: "hi" } };
this.controller.post();
this.sendRequest(data);
test.ok(this.res.end.called);
test.done();
}
});
The test fails, and Listing 14.24 shows the updated post method, which passes
all the tests.
Listing 14.24 Closing the response
post: function () {
/* ... */
this.request.addListener("end", function () {
/* ... */
this.response.end();
}.bind(this));
}
That's it for the post method. It is now functional enough to properly handle
well-formed requests. In a real-world setting, however, I encourage more rigid input
verification and error handling. Making the method more resilient is left as an
exercise.
14.2.6 Taking the Application for a Spin
If we make a small adjustment to the server, we can now take the application for a
spin. In the original listing, the server did not set up a chatRoom for the controller.
To successfully run the application, update the server to match Listing 14.25.
Listing 14.25 The final server
var http = require("http");
var url = require("url");
var crController = require("chapp/chat_room_controller");
var chatRoom = require("chapp/chat_room");
 
Search WWH ::




Custom Search