|
@@ -107,6 +107,20 @@ describe('UserUpdater', function () {
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ this.Modules = {
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ hooks: {
|
|
|
|
|
+ fire: sinon.stub().resolves([]),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.UserSessionsManager = {
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ removeSessionsFromRedis: sinon.stub().resolves(),
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
this.UserUpdater = SandboxedModule.require(MODULE_PATH, {
|
|
this.UserUpdater = SandboxedModule.require(MODULE_PATH, {
|
|
|
requires: {
|
|
requires: {
|
|
|
'../Helpers/Mongo': { normalizeQuery },
|
|
'../Helpers/Mongo': { normalizeQuery },
|
|
@@ -124,6 +138,8 @@ describe('UserUpdater', function () {
|
|
|
'../../Errors/Errors': Errors,
|
|
'../../Errors/Errors': Errors,
|
|
|
'../Subscription/SubscriptionLocator': this.SubscriptionLocator,
|
|
'../Subscription/SubscriptionLocator': this.SubscriptionLocator,
|
|
|
'../Notifications/NotificationsBuilder': this.NotificationsBuilder,
|
|
'../Notifications/NotificationsBuilder': this.NotificationsBuilder,
|
|
|
|
|
+ '../../infrastructure/Modules': this.Modules,
|
|
|
|
|
+ './UserSessionsManager': this.UserSessionsManager,
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -1054,4 +1070,57 @@ describe('UserUpdater', function () {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ describe('suspendUser', function () {
|
|
|
|
|
+ beforeEach(function () {
|
|
|
|
|
+ this.auditLog = {
|
|
|
|
|
+ initiatorId: 'abc123',
|
|
|
|
|
+ ip: '0.0.0.0',
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should suspend the user', async function () {
|
|
|
|
|
+ await this.UserUpdater.promises.suspendUser(this.user._id, this.auditLog)
|
|
|
|
|
+ expect(this.db.users.updateOne).to.have.been.calledWith(
|
|
|
|
|
+ { _id: this.user._id, suspended: { $ne: true } },
|
|
|
|
|
+ { $set: { suspended: true } }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should remove sessions from redis', async function () {
|
|
|
|
|
+ await this.UserUpdater.promises.suspendUser(this.user._id, this.auditLog)
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.UserSessionsManager.promises.removeSessionsFromRedis
|
|
|
|
|
+ ).to.have.been.calledWith({ _id: this.user._id })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should log the suspension to the audit log', async function () {
|
|
|
|
|
+ await this.UserUpdater.promises.suspendUser(this.user._id, this.auditLog)
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.UserAuditLogHandler.promises.addEntry
|
|
|
|
|
+ ).to.have.been.calledWith(
|
|
|
|
|
+ this.user._id,
|
|
|
|
|
+ 'account-suspension',
|
|
|
|
|
+ this.auditLog.initiatorId,
|
|
|
|
|
+ this.auditLog.ip,
|
|
|
|
|
+ {}
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should fire the removeDropbox hook', async function () {
|
|
|
|
|
+ await this.UserUpdater.promises.suspendUser(this.user._id, this.auditLog)
|
|
|
|
|
+ expect(this.Modules.promises.hooks.fire).to.have.been.calledWith(
|
|
|
|
|
+ 'removeDropbox',
|
|
|
|
|
+ this.user._id,
|
|
|
|
|
+ 'account-suspension'
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should handle not finding a record to update', async function () {
|
|
|
|
|
+ this.db.users.updateOne.resolves({ matchedCount: 0 })
|
|
|
|
|
+ await expect(
|
|
|
|
|
+ this.UserUpdater.promises.suspendUser(this.user._id, this.auditLog)
|
|
|
|
|
+ ).to.be.rejectedWith(Errors.NotFoundError)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|