Test acceptance of invite

This commit is contained in:
Shane Kilkelly 2016-07-29 11:04:07 +01:00
parent 563247044b
commit f33d01f375
2 changed files with 42 additions and 11 deletions

View file

@ -6,17 +6,32 @@ settings = require "settings-sharelatex"
CollaboratorsEmailHandler = require "../../../app/js/Features/Collaborators/CollaboratorsEmailHandler"
_createInvite = (projectId, sendingUser, email, callback=(err, invite)->) ->
createInvite = (projectId, sendingUser, email, callback=(err, invite)->) ->
sendingUser.getCsrfToken (err) ->
return callback(err) if err
sendingUser.request.post {
url: "/project/#{projectId}/invite",
json:
email: email
privileges: 'readAndWrite'
}, (err, response, body) ->
return callback(err) if err
callback(err, body.invite)
followInviteLink = (user, link, callback=(err, response, body)->) ->
user.request.get {
uri: link
baseUrl: null
}, callback
acceptInvite = (user, invite, callback=(err, response, body)->) ->
user.request.post {
uri: "/project/#{invite.projectId}/invite/#{invite._id}/accept"
json:
token: invite.token
}, callback
describe "ProjectInviteTests", ->
before (done) ->
@timeout(20000)
@ -60,26 +75,35 @@ describe "ProjectInviteTests", ->
beforeEach (done) ->
@invite = null
@link = null
_createInvite @projectId, @sendingUser, @email, (err, invite) =>
createInvite @projectId, @sendingUser, @email, (err, invite) =>
@invite = invite
@link = CollaboratorsEmailHandler._buildInviteUrl(@fakeProject, @invite)
done()
it 'should render the invite page', (done) ->
it 'should allow the user to accept the invite and access the project', (done) ->
Async.series(
[
# go to the invite page
(cb) =>
@user.request.get {
uri: @link
baseUrl: null
}, (err, response, body) =>
followInviteLink @user, @link, (err, response, body) =>
expect(err).to.be.oneOf [null, undefined]
expect(response.statusCode).to.equal 200
expect(body).to.match new RegExp("<title>Project Invite - .*</title>")
cb()
], (err, result) =>
if err
throw err
done()
# accept the invite
(cb) =>
acceptInvite @user, @invite, (err, response, body) =>
expect(err).to.be.oneOf [null, undefined]
expect(response.statusCode).to.equal 302
expect(response.headers.location).to.equal "/project/#{@invite.projectId}"
cb()
# access the project page
(cb) =>
@user.openProject @invite.projectId, (err) =>
expect(err).to.be.oneOf [null, undefined]
cb()
], done
)

View file

@ -69,6 +69,13 @@ class User
return callback(error) if error?
callback(null)
openProject: (project_id, callback=(error)) ->
@request.get {
url: "/project/#{project_id}"
}, (error, response, body) ->
return callback(error) if error? or response.statusCode != 200
callback(null)
addUserToProject: (project_id, email, privileges, callback = (error, user) ->) ->
@request.post {
url: "/project/#{project_id}/users",