2016-07-28 09:53:22 -04:00
|
|
|
expect = require("chai").expect
|
|
|
|
Async = require("async")
|
|
|
|
User = require "./helpers/User"
|
|
|
|
request = require "./helpers/request"
|
|
|
|
settings = require "settings-sharelatex"
|
2016-07-28 11:00:18 -04:00
|
|
|
CollaboratorsEmailHandler = require "../../../app/js/Features/Collaborators/CollaboratorsEmailHandler"
|
|
|
|
|
|
|
|
|
2016-07-29 06:04:07 -04:00
|
|
|
createInvite = (projectId, sendingUser, email, callback=(err, invite)->) ->
|
2016-07-29 04:52:55 -04:00
|
|
|
sendingUser.getCsrfToken (err) ->
|
2016-07-28 11:00:18 -04:00
|
|
|
return callback(err) if err
|
2016-07-29 04:52:55 -04:00
|
|
|
sendingUser.request.post {
|
2016-07-28 11:00:18 -04:00
|
|
|
url: "/project/#{projectId}/invite",
|
|
|
|
json:
|
|
|
|
email: email
|
2016-07-29 06:04:07 -04:00
|
|
|
privileges: 'readAndWrite'
|
2016-07-28 11:00:18 -04:00
|
|
|
}, (err, response, body) ->
|
|
|
|
return callback(err) if err
|
|
|
|
callback(err, body.invite)
|
2016-07-28 09:53:22 -04:00
|
|
|
|
2016-07-29 06:04:07 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2016-07-28 09:53:22 -04:00
|
|
|
describe "ProjectInviteTests", ->
|
|
|
|
before (done) ->
|
|
|
|
@timeout(20000)
|
|
|
|
@sendingUser = new User()
|
|
|
|
@user = new User()
|
|
|
|
@site_admin = new User({email: "admin@example.com"})
|
2016-07-29 04:52:55 -04:00
|
|
|
@email = 'smoketestuser@example.com'
|
2016-07-28 11:00:18 -04:00
|
|
|
@projectName = 'sharing test'
|
2016-07-28 09:53:22 -04:00
|
|
|
@projectId = null
|
2016-07-28 11:00:18 -04:00
|
|
|
@fakeProject = null
|
2016-07-28 09:53:22 -04:00
|
|
|
Async.series [
|
|
|
|
(cb) => @user.login cb
|
|
|
|
(cb) => @sendingUser.login cb
|
2016-07-28 11:00:18 -04:00
|
|
|
(cb) => @sendingUser.createProject(@projectName, (err, projectId, project) =>
|
2016-07-28 09:53:22 -04:00
|
|
|
throw err if err
|
|
|
|
@projectId = projectId
|
2016-07-28 11:00:18 -04:00
|
|
|
@fakeProject = {
|
|
|
|
_id: projectId,
|
|
|
|
name: @projectName,
|
|
|
|
owner_ref: @sendingUser
|
|
|
|
}
|
2016-07-28 09:53:22 -04:00
|
|
|
cb()
|
|
|
|
)
|
|
|
|
], done
|
|
|
|
|
2016-07-28 11:00:18 -04:00
|
|
|
after (done) ->
|
|
|
|
Async.series [
|
|
|
|
(cb) => @sendingUser.deleteProject(@projectId, cb)
|
|
|
|
], done
|
|
|
|
|
2016-07-28 09:53:22 -04:00
|
|
|
describe "user is logged in", ->
|
|
|
|
|
|
|
|
beforeEach (done) ->
|
|
|
|
@user.login (err) =>
|
|
|
|
if err
|
|
|
|
throw err
|
|
|
|
done()
|
|
|
|
|
2016-07-29 04:52:55 -04:00
|
|
|
describe 'user is not a member of the project', ->
|
2016-07-28 09:53:22 -04:00
|
|
|
|
2016-07-28 11:00:18 -04:00
|
|
|
beforeEach (done) ->
|
|
|
|
@invite = null
|
|
|
|
@link = null
|
2016-07-29 06:04:07 -04:00
|
|
|
createInvite @projectId, @sendingUser, @email, (err, invite) =>
|
2016-07-28 11:00:18 -04:00
|
|
|
@invite = invite
|
|
|
|
@link = CollaboratorsEmailHandler._buildInviteUrl(@fakeProject, @invite)
|
|
|
|
done()
|
2016-07-28 09:53:22 -04:00
|
|
|
|
2016-07-29 06:04:07 -04:00
|
|
|
it 'should allow the user to accept the invite and access the project', (done) ->
|
2016-07-28 09:53:22 -04:00
|
|
|
Async.series(
|
|
|
|
[
|
2016-07-29 06:04:07 -04:00
|
|
|
# go to the invite page
|
2016-07-28 09:53:22 -04:00
|
|
|
(cb) =>
|
2016-07-29 06:04:07 -04:00
|
|
|
followInviteLink @user, @link, (err, response, body) =>
|
2016-07-29 04:52:55 -04:00
|
|
|
expect(err).to.be.oneOf [null, undefined]
|
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
|
expect(body).to.match new RegExp("<title>Project Invite - .*</title>")
|
|
|
|
cb()
|
2016-07-28 09:53:22 -04:00
|
|
|
|
2016-07-29 06:04:07 -04:00
|
|
|
# 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
|
2016-07-28 09:53:22 -04:00
|
|
|
)
|