|
@@ -24,9 +24,12 @@ describe('UserPostRegistrationAnalyticsManager', function () {
|
|
|
}
|
|
}
|
|
|
this.UserGetter = {
|
|
this.UserGetter = {
|
|
|
promises: {
|
|
promises: {
|
|
|
- getUser: sinon.stub().resolves({ _id: this.fakeUserId }),
|
|
|
|
|
|
|
+ getUser: sinon.stub().resolves(),
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
+ this.UserGetter.promises.getUser
|
|
|
|
|
+ .withArgs({ _id: this.fakeUserId })
|
|
|
|
|
+ .resolves({ _id: this.fakeUserId })
|
|
|
this.InstitutionsAPI = {
|
|
this.InstitutionsAPI = {
|
|
|
promises: {
|
|
promises: {
|
|
|
getUserAffiliations: sinon.stub().resolves([]),
|
|
getUserAffiliations: sinon.stub().resolves([]),
|
|
@@ -35,114 +38,79 @@ describe('UserPostRegistrationAnalyticsManager', function () {
|
|
|
this.AnalyticsManager = {
|
|
this.AnalyticsManager = {
|
|
|
setUserProperty: sinon.stub().resolves(),
|
|
setUserProperty: sinon.stub().resolves(),
|
|
|
}
|
|
}
|
|
|
- this.Features = {
|
|
|
|
|
- hasFeature: sinon.stub().returns(true),
|
|
|
|
|
- }
|
|
|
|
|
- this.init = isSAAS => {
|
|
|
|
|
- this.Features.hasFeature.withArgs('saas').returns(isSAAS)
|
|
|
|
|
- this.UserPostRegistrationAnalyticsManager = SandboxedModule.require(
|
|
|
|
|
- MODULE_PATH,
|
|
|
|
|
|
|
+ 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(
|
|
|
{
|
|
{
|
|
|
- requires: {
|
|
|
|
|
- '../../infrastructure/Features': this.Features,
|
|
|
|
|
- '../../infrastructure/Queues': this.Queues,
|
|
|
|
|
- './UserGetter': this.UserGetter,
|
|
|
|
|
- '../Institutions/InstitutionsAPI': this.InstitutionsAPI,
|
|
|
|
|
- '../Analytics/AnalyticsManager': this.AnalyticsManager,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ _id: this.fakeUserId,
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- describe('in Server CE/Pro', function () {
|
|
|
|
|
- beforeEach(function () {
|
|
|
|
|
- this.init(false)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should schedule delayed job on queue', function () {
|
|
|
|
|
- this.UserPostRegistrationAnalyticsManager.schedulePostRegistrationAnalytics(
|
|
|
|
|
- { _id: this.fakeUserId }
|
|
|
|
|
|
|
+ expect(this.postRegistrationAnalyticsQueue.add).to.have.been.calledWith(
|
|
|
|
|
+ { userId: this.fakeUserId },
|
|
|
|
|
+ { delay: 24 * 60 * 60 * 1000 }
|
|
|
)
|
|
)
|
|
|
- expect(this.Queues.getPostRegistrationAnalyticsQueue).to.not.have.been
|
|
|
|
|
- .called
|
|
|
|
|
- expect(this.postRegistrationAnalyticsQueue.add).to.not.have.been.called
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('in SAAS', function () {
|
|
|
|
|
- beforeEach(function () {
|
|
|
|
|
- this.init(true)
|
|
|
|
|
- })
|
|
|
|
|
- describe('schedule jobs in SAAS', function () {
|
|
|
|
|
- it('should schedule delayed job on queue', function () {
|
|
|
|
|
- this.UserPostRegistrationAnalyticsManager.schedulePostRegistrationAnalytics(
|
|
|
|
|
- {
|
|
|
|
|
- _id: this.fakeUserId,
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- sinon.assert.calledWithMatch(
|
|
|
|
|
- this.postRegistrationAnalyticsQueue.add,
|
|
|
|
|
- { 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
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('process jobs', function () {
|
|
|
|
|
- it('stops without errors if user is not found', async function () {
|
|
|
|
|
- this.UserGetter.promises.getUser.resolves(null)
|
|
|
|
|
- await this.queueProcessFunction({ data: { userId: this.fakeUserId } })
|
|
|
|
|
- sinon.assert.calledWith(this.UserGetter.promises.getUser, {
|
|
|
|
|
- _id: this.fakeUserId,
|
|
|
|
|
- })
|
|
|
|
|
- sinon.assert.notCalled(
|
|
|
|
|
- this.InstitutionsAPI.promises.getUserAffiliations
|
|
|
|
|
- )
|
|
|
|
|
- sinon.assert.notCalled(this.AnalyticsManager.setUserProperty)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('sets user property if user has commons account affiliationd', async function () {
|
|
|
|
|
- this.InstitutionsAPI.promises.getUserAffiliations.resolves([
|
|
|
|
|
- {},
|
|
|
|
|
- {
|
|
|
|
|
- institution: {
|
|
|
|
|
- commonsAccount: true,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ it('sets user property if user has commons account affiliationd', async function () {
|
|
|
|
|
+ this.InstitutionsAPI.promises.getUserAffiliations.resolves([
|
|
|
|
|
+ {},
|
|
|
|
|
+ {
|
|
|
|
|
+ institution: {
|
|
|
|
|
+ commonsAccount: true,
|
|
|
},
|
|
},
|
|
|
- {
|
|
|
|
|
- institution: {
|
|
|
|
|
- commonsAccount: false,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ institution: {
|
|
|
|
|
+ commonsAccount: false,
|
|
|
},
|
|
},
|
|
|
- ])
|
|
|
|
|
- await this.queueProcessFunction({ data: { userId: this.fakeUserId } })
|
|
|
|
|
- sinon.assert.calledWith(this.UserGetter.promises.getUser, {
|
|
|
|
|
- _id: this.fakeUserId,
|
|
|
|
|
- })
|
|
|
|
|
- sinon.assert.calledWith(
|
|
|
|
|
- this.InstitutionsAPI.promises.getUserAffiliations,
|
|
|
|
|
- this.fakeUserId
|
|
|
|
|
- )
|
|
|
|
|
- sinon.assert.calledWith(
|
|
|
|
|
- this.AnalyticsManager.setUserProperty,
|
|
|
|
|
- this.fakeUserId,
|
|
|
|
|
- 'registered-from-commons-account',
|
|
|
|
|
- true
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ ])
|
|
|
|
|
+ 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,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ 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.queueProcessFunction({ data: { userId: this.fakeUserId } })
|
|
|
|
|
- sinon.assert.notCalled(this.AnalyticsManager.setUserProperty)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ ])
|
|
|
|
|
+ await this.UserPostRegistrationAnalyticsManager.postRegistrationAnalytics(
|
|
|
|
|
+ this.fakeUserId
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(this.AnalyticsManager.setUserProperty).not.to.have.been.called
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|