get invite and link for test

This commit is contained in:
Shane Kilkelly 2016-07-28 16:00:18 +01:00
parent 9c6195fbec
commit 23c94c9599
2 changed files with 46 additions and 10 deletions

View file

@ -3,6 +3,19 @@ Async = require("async")
User = require "./helpers/User"
request = require "./helpers/request"
settings = require "settings-sharelatex"
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)
describe "ProjectInviteTests", ->
before (done) ->
@ -10,19 +23,30 @@ describe "ProjectInviteTests", ->
@sendingUser = new User()
@user = new User()
@site_admin = new User({email: "admin@example.com"})
@email = 'user@example.com'
@projectName = 'sharing test'
@projectId = null
@fakeProject = null
Async.series [
(cb) => @user.login cb
(cb) => @user.logout cb
(cb) => @sendingUser.login cb
(cb) => @sendingUser.createProject('sharing test', (err, projectId) =>
(cb) => @sendingUser.createProject(@projectName, (err, projectId, project) =>
throw err if err
@projectId = projectId
@fakeProject = {
_id: projectId,
name: @projectName,
owner_ref: @sendingUser
}
cb()
)
(cb) => @sendingUser.logout cb
], done
after (done) ->
Async.series [
(cb) => @sendingUser.deleteProject(@projectId, cb)
], done
describe "user is logged in", ->
beforeEach (done) ->
@ -33,16 +57,21 @@ describe "ProjectInviteTests", ->
describe 'user is already a member of the project', ->
beforeEach ->
beforeEach (done) ->
@invite = null
@link = null
_createInvite @projectId, @sendingUser, @email, (err, invite) =>
@invite = invite
@link = CollaboratorsEmailHandler._buildInviteUrl(@fakeProject, @invite)
done()
it 'should redirect to the project page', (done) ->
Async.series(
[
(cb) =>
console.log ">> yes"
cb()
], (err, result) =>
if err
throw err

View file

@ -13,7 +13,7 @@ class User
@request = request.defaults({
jar: @jar
})
login: (callback = (error) ->) ->
@getCsrfToken (error) =>
return callback(error) if error?
@ -58,8 +58,15 @@ class User
return callback(error) if error?
if !body?.project_id?
console.error "SOMETHING WENT WRONG CREATING PROJECT", response.statusCode, response.headers["location"], body
callback(null, body.project_id)
callback(null, body.project_id, body)
deleteProject: (project_id, callback=(error)) ->
@request.delete {
url: "/project/#{project_id}"
}, (error, response, body) ->
return callback(error) if error?
callback(null)
addUserToProject: (project_id, email, privileges, callback = (error, user) ->) ->
@request.post {
url: "/project/#{project_id}/users",
@ -67,7 +74,7 @@ class User
}, (error, response, body) ->
return callback(error) if error?
callback(null, body.user)
makePublic: (project_id, level, callback = (error) ->) ->
@request.post {
url: "/project/#{project_id}/settings/admin",