mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
6232854ff7
Remove User Memberships on Deletion GitOrigin-RevId: d6e6a4cc01e31288f660c2fd36a0cee174ee5dd1
40 lines
1.2 KiB
CoffeeScript
40 lines
1.2 KiB
CoffeeScript
sinon = require('sinon')
|
|
assertCalledWith = sinon.assert.calledWith
|
|
ObjectId = require("../../../../app/js/infrastructure/mongojs").ObjectId
|
|
modulePath = "../../../../app/js/Features/UserMembership/UserMembershipsHandler"
|
|
SandboxedModule = require("sandboxed-module")
|
|
|
|
describe 'UserMembershipsHandler', ->
|
|
beforeEach ->
|
|
@user = _id: ObjectId()
|
|
|
|
@Institution =
|
|
updateMany: sinon.stub().yields(null)
|
|
@Subscription =
|
|
updateMany: sinon.stub().yields(null)
|
|
@Publisher =
|
|
updateMany: sinon.stub().yields(null)
|
|
@UserMembershipsHandler = SandboxedModule.require modulePath, requires:
|
|
'../../models/Institution': Institution: @Institution
|
|
'../../models/Subscription': Subscription: @Subscription
|
|
'../../models/Publisher': Publisher: @Publisher
|
|
|
|
describe 'remove user', ->
|
|
it 'remove user from all entities', (done) ->
|
|
@UserMembershipsHandler.removeUserFromAllEntities @user._id, (error) =>
|
|
assertCalledWith(
|
|
@Institution.updateMany,
|
|
{},
|
|
{ "$pull": { managerIds: @user._id } }
|
|
)
|
|
assertCalledWith(
|
|
@Subscription.updateMany,
|
|
{},
|
|
{ "$pull": { manager_ids: @user._id } }
|
|
)
|
|
assertCalledWith(
|
|
@Publisher.updateMany,
|
|
{},
|
|
{ "$pull": { managerIds: @user._id } }
|
|
)
|
|
done()
|