Merge pull request #4035 from overleaf/jel-reconfirmation-dropbox-notification
Notification for Dropbox unlinked due to reconfirmation lapse GitOrigin-RevId: 03d2bed922e1d3dd993f9227b8e7675af42eda4b
This commit is contained in:
@@ -1,108 +0,0 @@
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const path = require('path')
|
||||
const sinon = require('sinon')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const { expect } = require('chai')
|
||||
const modulePath = path.join(
|
||||
__dirname,
|
||||
'../../../../app/src/Features/Institutions/InstitutionsReconfirmationHandler'
|
||||
)
|
||||
|
||||
describe('InstitutionsReconfirmationHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.InstitutionsReconfirmationHandler = SandboxedModule.require(
|
||||
modulePath,
|
||||
{
|
||||
requires: {
|
||||
'../../infrastructure/mongodb': (this.mongodb = {
|
||||
ObjectId,
|
||||
waitForDb: sinon.stub().resolves(),
|
||||
}),
|
||||
'../Subscription/FeaturesUpdater': (this.FeaturesUpdater = {
|
||||
refreshFeatures: sinon.stub(),
|
||||
}),
|
||||
'./InstitutionsAPI': (this.InstitutionsAPI = {
|
||||
promises: {
|
||||
getUsersNeedingReconfirmationsLapsedProcessed: sinon.stub(),
|
||||
sendUsersWithReconfirmationsLapsedProcessed: sinon.stub(),
|
||||
},
|
||||
}),
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
describe('userId list', function () {
|
||||
it('should throw an error if IDs not an array', async function () {
|
||||
let error
|
||||
try {
|
||||
await this.InstitutionsReconfirmationHandler.processLapsed()
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
expect(error).to.exist
|
||||
expect(error.message).to.equal('users is not an array')
|
||||
})
|
||||
it('should throw an error if IDs not valid ObjectIds', async function () {
|
||||
this.InstitutionsAPI.promises.getUsersNeedingReconfirmationsLapsedProcessed.resolves(
|
||||
{
|
||||
data: { users: ['not an objectid'] },
|
||||
}
|
||||
)
|
||||
let error
|
||||
try {
|
||||
await this.InstitutionsReconfirmationHandler.processLapsed()
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
expect(error).to.exist
|
||||
expect(error.message).to.equal('user ID not valid')
|
||||
})
|
||||
})
|
||||
|
||||
it('should log users that have refreshFeatures errors', async function () {
|
||||
const anError = new Error('oops')
|
||||
const aUserId = '5efb8b6e9b647b0027e4c0b0'
|
||||
this.FeaturesUpdater.refreshFeatures.yields(anError)
|
||||
this.InstitutionsAPI.promises.getUsersNeedingReconfirmationsLapsedProcessed.resolves(
|
||||
{
|
||||
data: { users: [aUserId] },
|
||||
}
|
||||
)
|
||||
this.InstitutionsAPI.promises.sendUsersWithReconfirmationsLapsedProcessed.resolves()
|
||||
let error, result
|
||||
try {
|
||||
result = await this.InstitutionsReconfirmationHandler.processLapsed()
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
expect(error).to.not.exist
|
||||
expect(result.failedToRefresh.length).to.equal(1)
|
||||
expect(result.failedToRefresh[0]).to.equal(aUserId)
|
||||
expect(result.refreshedUsers.length).to.equal(0)
|
||||
})
|
||||
|
||||
it('should log but not return errors from sendUsersWithReconfirmationsLapsedProcessed', async function () {
|
||||
const anError = new Error('oops')
|
||||
const aUserId = '5efb8b6e9b647b0027e4c0b0'
|
||||
this.FeaturesUpdater.refreshFeatures.yields()
|
||||
this.InstitutionsAPI.promises.getUsersNeedingReconfirmationsLapsedProcessed.resolves(
|
||||
{
|
||||
data: { users: [aUserId] },
|
||||
}
|
||||
)
|
||||
this.InstitutionsAPI.promises.sendUsersWithReconfirmationsLapsedProcessed.rejects(
|
||||
anError
|
||||
)
|
||||
let error, result
|
||||
try {
|
||||
result = await this.InstitutionsReconfirmationHandler.processLapsed()
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
expect(error).to.not.exist
|
||||
expect(result.refreshedUsers.length).to.equal(1)
|
||||
expect(result.refreshedUsers[0]).to.equal(aUserId)
|
||||
expect(result.failedToRefresh.length).to.equal(0)
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,5 @@
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const modulePath = require('path').join(
|
||||
__dirname,
|
||||
@@ -8,20 +9,55 @@ const modulePath = require('path').join(
|
||||
describe('NotificationsBuilder', function () {
|
||||
const userId = '123nd3ijdks'
|
||||
|
||||
describe('ipMatcherAffiliation', function () {
|
||||
beforeEach(function () {
|
||||
this.handler = { createNotification: sinon.stub().callsArgWith(6) }
|
||||
this.settings = { apis: { v1: { url: 'v1.url', user: '', pass: '' } } }
|
||||
this.request = sinon.stub()
|
||||
this.controller = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./NotificationsHandler': this.handler,
|
||||
'settings-sharelatex': this.settings,
|
||||
request: this.request,
|
||||
},
|
||||
beforeEach(function () {
|
||||
this.handler = { createNotification: sinon.stub().callsArgWith(6) }
|
||||
this.settings = { apis: { v1: { url: 'v1.url', user: '', pass: '' } } }
|
||||
this.request = sinon.stub()
|
||||
this.controller = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./NotificationsHandler': this.handler,
|
||||
'settings-sharelatex': this.settings,
|
||||
request: this.request,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe('dropboxUnlinkedDueToLapsedReconfirmation', function (done) {
|
||||
it('should create the notification', function (done) {
|
||||
this.controller
|
||||
.dropboxUnlinkedDueToLapsedReconfirmation(userId)
|
||||
.create(error => {
|
||||
expect(error).to.not.exist
|
||||
expect(this.handler.createNotification).to.have.been.calledWith(
|
||||
userId,
|
||||
'drobox-unlinked-due-to-lapsed-reconfirmation',
|
||||
'notification_dropbox_unlinked_due_to_lapsed_reconfirmation',
|
||||
{},
|
||||
null,
|
||||
true
|
||||
)
|
||||
done()
|
||||
})
|
||||
})
|
||||
describe('NotificationsHandler error', function () {
|
||||
let anError
|
||||
beforeEach(function () {
|
||||
anError = new Error('oops')
|
||||
this.handler.createNotification.yields(anError)
|
||||
})
|
||||
it('should return errors from NotificationsHandler', function (done) {
|
||||
this.controller
|
||||
.dropboxUnlinkedDueToLapsedReconfirmation(userId)
|
||||
.create(error => {
|
||||
expect(error).to.exist
|
||||
expect(error).to.deep.equal(anError)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('ipMatcherAffiliation', function () {
|
||||
describe('with portal and with SSO', function () {
|
||||
beforeEach(function () {
|
||||
this.body = {
|
||||
|
||||
@@ -170,7 +170,7 @@ describe('FeaturesUpdater', function () {
|
||||
})
|
||||
it('should fire module hook to unlink dropbox', function () {
|
||||
this.Modules.hooks.fire
|
||||
.calledWith('removeDropbox', this.user._id)
|
||||
.calledWith('removeDropbox', this.user._id, 'test')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -376,7 +376,8 @@ function expectDropboxUnlinked() {
|
||||
it('unlinks Dropbox', function () {
|
||||
expect(this.Modules.hooks.fire).to.have.been.calledWith(
|
||||
'removeDropbox',
|
||||
this.userId
|
||||
this.userId,
|
||||
'duplicate-projects'
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user