|
|
@@ -69,6 +69,7 @@ describe('UserDeleter', function () {
|
|
|
ctx.SubscriptionLocator = {
|
|
|
promises: {
|
|
|
getUsersSubscription: sinon.stub().resolves(),
|
|
|
+ getUniqueManagedSubscriptionMemberOf: sinon.stub().resolves(),
|
|
|
},
|
|
|
}
|
|
|
|
|
|
@@ -427,7 +428,8 @@ describe('UserDeleter', function () {
|
|
|
ctx.userId,
|
|
|
'delete-account',
|
|
|
ctx.userId,
|
|
|
- ctx.ipAddress
|
|
|
+ ctx.ipAddress,
|
|
|
+ {}
|
|
|
)
|
|
|
})
|
|
|
})
|
|
|
@@ -508,7 +510,8 @@ describe('UserDeleter', function () {
|
|
|
ctx.userId,
|
|
|
'delete-account',
|
|
|
ctx.deleterId,
|
|
|
- ctx.ipAddress
|
|
|
+ ctx.ipAddress,
|
|
|
+ {}
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -524,6 +527,81 @@ describe('UserDeleter', function () {
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ describe('when the user is part of a managed subscription', function () {
|
|
|
+ beforeEach(function (ctx) {
|
|
|
+ ctx.managedSubscriptionId = new ObjectId()
|
|
|
+ ctx.SubscriptionLocator.promises.getUniqueManagedSubscriptionMemberOf.resolves(
|
|
|
+ {
|
|
|
+ _id: ctx.managedSubscriptionId,
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ ctx.DeletedUserMock.expects('updateOne')
|
|
|
+ .withArgs(
|
|
|
+ { 'deleterData.deletedUserId': ctx.userId },
|
|
|
+ ctx.deletedUser,
|
|
|
+ { upsert: true }
|
|
|
+ )
|
|
|
+ .chain('exec')
|
|
|
+ .resolves()
|
|
|
+ ctx.UserMock.expects('deleteOne')
|
|
|
+ .withArgs({ _id: ctx.userId })
|
|
|
+ .chain('exec')
|
|
|
+ .resolves()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should include managedSubscriptionId in audit log', async function (ctx) {
|
|
|
+ await ctx.UserDeleter.promises.deleteUser(ctx.userId, {
|
|
|
+ ipAddress: ctx.ipAddress,
|
|
|
+ })
|
|
|
+ expect(
|
|
|
+ ctx.UserAuditLogHandler.promises.addEntry
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ ctx.userId,
|
|
|
+ 'delete-account',
|
|
|
+ ctx.userId,
|
|
|
+ ctx.ipAddress,
|
|
|
+ {}
|
|
|
+ )
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('when checking managed subscription fails', function () {
|
|
|
+ beforeEach(function (ctx) {
|
|
|
+ ctx.SubscriptionLocator.promises.getUniqueManagedSubscriptionMemberOf.rejects(
|
|
|
+ new Error('subscription lookup failed')
|
|
|
+ )
|
|
|
+
|
|
|
+ ctx.DeletedUserMock.expects('updateOne')
|
|
|
+ .withArgs(
|
|
|
+ { 'deleterData.deletedUserId': ctx.userId },
|
|
|
+ ctx.deletedUser,
|
|
|
+ { upsert: true }
|
|
|
+ )
|
|
|
+ .chain('exec')
|
|
|
+ .resolves()
|
|
|
+ ctx.UserMock.expects('deleteOne')
|
|
|
+ .withArgs({ _id: ctx.userId })
|
|
|
+ .chain('exec')
|
|
|
+ .resolves()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should continue with deletion and not include managedSubscriptionId', async function (ctx) {
|
|
|
+ await ctx.UserDeleter.promises.deleteUser(ctx.userId, {
|
|
|
+ ipAddress: ctx.ipAddress,
|
|
|
+ })
|
|
|
+ expect(
|
|
|
+ ctx.UserAuditLogHandler.promises.addEntry
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ ctx.userId,
|
|
|
+ 'delete-account',
|
|
|
+ ctx.userId,
|
|
|
+ ctx.ipAddress,
|
|
|
+ {}
|
|
|
+ )
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('when the user cannot be deleted because they are a subscription admin', function () {
|