 							expectInviteRedirectToRegister @user, badLink, (err, redirectUrl) =>
 								@_redir = redirectUrl
 								cb()
-						(cb) =>
-							expectRegistrationRedirectToInvite @user, "some_email@example.com", @_redir, badLink, cb
-						(cb) =>
-							expectInvalidInvitePage @user, badLink, cb
-						(cb) =>
-							expectNoProjectAccess @user, @invite.projectId, cb
-					], done
+						(cb) => expectRegistrationRedirectToInvite @user, "some_email@example.com", @_redir, badLink, cb
+						(cb) => expectInvalidInvitePage @user, badLink, cb
+						(cb) => expectNoProjectAccess @user, @invite.projectId, cb
+					], done
+
+			describe 'login workflow with valid token', ->
+
+				before (done)->
+					@user.logout done
+
+				it 'should redirect to the register page', (done) ->
+					Async.series [
+						(cb) => expectInviteRedirectToRegister(@user, @link, cb)
+					], done
+
+				it 'should allow the user to login to view the invite', (done) ->
+					Async.series [
+						(cb) =>
+							expectInviteRedirectToRegister @user, @link, (err, redirectUrl, loginUrl) =>
+								@_redir = redirectUrl
+								@_loginLink = loginUrl
+								cb()
+						(cb) =>
+							expectLoginPage @user, @_loginLink, (err, redirectUrl) =>
+								expect(@_redir).to.equal redirectUrl
+								cb()
+						(cb) => expectLoginRedirectToInvite @user, @_redir, @link, cb
+						(cb) => expectInvitePage @user, @link, cb
+						(cb) => expectNoProjectAccess @user, @invite.projectId, cb
+					], done
+
+
+				it 'should allow user to accept the invite if the user registers a new account', (done) ->
+					Async.series [
+						(cb) => expectInvitePage @user, @link, cb
+						(cb) => expectAcceptInviteAndRedirect @user, @invite, cb
+						(cb) => expectProjectAccess @user, @invite.projectId, cb
+					], done

			expect(redirectUrl).to.not.be.oneOf [null, undefined]
			expect(loginUrl).to.not.be.oneOf [null, undefined]
			callback(null, redirectUrl, loginUrl)

expectRegistrationRedirectToInvite = (user, email, redir, link, callback=(err, result)->) ->
	tryRegisterUser user, email, redir, (err, response, body) ->

				redir: redir
		}, callback

tryFollowLoginLink = (user, loginLink, callback=(err, response, body)->) ->
	user.getCsrfToken (error) =>
		return callback(error) if error?
		user.request.get loginLink, callback

tryLoginUser = (user, redir, callback=(err, response, body)->) ->
	user.getCsrfToken (error) =>
		return callback(error) if error?
		user.request.post {
			url: "/login"
			json:
				email: user.email
				password: user.password
				redir: redir
		}, callback


# Expectations
expectProjectAccess = (user, projectId, callback=(err,result)->) ->
