mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Test acceptance of invite
This commit is contained in:
parent
563247044b
commit
f33d01f375
2 changed files with 42 additions and 11 deletions
|
@ -6,17 +6,32 @@ settings = require "settings-sharelatex"
|
||||||
CollaboratorsEmailHandler = require "../../../app/js/Features/Collaborators/CollaboratorsEmailHandler"
|
CollaboratorsEmailHandler = require "../../../app/js/Features/Collaborators/CollaboratorsEmailHandler"
|
||||||
|
|
||||||
|
|
||||||
_createInvite = (projectId, sendingUser, email, callback=(err, invite)->) ->
|
createInvite = (projectId, sendingUser, email, callback=(err, invite)->) ->
|
||||||
sendingUser.getCsrfToken (err) ->
|
sendingUser.getCsrfToken (err) ->
|
||||||
return callback(err) if err
|
return callback(err) if err
|
||||||
sendingUser.request.post {
|
sendingUser.request.post {
|
||||||
url: "/project/#{projectId}/invite",
|
url: "/project/#{projectId}/invite",
|
||||||
json:
|
json:
|
||||||
email: email
|
email: email
|
||||||
|
privileges: 'readAndWrite'
|
||||||
}, (err, response, body) ->
|
}, (err, response, body) ->
|
||||||
return callback(err) if err
|
return callback(err) if err
|
||||||
callback(err, body.invite)
|
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", ->
|
describe "ProjectInviteTests", ->
|
||||||
before (done) ->
|
before (done) ->
|
||||||
@timeout(20000)
|
@timeout(20000)
|
||||||
|
@ -60,26 +75,35 @@ describe "ProjectInviteTests", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@invite = null
|
@invite = null
|
||||||
@link = null
|
@link = null
|
||||||
_createInvite @projectId, @sendingUser, @email, (err, invite) =>
|
createInvite @projectId, @sendingUser, @email, (err, invite) =>
|
||||||
@invite = invite
|
@invite = invite
|
||||||
@link = CollaboratorsEmailHandler._buildInviteUrl(@fakeProject, @invite)
|
@link = CollaboratorsEmailHandler._buildInviteUrl(@fakeProject, @invite)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should render the invite page', (done) ->
|
it 'should allow the user to accept the invite and access the project', (done) ->
|
||||||
Async.series(
|
Async.series(
|
||||||
[
|
[
|
||||||
|
# go to the invite page
|
||||||
(cb) =>
|
(cb) =>
|
||||||
@user.request.get {
|
followInviteLink @user, @link, (err, response, body) =>
|
||||||
uri: @link
|
|
||||||
baseUrl: null
|
|
||||||
}, (err, response, body) =>
|
|
||||||
expect(err).to.be.oneOf [null, undefined]
|
expect(err).to.be.oneOf [null, undefined]
|
||||||
expect(response.statusCode).to.equal 200
|
expect(response.statusCode).to.equal 200
|
||||||
expect(body).to.match new RegExp("<title>Project Invite - .*</title>")
|
expect(body).to.match new RegExp("<title>Project Invite - .*</title>")
|
||||||
cb()
|
cb()
|
||||||
|
|
||||||
], (err, result) =>
|
# accept the invite
|
||||||
if err
|
(cb) =>
|
||||||
throw err
|
acceptInvite @user, @invite, (err, response, body) =>
|
||||||
done()
|
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
|
||||||
)
|
)
|
||||||
|
|
|
@ -69,6 +69,13 @@ class User
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
callback(null)
|
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) ->) ->
|
addUserToProject: (project_id, email, privileges, callback = (error, user) ->) ->
|
||||||
@request.post {
|
@request.post {
|
||||||
url: "/project/#{project_id}/users",
|
url: "/project/#{project_id}/users",
|
||||||
|
|
Loading…
Reference in a new issue