Просмотр исходного кода

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

alpha and beta program user properties

GitOrigin-RevId: 633a61df83dd8206e780f67c85dd3403902f00f2
Alexandre Bourdin 4 лет назад
Родитель
Сommit
98db86b8f0

+ 3 - 0
services/web/app/src/Features/BetaProgram/BetaProgramHandler.js

@@ -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 = {

+ 29 - 0
services/web/test/unit/src/BetaProgram/BetaProgramHandlerTests.js

@@ -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