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"
|
|
|
|
|
|
|
|
|
|
|
|
_createInvite = (projectId, user, email, callback=(err, invite)->) ->
|
|
|
|
user.getCsrfToken (err) ->
|
|
|
|
return callback(err) if err
|
|
|
|
user.request.post {
|
|
|
|
url: "/project/#{projectId}/invite",
|
|
|
|
json:
|
|
|
|
email: email
|
|
|
|
}, (err, response, body) ->
|
|
|
|
return callback(err) if err
|
|
|
|
callback(err, body.invite)
|
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-28 11:00:18 -04:00
|
|
|
@email = 'user@example.com'
|
|
|
|
@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()
|
|
|
|
|
|
|
|
describe 'user is already a member of the project', ->
|
|
|
|
|
2016-07-28 11:00:18 -04:00
|
|
|
beforeEach (done) ->
|
|
|
|
@invite = null
|
|
|
|
@link = null
|
|
|
|
_createInvite @projectId, @sendingUser, @email, (err, invite) =>
|
|
|
|
@invite = invite
|
|
|
|
@link = CollaboratorsEmailHandler._buildInviteUrl(@fakeProject, @invite)
|
|
|
|
done()
|
2016-07-28 09:53:22 -04:00
|
|
|
|
|
|
|
it 'should redirect to the project page', (done) ->
|
|
|
|
Async.series(
|
|
|
|
[
|
|
|
|
(cb) =>
|
2016-07-28 11:00:18 -04:00
|
|
|
console.log ">> yes"
|
2016-07-28 09:53:22 -04:00
|
|
|
cb()
|
|
|
|
|
|
|
|
], (err, result) =>
|
|
|
|
if err
|
|
|
|
throw err
|
|
|
|
done()
|
|
|
|
)
|