Merge pull request #5348 from overleaf/ab-alpha-beta-properties

alpha and beta program user properties

GitOrigin-RevId: 633a61df83dd8206e780f67c85dd3403902f00f2
This commit is contained in:
Alexandre Bourdin 2021-10-05 15:38:53 +02:00 committed by Copybot
parent 4cecc6383a
commit 98db86b8f0
2 changed files with 32 additions and 0 deletions

View file

@ -1,10 +1,12 @@
const { callbackify } = require('util')
const metrics = require('@overleaf/metrics')
const UserUpdater = require('../User/UserUpdater')
const AnalyticsManager = require('../Analytics/AnalyticsManager')
async function optIn(userId) {
await UserUpdater.promises.updateUser(userId, { $set: { betaProgram: true } })
metrics.inc('beta-program.opt-in')
AnalyticsManager.setUserPropertyForUser(userId, 'beta-program', true)
}
async function optOut(userId) {
@ -12,6 +14,7 @@ async function optOut(userId) {
$set: { betaProgram: false },
})
metrics.inc('beta-program.opt-out')
AnalyticsManager.setUserPropertyForUser(userId, 'beta-program', false)
}
const BetaProgramHandler = {

View file

@ -27,6 +27,9 @@ describe('BetaProgramHandler', function () {
updateUser: sinon.stub().resolves(),
},
}),
'../Analytics/AnalyticsManager': (this.AnalyticsManager = {
setUserPropertyForUser: sinon.stub().resolves(),
}),
},
})
})
@ -47,6 +50,19 @@ describe('BetaProgramHandler', function () {
})
})
it('should set beta-program user property to true', function (done) {
this.call(err => {
expect(err).to.not.exist
sinon.assert.calledWith(
this.AnalyticsManager.setUserPropertyForUser,
this.user_id,
'beta-program',
true
)
done()
})
})
it('should not produce an error', function (done) {
this.call(err => {
expect(err).to.not.exist
@ -85,6 +101,19 @@ describe('BetaProgramHandler', function () {
})
})
it('should set beta-program user property to false', function (done) {
this.call(err => {
expect(err).to.not.exist
sinon.assert.calledWith(
this.AnalyticsManager.setUserPropertyForUser,
this.user_id,
'beta-program',
false
)
done()
})
})
it('should not produce an error', function (done) {
this.call(err => {
expect(err).to.not.exist