Created
October 25, 2014 18:40
-
-
Save dewe/9d57faf7ae1cb84af941 to your computer and use it in GitHub Desktop.
How to mock session data for socket.io 0.9.16 in express.io 1.1.13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express.io')(); | |
app.http().io(); | |
app.listen(7076) | |
// override authorization checks, always true. This works even though app has begun listening. | |
app.io.set('authorization', function (handshake, accept) { accept(null, true); }); | |
// register a new handler for the message handler under test. The can inject mock data into session. | |
var handler = app.io.router['get-discussions']; | |
app.io.router['get-discussions'] = function (request) { | |
// create a new session for the request | |
request.sessionStore.generate(request); | |
// add some data to the session | |
request.session.apikey = "1234567890" | |
// call the sut. | |
handler(request); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment