Recreating Express Sessions?

Given a sessionId, I need to get a hold of the express session object. Afterwards, I would like to be able to edit this session object, and have it automatically update the session in the session store.

Session = require('express').session.Session;

_testSession: (sStore, sId) ->
  console.log 'called _testSession with session id: ' + sId

  sStore.get sId, (error, session) ->
    expressSession = new Session 
        sessionId: sId
        sessionStore: sStore
        , session
    expressSession.foo = 17

    console.log 'set expressSession.foo to: ' + expressSession.foo

    setTimeout (()->
        sStore.get sId, (error, session) ->
            console.log 'foo = ' + session.foo
        ), 1000

However, when running this test, I get the following output:

called _testSession with session id: YaFLcq3eSvoNuwnLS1T1ntrC.3UJMuQ5So6lYRWLDgIRx4Vk/Ab1qH65zV9IwMqoMcR8
set expressSession.foo to: 17
foo = undefined

Does anyone have any idea what's going on here?... :(

==== EDIT ====

I tried calling save() as well, so that the code reads:

console.log 'set expressSession.foo to: ' + expressSession.foo

expressSession.save (error) ->
    console.log 'error: ' + error
    setTimeout (()->
        sStore.get sId, (error, session) ->
            console.log 'foo = ' + session.foo
        ), 1000

And got the same output :(

==== EDIT ====

Nevermind, save() works. sessionId should be sessionID... /facepalm.

As @robertj said, you probably won't see the object saved unless you tell it to save.

But more importantly, unless you're specifically intending to test the session object itself (ie connect's middleware for sessions) then there's no point to what you're doing.

It's hard to say without more context, but I expect that your purpose here is making sure that some route handler or middleware puts something into session, yes? If so, just test it in isolation. e.g.

var should = require('should');

var req = { session : {}, /*any other bits of req you expect your handler to need */};
var res = { /* whatever functions your handler needs off the response */ };

yourHandler(req, res);
req.session.foo.should.be.ok; // not null; alternatively test equality or whatever

That's for a 'unit test'. If you're doing an integration test (where you want to see things work together, e.g db and view and such), then you still shouldn't need to check session, you should check the effects of it having been