Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pawels-optimizely committed Nov 15, 2019
1 parent ff76a6d commit b30569e
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 10 deletions.
128 changes: 121 additions & 7 deletions pkg/decision/composite_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ func (s *CompositeServiceFeatureTestSuite) SetupTest() {
s.decisionContext = FeatureDecisionContext{
Feature: &testFeat3333,
ProjectConfig: mockConfig,
Variable: entities.Variable{
DefaultValue: "23.34",
ID: "1",
Key: "Key",
Type: entities.Double,
},
}
s.mockFeatureService = new(MockFeatureDecisionService)
s.testUserContext = entities.UserContext{
Expand Down Expand Up @@ -97,10 +91,16 @@ func (s *CompositeServiceFeatureTestSuite) TestDecisionListeners() {
s.Equal(numberOfCalls, 1)
}

func (s *CompositeServiceFeatureTestSuite) TestDecisionListenersNotificationWithVariable() {
func (s *CompositeServiceFeatureTestSuite) TestDecisionListenersNotificationWithFloatVariable() {

compositeExperimentService := NewCompositeExperimentService()
compositeFeatureDecisionService := NewCompositeFeatureService(compositeExperimentService)
s.decisionContext.Variable = entities.Variable{
DefaultValue: "23.34",
ID: "1",
Key: "Key",
Type: entities.Double,
}

decisionService := &CompositeService{
compositeFeatureService: compositeFeatureDecisionService,
Expand Down Expand Up @@ -129,6 +129,120 @@ func (s *CompositeServiceFeatureTestSuite) TestDecisionListenersNotificationWith

}

func (s *CompositeServiceFeatureTestSuite) TestDecisionListenersNotificationWithIntegerVariable() {

compositeExperimentService := NewCompositeExperimentService()
compositeFeatureDecisionService := NewCompositeFeatureService(compositeExperimentService)
s.decisionContext.Variable = entities.Variable{
DefaultValue: "23",
ID: "1",
Key: "Key",
Type: entities.Integer,
}

decisionService := &CompositeService{
compositeFeatureService: compositeFeatureDecisionService,
notificationCenter: registry.GetNotificationCenter("some_key"),
}
decisionService.GetFeatureDecision(s.decisionContext, s.testUserContext)

var numberOfCalls = 0
note := notification.DecisionNotification{}
callback := func(notification notification.DecisionNotification) {
note = notification
numberOfCalls++
}
id, _ := decisionService.OnDecision(callback)

s.NotEqual(id, 0)

decisionService.GetFeatureDecision(s.decisionContext, s.testUserContext)
s.Equal(numberOfCalls, 1)

expectedDecisionInfo := map[string]interface{}{"feature": map[string]interface{}{"featureEnabled": false, "featureKey": "my_test_feature_3333", "source": FeatureTest,
"sourceInfo": map[string]string{"experimentKey": "my_test_feature_3333", "variationKey": "2222"},
"variableKey": "Key", "variableType": entities.Integer, "variableValue": 23}}

s.Equal(expectedDecisionInfo, note.DecisionInfo)

}

func (s *CompositeServiceFeatureTestSuite) TestDecisionListenersNotificationWithBoolVariable() {

compositeExperimentService := NewCompositeExperimentService()
compositeFeatureDecisionService := NewCompositeFeatureService(compositeExperimentService)
s.decisionContext.Variable = entities.Variable{
DefaultValue: "true",
ID: "1",
Key: "Key",
Type: entities.Boolean,
}

decisionService := &CompositeService{
compositeFeatureService: compositeFeatureDecisionService,
notificationCenter: registry.GetNotificationCenter("some_key"),
}
decisionService.GetFeatureDecision(s.decisionContext, s.testUserContext)

var numberOfCalls = 0
note := notification.DecisionNotification{}
callback := func(notification notification.DecisionNotification) {
note = notification
numberOfCalls++
}
id, _ := decisionService.OnDecision(callback)

s.NotEqual(id, 0)

decisionService.GetFeatureDecision(s.decisionContext, s.testUserContext)
s.Equal(numberOfCalls, 1)

expectedDecisionInfo := map[string]interface{}{"feature": map[string]interface{}{"featureEnabled": false, "featureKey": "my_test_feature_3333", "source": FeatureTest,
"sourceInfo": map[string]string{"experimentKey": "my_test_feature_3333", "variationKey": "2222"},
"variableKey": "Key", "variableType": entities.Boolean, "variableValue": true}}

s.Equal(expectedDecisionInfo, note.DecisionInfo)

}

func (s *CompositeServiceFeatureTestSuite) TestDecisionListenersNotificationWithWrongTypelVariable() {

compositeExperimentService := NewCompositeExperimentService()
compositeFeatureDecisionService := NewCompositeFeatureService(compositeExperimentService)
s.decisionContext.Variable = entities.Variable{
DefaultValue: "string",
ID: "1",
Key: "Key",
Type: entities.Double,
}

decisionService := &CompositeService{
compositeFeatureService: compositeFeatureDecisionService,
notificationCenter: registry.GetNotificationCenter("some_key"),
}
decisionService.GetFeatureDecision(s.decisionContext, s.testUserContext)

var numberOfCalls = 0
note := notification.DecisionNotification{}
callback := func(notification notification.DecisionNotification) {
note = notification
numberOfCalls++
}
id, _ := decisionService.OnDecision(callback)

s.NotEqual(id, 0)

decisionService.GetFeatureDecision(s.decisionContext, s.testUserContext)
s.Equal(numberOfCalls, 1)

expectedDecisionInfo := map[string]interface{}{"feature": map[string]interface{}{"featureEnabled": false, "featureKey": "my_test_feature_3333", "source": FeatureTest,
"sourceInfo": map[string]string{"experimentKey": "my_test_feature_3333", "variationKey": "2222"},
"variableKey": "Key", "variableType": entities.Double, "variableValue": "string"}}

s.Equal(expectedDecisionInfo, note.DecisionInfo)

}

func (s *CompositeServiceFeatureTestSuite) TestDecisionListenersNotificationWithNoVariable() {

compositeExperimentService := NewCompositeExperimentService()
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/support/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (c *ScenarioCtx) InTheResponseKeyShouldBeObject(argumentType, value string)
return nil
}
// @TODO: Revert this to test listener called
return nil
//return nil
default:
break
}
Expand All @@ -181,7 +181,7 @@ func (c *ScenarioCtx) InTheResponseShouldMatch(argumentType string, value *gherk
return nil
}
// @TODO: Revert this to test listener called
return nil
//return nil
default:
break
}
Expand All @@ -206,7 +206,7 @@ func (c *ScenarioCtx) ResponseShouldHaveThisExactlyNTimes(argumentType string, c
return nil
}
// @TODO: Revert this to test listener called
return nil
//return nil
default:
break
}
Expand Down

0 comments on commit b30569e

Please sign in to comment.