mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Start testing acceptInvite
This commit is contained in:
parent
78a410c39d
commit
5438f39f9e
2 changed files with 82 additions and 12 deletions
|
@ -61,7 +61,7 @@ module.exports = CollaboratorsInviteHandler =
|
||||||
logger.log {err, projectId, inviteId}, "no project found"
|
logger.log {err, projectId, inviteId}, "no project found"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
# TODO: check if we need to cast the ids to ObjectId
|
# TODO: check if we need to cast the ids to ObjectId
|
||||||
ProjectInvite.findOne {_id: inviteId, projectId: projectId, token: token}, (err, invite) ->
|
ProjectInvite.findOne {_id: inviteId, projectId: projectId, token: tokenString}, (err, invite) ->
|
||||||
if err?
|
if err?
|
||||||
logger.err {err, projectId, inviteId}, "error finding invite"
|
logger.err {err, projectId, inviteId}, "error finding invite"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
@ -94,9 +94,9 @@ module.exports = CollaboratorsInviteHandler =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
# Flush to TPDS in background to add files to collaborator's Dropbox
|
# Flush to TPDS in background to add files to collaborator's Dropbox
|
||||||
ProjectEntityHandler = require("../Project/ProjectEntityHandler")
|
ProjectEntityHandler = require("../Project/ProjectEntityHandler")
|
||||||
ProjectEntityHandler.flushProjectToThirdPartyDataStore project_id, (error) ->
|
ProjectEntityHandler.flushProjectToThirdPartyDataStore project._id, (error) ->
|
||||||
if error?
|
if error?
|
||||||
logger.error {err: error, project_id, user_id}, "error flushing to TPDS after adding collaborator"
|
logger.error {err: error, project_id: project._id, user_id}, "error flushing to TPDS after adding collaborator"
|
||||||
# Remove invite
|
# Remove invite
|
||||||
ProjectInvite.remove {_id: inviteId}, (err) ->
|
ProjectInvite.remove {_id: inviteId}, (err) ->
|
||||||
if err?
|
if err?
|
||||||
|
|
|
@ -19,7 +19,11 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
save: sinon.stub()
|
save: sinon.stub()
|
||||||
@findOne: sinon.stub()
|
@findOne: sinon.stub()
|
||||||
@remove: sinon.stub()
|
@remove: sinon.stub()
|
||||||
@Project = {}
|
@Project = class Project
|
||||||
|
constructor: () ->
|
||||||
|
this
|
||||||
|
@findOne: sinon.stub()
|
||||||
|
@update: sinon.stub()
|
||||||
@Crypto = Crypto
|
@Crypto = Crypto
|
||||||
@CollaboratorsInviteHandler = SandboxedModule.require modulePath, requires:
|
@CollaboratorsInviteHandler = SandboxedModule.require modulePath, requires:
|
||||||
'settings-sharelatex': @settings = {}
|
'settings-sharelatex': @settings = {}
|
||||||
|
@ -28,15 +32,27 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
'../Contacts/ContactManager': @ContactManager = {}
|
'../Contacts/ContactManager': @ContactManager = {}
|
||||||
'../../models/Project': {Project: @Project}
|
'../../models/Project': {Project: @Project}
|
||||||
'../../models/ProjectInvite': {ProjectInvite: @ProjectInvite}
|
'../../models/ProjectInvite': {ProjectInvite: @ProjectInvite}
|
||||||
|
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
|
||||||
'crypto': @Crypto
|
'crypto': @Crypto
|
||||||
|
|
||||||
@projectId = ObjectId()
|
@projectId = ObjectId()
|
||||||
@sendingUserId = ObjectId()
|
@sendingUserId = ObjectId()
|
||||||
@email = "user@example.com"
|
@email = "user@example.com"
|
||||||
@userId = ObjectId()
|
@userId = ObjectId()
|
||||||
|
@user =
|
||||||
|
_id: @userId
|
||||||
|
email: 'someone@example.com'
|
||||||
@inviteId = ObjectId()
|
@inviteId = ObjectId()
|
||||||
@token = 'hnhteaosuhtaeosuahs'
|
@token = 'hnhteaosuhtaeosuahs'
|
||||||
@privileges = "readAndWrite"
|
@privileges = "readAndWrite"
|
||||||
|
@fakeInvite =
|
||||||
|
_id: @inviteId
|
||||||
|
email: @email
|
||||||
|
token: @token
|
||||||
|
sendingUserId: @sendingUserId
|
||||||
|
projectId: @projectId
|
||||||
|
privileges: @privileges
|
||||||
|
createdAt: new Date()
|
||||||
|
|
||||||
describe 'inviteToProject', ->
|
describe 'inviteToProject', ->
|
||||||
|
|
||||||
|
@ -130,14 +146,6 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
describe 'getInviteByToken', ->
|
describe 'getInviteByToken', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@fakeInvite =
|
|
||||||
_id: @inviteId
|
|
||||||
email: @email
|
|
||||||
token: @token
|
|
||||||
sendingUserId: @sendingUserId
|
|
||||||
projectId: @projectId
|
|
||||||
privileges: @privileges
|
|
||||||
createdAt: new Date()
|
|
||||||
@ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
@ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
||||||
@call = (callback) =>
|
@call = (callback) =>
|
||||||
@CollaboratorsInviteHandler.getInviteByToken @projectId, @token, callback
|
@CollaboratorsInviteHandler.getInviteByToken @projectId, @token, callback
|
||||||
|
@ -189,3 +197,65 @@ describe "CollaboratorsInviteHandler", ->
|
||||||
expect(invite).to.not.be.instanceof Error
|
expect(invite).to.not.be.instanceof Error
|
||||||
expect(invite).to.be.oneOf [null, undefined]
|
expect(invite).to.be.oneOf [null, undefined]
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe 'acceptInvite', ->
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
@fakeProject =
|
||||||
|
_id: @projectId
|
||||||
|
collaberator_refs: []
|
||||||
|
readOnly_refs: []
|
||||||
|
@Project.findOne.callsArgWith(1, null, @fakeProject)
|
||||||
|
@ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
||||||
|
@ContactManager.addContact = sinon.stub()
|
||||||
|
@Project.update.callsArgWith(2, null)
|
||||||
|
@ProjectEntityHandler.flushProjectToThirdPartyDataStore = sinon.stub().callsArgWith(1, null)
|
||||||
|
@ProjectInvite.remove.callsArgWith(1, null)
|
||||||
|
@call = (callback) =>
|
||||||
|
@CollaboratorsInviteHandler.acceptInvite @projectId, @inviteId, @token, @user, callback
|
||||||
|
|
||||||
|
describe 'when all goes well', ->
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
|
||||||
|
it 'should not produce an error', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
expect(err).to.not.be.instanceof Error
|
||||||
|
expect(err).to.be.oneOf [null, undefined]
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should have called Project.findOne', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
@Project.findOne.callCount.should.equal 1
|
||||||
|
@Project.findOne.calledWith({_id: @projectId}).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should have called ProjectInvite.findOne', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
@ProjectInvite.findOne.callCount.should.equal 1
|
||||||
|
@ProjectInvite.findOne.calledWith({_id: @inviteId, projectId: @projectId, token: @token}).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should have called ContactManager.addContact', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
@ContactManager.addContact.callCount.should.equal 1
|
||||||
|
@ContactManager.addContact.calledWith(@sendingUserId, @userId).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should have called Project.update, adding the user to callaberator_refs', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
@Project.update.callCount.should.equal 1
|
||||||
|
@Project.update.calledWith({_id: @projectId}, {$addToSet: {"collaberator_refs": @userId}}).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should have called ProjectEntityHandler.flushProjectToThirdPartyDataStore', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
@ProjectEntityHandler.flushProjectToThirdPartyDataStore.callCount.should.equal 1
|
||||||
|
@ProjectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(@projectId).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should have called ProjectInvite.remove', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
@ProjectInvite.remove.callCount.should.equal 1
|
||||||
|
@ProjectInvite.remove.calledWith({_id: @inviteId}).should.equal true
|
||||||
|
done()
|
||||||
|
|
Loading…
Reference in a new issue