mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-05 07:20:08 +00: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"
|
||||
return callback(err)
|
||||
# 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?
|
||||
logger.err {err, projectId, inviteId}, "error finding invite"
|
||||
return callback(err)
|
||||
|
@ -94,9 +94,9 @@ module.exports = CollaboratorsInviteHandler =
|
|||
return callback(error) if error?
|
||||
# Flush to TPDS in background to add files to collaborator's Dropbox
|
||||
ProjectEntityHandler = require("../Project/ProjectEntityHandler")
|
||||
ProjectEntityHandler.flushProjectToThirdPartyDataStore project_id, (error) ->
|
||||
ProjectEntityHandler.flushProjectToThirdPartyDataStore project._id, (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
|
||||
ProjectInvite.remove {_id: inviteId}, (err) ->
|
||||
if err?
|
||||
|
|
|
@ -19,7 +19,11 @@ describe "CollaboratorsInviteHandler", ->
|
|||
save: sinon.stub()
|
||||
@findOne: sinon.stub()
|
||||
@remove: sinon.stub()
|
||||
@Project = {}
|
||||
@Project = class Project
|
||||
constructor: () ->
|
||||
this
|
||||
@findOne: sinon.stub()
|
||||
@update: sinon.stub()
|
||||
@Crypto = Crypto
|
||||
@CollaboratorsInviteHandler = SandboxedModule.require modulePath, requires:
|
||||
'settings-sharelatex': @settings = {}
|
||||
|
@ -28,15 +32,27 @@ describe "CollaboratorsInviteHandler", ->
|
|||
'../Contacts/ContactManager': @ContactManager = {}
|
||||
'../../models/Project': {Project: @Project}
|
||||
'../../models/ProjectInvite': {ProjectInvite: @ProjectInvite}
|
||||
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
|
||||
'crypto': @Crypto
|
||||
|
||||
@projectId = ObjectId()
|
||||
@sendingUserId = ObjectId()
|
||||
@email = "user@example.com"
|
||||
@userId = ObjectId()
|
||||
@user =
|
||||
_id: @userId
|
||||
email: 'someone@example.com'
|
||||
@inviteId = ObjectId()
|
||||
@token = 'hnhteaosuhtaeosuahs'
|
||||
@privileges = "readAndWrite"
|
||||
@fakeInvite =
|
||||
_id: @inviteId
|
||||
email: @email
|
||||
token: @token
|
||||
sendingUserId: @sendingUserId
|
||||
projectId: @projectId
|
||||
privileges: @privileges
|
||||
createdAt: new Date()
|
||||
|
||||
describe 'inviteToProject', ->
|
||||
|
||||
|
@ -130,14 +146,6 @@ describe "CollaboratorsInviteHandler", ->
|
|||
describe 'getInviteByToken', ->
|
||||
|
||||
beforeEach ->
|
||||
@fakeInvite =
|
||||
_id: @inviteId
|
||||
email: @email
|
||||
token: @token
|
||||
sendingUserId: @sendingUserId
|
||||
projectId: @projectId
|
||||
privileges: @privileges
|
||||
createdAt: new Date()
|
||||
@ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
||||
@call = (callback) =>
|
||||
@CollaboratorsInviteHandler.getInviteByToken @projectId, @token, callback
|
||||
|
@ -189,3 +197,65 @@ describe "CollaboratorsInviteHandler", ->
|
|||
expect(invite).to.not.be.instanceof Error
|
||||
expect(invite).to.be.oneOf [null, undefined]
|
||||
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