overleaf/services/web/test/unit/coffee/UserMembership/UserMembershipsHandlerTests.coffee
Timothée Alby 6232854ff7 Remove User Memberships on Deletion (#1688)
Remove User Memberships on Deletion

GitOrigin-RevId: d6e6a4cc01e31288f660c2fd36a0cee174ee5dd1
2019-04-23 14:34:40 +00:00

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()