|
1 | 1 | /**************************************************************************** |
2 | | - * Copyright 2019-2021, Optimizely, Inc. and contributors * |
| 2 | + * Copyright 2019-2026, Optimizely, Inc. and contributors * |
3 | 3 | * * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * |
5 | 5 | * you may not use this file except in compliance with the License. * |
@@ -137,6 +137,45 @@ func (s *PersistingExperimentServiceTestSuite) TestSavedVariationNoLongerValid() |
137 | 137 | s.mockUserProfileService.AssertExpectations(s.T()) |
138 | 138 | } |
139 | 139 |
|
| 140 | +func (s *PersistingExperimentServiceTestSuite) TestCmabExperimentSkipsUserProfileService() { |
| 141 | + // Create a CMAB experiment (has Cmab field set) |
| 142 | + cmabExperiment := entities.Experiment{ |
| 143 | + ID: "cmab_exp_1", |
| 144 | + Key: "cmab_experiment", |
| 145 | + Variations: map[string]entities.Variation{ |
| 146 | + "var1": {ID: "var1", Key: "variation_1"}, |
| 147 | + }, |
| 148 | + Cmab: &entities.Cmab{ |
| 149 | + AttributeIds: []string{"attr1"}, |
| 150 | + TrafficAllocation: 5000, |
| 151 | + }, |
| 152 | + } |
| 153 | + |
| 154 | + cmabDecisionContext := ExperimentDecisionContext{ |
| 155 | + Experiment: &cmabExperiment, |
| 156 | + ProjectConfig: s.mockProjectConfig, |
| 157 | + } |
| 158 | + |
| 159 | + cmabVariation := cmabExperiment.Variations["var1"] |
| 160 | + cmabDecision := ExperimentDecision{ |
| 161 | + Variation: &cmabVariation, |
| 162 | + } |
| 163 | + |
| 164 | + // Setup mock to return decision from bucketer service |
| 165 | + s.mockExperimentService.On("GetDecision", cmabDecisionContext, testUserContext, s.options).Return(cmabDecision, s.reasons, nil) |
| 166 | + |
| 167 | + persistingExperimentService := NewPersistingExperimentService(s.mockUserProfileService, s.mockExperimentService, logging.GetLogger("", "NewPersistingExperimentService")) |
| 168 | + decision, _, err := persistingExperimentService.GetDecision(cmabDecisionContext, testUserContext, s.options) |
| 169 | + |
| 170 | + s.Equal(cmabDecision, decision) |
| 171 | + s.NoError(err) |
| 172 | + // Verify bucketer service was called |
| 173 | + s.mockExperimentService.AssertCalled(s.T(), "GetDecision", cmabDecisionContext, testUserContext, s.options) |
| 174 | + // Verify UPS was NOT called - CMAB should skip user profile service entirely |
| 175 | + s.mockUserProfileService.AssertNotCalled(s.T(), "Lookup", mock.Anything) |
| 176 | + s.mockUserProfileService.AssertNotCalled(s.T(), "Save", mock.Anything) |
| 177 | +} |
| 178 | + |
140 | 179 | func TestPersistingExperimentServiceTestSuite(t *testing.T) { |
141 | 180 | suite.Run(t, new(PersistingExperimentServiceTestSuite)) |
142 | 181 | } |
0 commit comments