|
|
@@ -28,6 +28,8 @@ describe "AuthenticationController", ->
|
|
|
trackSession: sinon.stub()
|
|
|
untrackSession: sinon.stub()
|
|
|
revokeAllUserSessions: sinon.stub().callsArgWith(1, null)
|
|
|
+ "../../infrastructure/GeoIpLookup": @GeoIpLookup =
|
|
|
+ getDetails: sinon.stub().callsArgWith(1, null, {})
|
|
|
@user =
|
|
|
_id: ObjectId()
|
|
|
email: @email = "USER@example.com"
|
|
|
@@ -172,6 +174,8 @@ describe "AuthenticationController", ->
|
|
|
@req.session.save = sinon.stub().callsArgWith(0, null)
|
|
|
@req.sessionStore = {generate: sinon.stub()}
|
|
|
@UserSessionsManager.trackSession = sinon.stub()
|
|
|
+ @GeoIpLookup.getDetails = sinon.stub()
|
|
|
+ .callsArgWith(1, null, @geoDetails = {country_code: 'US'})
|
|
|
@call = (callback) =>
|
|
|
@AuthenticationController.afterLoginSessionSetup @req, @user, callback
|
|
|
|
|
|
@@ -185,14 +189,21 @@ describe "AuthenticationController", ->
|
|
|
@req.login.callCount.should.equal 1
|
|
|
done()
|
|
|
|
|
|
- it 'should call req.session.save', (done) ->
|
|
|
+ it 'should call UserSessionsManager.trackSession', (done) ->
|
|
|
@call (err) =>
|
|
|
- @req.session.save.callCount.should.equal 1
|
|
|
+ @UserSessionsManager.trackSession.callCount.should.equal 1
|
|
|
done()
|
|
|
|
|
|
- it 'should call UserSessionsManager.trackSession', (done) ->
|
|
|
+ it 'should call GeoIpLookup.getDetails', (done) ->
|
|
|
@call (err) =>
|
|
|
- @UserSessionsManager.trackSession.callCount.should.equal 1
|
|
|
+ @GeoIpLookup.getDetails.callCount.should.equal 1
|
|
|
+ @req.session.countryCode.should.exist
|
|
|
+ @req.session.countryCode.should.equal @geoDetails.country_code
|
|
|
+ done()
|
|
|
+
|
|
|
+ it 'should call req.session.save', (done) ->
|
|
|
+ @call (err) =>
|
|
|
+ @req.session.save.callCount.should.equal 1
|
|
|
done()
|
|
|
|
|
|
describe 'when req.session.save produces an error', ->
|
|
|
@@ -211,6 +222,39 @@ describe "AuthenticationController", ->
|
|
|
@UserSessionsManager.trackSession.callCount.should.equal 0
|
|
|
done()
|
|
|
|
|
|
+ describe 'when GeoIpLookup produces an error', ->
|
|
|
+ beforeEach ->
|
|
|
+ @GeoIpLookup.getDetails = sinon.stub()
|
|
|
+ .callsArgWith(1, new Error('woops'))
|
|
|
+
|
|
|
+ it 'should not produce an error', (done) ->
|
|
|
+ @call (err) =>
|
|
|
+ expect(err).to.not.exist
|
|
|
+ done()
|
|
|
+
|
|
|
+ it 'should still call req.session.save', (done) ->
|
|
|
+ @call (err) =>
|
|
|
+ @req.session.save.callCount.should.equal 1
|
|
|
+ expect(@req.session.countryCode).to.equal null
|
|
|
+ done()
|
|
|
+
|
|
|
+ describe 'when GeoIpLookup produces no data', ->
|
|
|
+ beforeEach ->
|
|
|
+ @GeoIpLookup.getDetails = sinon.stub()
|
|
|
+ .callsArgWith(1, null, undefined)
|
|
|
+
|
|
|
+ it 'should not produce an error', (done) ->
|
|
|
+ @call (err) =>
|
|
|
+ expect(err).to.not.exist
|
|
|
+ done()
|
|
|
+
|
|
|
+ it 'should still call req.session.save', (done) ->
|
|
|
+ @call (err) =>
|
|
|
+ @req.session.save.callCount.should.equal 1
|
|
|
+ expect(@req.session.countryCode).to.equal null
|
|
|
+ done()
|
|
|
+
|
|
|
+
|
|
|
describe 'getSessionUser', ->
|
|
|
|
|
|
it 'should get the user object from session', ->
|