mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-04 06:39:02 +02:00
0654805cbb
Start queue workers explicitly GitOrigin-RevId: 0f8b710e0f1c0d64efa04f46fec269fae53609b2
117 lines
3.4 KiB
JavaScript
117 lines
3.4 KiB
JavaScript
const SandboxedModule = require('sandboxed-module')
|
|
const path = require('path')
|
|
const sinon = require('sinon')
|
|
const { expect } = require('chai')
|
|
|
|
const MODULE_PATH = path.join(
|
|
__dirname,
|
|
'../../../../app/src/Features/User/UserPostRegistrationAnalyticsManager'
|
|
)
|
|
|
|
describe('UserPostRegistrationAnalyticsManager', function () {
|
|
beforeEach(function () {
|
|
this.fakeUserId = '123abc'
|
|
this.postRegistrationAnalyticsQueue = {
|
|
add: sinon.stub().resolves(),
|
|
process: callback => {
|
|
this.queueProcessFunction = callback
|
|
},
|
|
}
|
|
this.Queues = {
|
|
getPostRegistrationAnalyticsQueue: sinon
|
|
.stub()
|
|
.returns(this.postRegistrationAnalyticsQueue),
|
|
}
|
|
this.UserGetter = {
|
|
promises: {
|
|
getUser: sinon.stub().resolves(),
|
|
},
|
|
}
|
|
this.UserGetter.promises.getUser
|
|
.withArgs({ _id: this.fakeUserId })
|
|
.resolves({ _id: this.fakeUserId })
|
|
this.InstitutionsAPI = {
|
|
promises: {
|
|
getUserAffiliations: sinon.stub().resolves([]),
|
|
},
|
|
}
|
|
this.AnalyticsManager = {
|
|
setUserProperty: sinon.stub().resolves(),
|
|
}
|
|
this.UserPostRegistrationAnalyticsManager = SandboxedModule.require(
|
|
MODULE_PATH,
|
|
{
|
|
requires: {
|
|
'../../infrastructure/Queues': this.Queues,
|
|
'./UserGetter': this.UserGetter,
|
|
'../Institutions/InstitutionsAPI': this.InstitutionsAPI,
|
|
'../Analytics/AnalyticsManager': this.AnalyticsManager,
|
|
},
|
|
}
|
|
)
|
|
})
|
|
|
|
describe('schedulePostRegistrationAnalytics', function () {
|
|
it('should schedule delayed job on queue', async function () {
|
|
await this.UserPostRegistrationAnalyticsManager.schedulePostRegistrationAnalytics(
|
|
{
|
|
_id: this.fakeUserId,
|
|
}
|
|
)
|
|
expect(this.postRegistrationAnalyticsQueue.add).to.have.been.calledWith(
|
|
{ userId: this.fakeUserId },
|
|
{ delay: 24 * 60 * 60 * 1000 }
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('postRegistrationAnalytics', function () {
|
|
it('stops without errors if user is not found', async function () {
|
|
await this.UserPostRegistrationAnalyticsManager.postRegistrationAnalytics(
|
|
'not-a-user'
|
|
)
|
|
expect(this.InstitutionsAPI.promises.getUserAffiliations).not.to.have.been
|
|
.called
|
|
expect(this.AnalyticsManager.setUserProperty).not.to.have.been.called
|
|
})
|
|
|
|
it('sets user property if user has commons account affiliationd', async function () {
|
|
this.InstitutionsAPI.promises.getUserAffiliations.resolves([
|
|
{},
|
|
{
|
|
institution: {
|
|
commonsAccount: true,
|
|
},
|
|
},
|
|
{
|
|
institution: {
|
|
commonsAccount: false,
|
|
},
|
|
},
|
|
])
|
|
await this.UserPostRegistrationAnalyticsManager.postRegistrationAnalytics(
|
|
this.fakeUserId
|
|
)
|
|
expect(this.AnalyticsManager.setUserProperty).to.have.been.calledWith(
|
|
this.fakeUserId,
|
|
'registered-from-commons-account',
|
|
true
|
|
)
|
|
})
|
|
|
|
it('does not set user property if user has no commons account affiliation', async function () {
|
|
this.InstitutionsAPI.promises.getUserAffiliations.resolves([
|
|
{
|
|
institution: {
|
|
commonsAccount: false,
|
|
},
|
|
},
|
|
])
|
|
await this.UserPostRegistrationAnalyticsManager.postRegistrationAnalytics(
|
|
this.fakeUserId
|
|
)
|
|
expect(this.AnalyticsManager.setUserProperty).not.to.have.been.called
|
|
})
|
|
})
|
|
})
|