Skip to content

Commit a1e58e8

Browse files
committed
additional changes
1 parent 769cd4a commit a1e58e8

File tree

2 files changed

+101
-105
lines changed

2 files changed

+101
-105
lines changed

pkg/cmab/client.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import (
3131
)
3232

3333
// CMABPredictionEndpoint is the endpoint for CMAB predictions
34-
// TEMPORARY: Using integration endpoint for testing
35-
var CMABPredictionEndpoint = "https://inte.prediction.cmab.optimizely.com/predict/%s"
34+
var CMABPredictionEndpoint = "https://prediction.cmab.optimizely.com/predict/%s"
3635

3736
const (
3837
// DefaultMaxRetries is the default number of retries for CMAB requests
@@ -135,9 +134,7 @@ func (c *DefaultCmabClient) FetchDecision(
135134
) (string, error) {
136135

137136
// Create the URL
138-
// TEMPORARY: Override with test ruleID
139-
testRuleID := "1304618"
140-
url := fmt.Sprintf(CMABPredictionEndpoint, testRuleID)
137+
url := fmt.Sprintf(CMABPredictionEndpoint, ruleID)
141138

142139
// Log the URL being called
143140
c.logger.Debug(fmt.Sprintf("CMAB Prediction URL: %s", url))
@@ -157,7 +154,7 @@ func (c *DefaultCmabClient) FetchDecision(
157154
Instances: []Instance{
158155
{
159156
VisitorID: userID,
160-
ExperimentID: testRuleID, // TEMPORARY: Use test ruleID
157+
ExperimentID: ruleID,
161158
Attributes: cmabAttributes,
162159
CmabUUID: cmabUUID,
163160
},

pkg/decision/experiment_bucketer_service_test.go

Lines changed: 98 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -14,105 +14,104 @@
1414
* limitations under the License. *
1515
***************************************************************************/
1616

17-
package decision
18-
19-
import (
20-
"fmt"
21-
"testing"
22-
23-
"github.com/optimizely/go-sdk/v2/pkg/decide"
24-
"github.com/optimizely/go-sdk/v2/pkg/decision/reasons"
25-
"github.com/optimizely/go-sdk/v2/pkg/logging"
26-
27-
"github.com/optimizely/go-sdk/v2/pkg/entities"
28-
"github.com/stretchr/testify/mock"
29-
"github.com/stretchr/testify/suite"
30-
)
31-
32-
type MockBucketer struct {
33-
mock.Mock
34-
}
35-
36-
func (m *MockBucketer) Bucket(bucketingID string, experiment entities.Experiment, group entities.Group) (*entities.Variation, reasons.Reason, error) {
37-
args := m.Called(bucketingID, experiment, group)
38-
return args.Get(0).(*entities.Variation), args.Get(1).(reasons.Reason), args.Error(2)
39-
}
40-
41-
// Add the new method to satisfy the ExperimentBucketer interface
42-
func (m *MockBucketer) BucketToEntityID(bucketingID string, experiment entities.Experiment, group entities.Group) (string, reasons.Reason, error) {
43-
args := m.Called(bucketingID, experiment, group)
44-
return args.String(0), args.Get(1).(reasons.Reason), args.Error(2)
45-
}
46-
47-
type MockLogger struct {
48-
mock.Mock
49-
}
50-
51-
func (m *MockLogger) Debug(message string) {
52-
m.Called(message)
53-
}
54-
55-
func (m *MockLogger) Info(message string) {
56-
m.Called(message)
57-
}
58-
59-
func (m *MockLogger) Warning(message string) {
60-
m.Called(message)
61-
}
62-
63-
func (m *MockLogger) Error(message string, err interface{}) {
64-
m.Called(message, err)
65-
}
66-
67-
type ExperimentBucketerTestSuite struct {
68-
suite.Suite
69-
mockBucketer *MockBucketer
70-
mockLogger *MockLogger
71-
mockConfig *mockProjectConfig
72-
options *decide.Options
73-
reasons decide.DecisionReasons
74-
}
75-
76-
func (s *ExperimentBucketerTestSuite) SetupTest() {
77-
s.mockBucketer = new(MockBucketer)
78-
s.mockLogger = new(MockLogger)
79-
s.mockConfig = new(mockProjectConfig)
80-
s.options = &decide.Options{}
81-
s.reasons = decide.NewDecisionReasons(s.options)
82-
}
83-
84-
func (s *ExperimentBucketerTestSuite) TestGetDecisionNoTargeting() {
85-
testUserContext := entities.UserContext{
86-
ID: "test_user_1",
87-
}
88-
89-
expectedDecision := ExperimentDecision{
90-
Variation: &testExp1111Var2222,
91-
Decision: Decision{
92-
Reason: reasons.BucketedIntoVariation,
93-
},
94-
}
95-
96-
testDecisionContext := ExperimentDecisionContext{
97-
Experiment: &testExp1111,
98-
ProjectConfig: s.mockConfig,
99-
}
100-
s.mockBucketer.On("Bucket", testUserContext.ID, testExp1111, entities.Group{}).Return(&testExp1111Var2222, reasons.BucketedIntoVariation, nil)
101-
s.mockLogger.On("Debug", fmt.Sprintf(logging.ExperimentAudiencesEvaluatedTo.String(), "test_experiment_1111", true))
102-
experimentBucketerService := ExperimentBucketerService{
103-
bucketer: s.mockBucketer,
104-
logger: s.mockLogger,
105-
}
106-
s.options.IncludeReasons = true
107-
decision, rsons, err := experimentBucketerService.GetDecision(testDecisionContext, testUserContext, s.options)
108-
messages := rsons.ToReport()
109-
s.Len(messages, 1)
110-
s.Equal(`Audiences for experiment test_experiment_1111 collectively evaluated to true.`, messages[0])
111-
s.Equal(expectedDecision, decision)
112-
s.NoError(err)
113-
s.mockLogger.AssertExpectations(s.T())
114-
}
115-
17+
package decision
18+
19+
import (
20+
"fmt"
21+
"testing"
22+
23+
"github.com/optimizely/go-sdk/v2/pkg/decide"
24+
"github.com/optimizely/go-sdk/v2/pkg/decision/reasons"
25+
"github.com/optimizely/go-sdk/v2/pkg/logging"
26+
27+
"github.com/optimizely/go-sdk/v2/pkg/entities"
28+
"github.com/stretchr/testify/mock"
29+
"github.com/stretchr/testify/suite"
30+
)
31+
32+
type MockBucketer struct {
33+
mock.Mock
34+
}
35+
36+
func (m *MockBucketer) Bucket(bucketingID string, experiment entities.Experiment, group entities.Group) (*entities.Variation, reasons.Reason, error) {
37+
args := m.Called(bucketingID, experiment, group)
38+
return args.Get(0).(*entities.Variation), args.Get(1).(reasons.Reason), args.Error(2)
39+
}
40+
41+
// Add the new method to satisfy the ExperimentBucketer interface
42+
func (m *MockBucketer) BucketToEntityID(bucketingID string, experiment entities.Experiment, group entities.Group) (string, reasons.Reason, error) {
43+
args := m.Called(bucketingID, experiment, group)
44+
return args.String(0), args.Get(1).(reasons.Reason), args.Error(2)
45+
}
46+
47+
type MockLogger struct {
48+
mock.Mock
49+
}
50+
51+
func (m *MockLogger) Debug(message string) {
52+
m.Called(message)
53+
}
54+
55+
func (m *MockLogger) Info(message string) {
56+
m.Called(message)
57+
}
58+
59+
func (m *MockLogger) Warning(message string) {
60+
m.Called(message)
61+
}
62+
63+
func (m *MockLogger) Error(message string, err interface{}) {
64+
m.Called(message, err)
65+
}
66+
67+
type ExperimentBucketerTestSuite struct {
68+
suite.Suite
69+
mockBucketer *MockBucketer
70+
mockLogger *MockLogger
71+
mockConfig *mockProjectConfig
72+
options *decide.Options
73+
reasons decide.DecisionReasons
74+
}
75+
76+
func (s *ExperimentBucketerTestSuite) SetupTest() {
77+
s.mockBucketer = new(MockBucketer)
78+
s.mockLogger = new(MockLogger)
79+
s.mockConfig = new(mockProjectConfig)
80+
s.options = &decide.Options{}
81+
s.reasons = decide.NewDecisionReasons(s.options)
82+
}
83+
84+
func (s *ExperimentBucketerTestSuite) TestGetDecisionNoTargeting() {
85+
testUserContext := entities.UserContext{
86+
ID: "test_user_1",
87+
}
88+
89+
expectedDecision := ExperimentDecision{
90+
Variation: &testExp1111Var2222,
91+
Decision: Decision{
92+
Reason: reasons.BucketedIntoVariation,
93+
},
94+
}
95+
96+
testDecisionContext := ExperimentDecisionContext{
97+
Experiment: &testExp1111,
98+
ProjectConfig: s.mockConfig,
99+
}
100+
s.mockBucketer.On("Bucket", testUserContext.ID, testExp1111, entities.Group{}).Return(&testExp1111Var2222, reasons.BucketedIntoVariation, nil)
101+
s.mockLogger.On("Debug", fmt.Sprintf(logging.ExperimentAudiencesEvaluatedTo.String(), "test_experiment_1111", true))
102+
experimentBucketerService := ExperimentBucketerService{
103+
bucketer: s.mockBucketer,
104+
logger: s.mockLogger,
105+
}
106+
s.options.IncludeReasons = true
107+
decision, rsons, err := experimentBucketerService.GetDecision(testDecisionContext, testUserContext, s.options)
108+
messages := rsons.ToReport()
109+
s.Len(messages, 1)
110+
s.Equal(`Audiences for experiment test_experiment_1111 collectively evaluated to true.`, messages[0])
111+
s.Equal(expectedDecision, decision)
112+
s.NoError(err)
113+
s.mockLogger.AssertExpectations(s.T())
114+
}
116115

117116
func (s *ExperimentBucketerTestSuite) TestGetDecisionWithTargetingPasses() {
118117
testUserContext := entities.UserContext{

0 commit comments

Comments
 (0)