Explorar o código

Merge pull request #9009 from overleaf/ab-split-tests-saas-check

[web] Skip split test assignment logic when not in SaaS mode

GitOrigin-RevId: 4c370bbc78c5a6828207f3336dfa6af9f4d71e17
Timothée Alby %!s(int64=4) %!d(string=hai) anos
pai
achega
95a289b80b

+ 17 - 0
services/web/app/src/Features/SplitTests/SplitTestHandler.js

@@ -9,6 +9,7 @@ const SplitTestCache = require('./SplitTestCache')
 const { SplitTest } = require('../../models/SplitTest')
 const UserAnalyticsIdCache = require('../Analytics/UserAnalyticsIdCache')
 const { getAnalyticsIdFromMongoUser } = require('../Analytics/AnalyticsHelper')
+const Features = require('../../infrastructure/Features')
 
 const DEFAULT_VARIANT = 'default'
 const ALPHA_PHASE = 'alpha'
@@ -46,6 +47,10 @@ const DEFAULT_ASSIGNMENT = {
  * @returns {Promise<{variant: string, analytics: {segmentation: {splitTest: string, variant: string, phase: string, versionNumber: number}|{}}}>}
  */
 async function getAssignment(req, res, splitTestName, { sync = false } = {}) {
+  if (!Features.hasFeature('saas')) {
+    return DEFAULT_ASSIGNMENT
+  }
+
   const query = req.query || {}
   let assignment
 
@@ -100,6 +105,10 @@ async function getAssignmentForUser(
   splitTestName,
   { sync = false } = {}
 ) {
+  if (!Features.hasFeature('saas')) {
+    return DEFAULT_ASSIGNMENT
+  }
+
   const analyticsId = await UserAnalyticsIdCache.get(userId)
   return _getAssignment(splitTestName, { analyticsId, userId, sync })
 }
@@ -120,6 +129,10 @@ async function getAssignmentForMongoUser(
   splitTestName,
   { sync = false } = {}
 ) {
+  if (!Features.hasFeature('saas')) {
+    return DEFAULT_ASSIGNMENT
+  }
+
   return _getAssignment(splitTestName, {
     analyticsId: getAnalyticsIdFromMongoUser(user),
     sync,
@@ -132,6 +145,10 @@ async function getAssignmentForMongoUser(
  * Get a mapping of the active split test assignments for the given user
  */
 async function getActiveAssignmentsForUser(userId) {
+  if (!Features.hasFeature('saas')) {
+    return {}
+  }
+
   const user = await _getUser(userId)
   if (user == null) {
     return {}

+ 5 - 0
services/web/test/acceptance/src/PrimaryEmailCheckTests.js

@@ -2,6 +2,7 @@ const UserHelper = require('./helpers/UserHelper')
 const Settings = require('@overleaf/settings')
 const { expect } = require('chai')
 const SplitTestManager = require('../../../app/src/Features/SplitTests/SplitTestManager')
+const Features = require('../../../app/src/infrastructure/Features')
 
 // While the split test is in progress this must be appended to URLs during tests
 const SPLIT_TEST_QUERY = '?primary-email-check=active'
@@ -12,6 +13,10 @@ describe('PrimaryEmailCheck', function () {
   // Create the primary-email-check split test because this is now required for the query string override to work. See
   // https://github.com/overleaf/internal/pull/7545#discussion_r848575736
   before(async function () {
+    if (!Features.hasFeature('saas')) {
+      this.skip()
+    }
+
     await SplitTestManager.createSplitTest({
       name: 'primary-email-check',
       configuration: {