Skip to content

Commit

Permalink
Moving strategy to separate package + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rajagopal28 committed Aug 1, 2021
1 parent 0ea497e commit 7e0fe15
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 6 additions & 2 deletions service/app/generate_pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"pricingengine"
"pricingengine/service/strategy"
"pricingengine/service/config"
)

Expand Down Expand Up @@ -44,7 +45,7 @@ func (a *App) GeneratePricing(ctx context.Context, request *pricingengine.Genera
return &result, nil
}

var strategies = Strategy{}
var strategies = strategy.Strategy{}
driver_factor_range, err := strategies.FindMatchingDriverAgeFactor(request, a.Cache.DriverAgeFactorList)
if(err != nil) {
log.Printf("error finding driver_factor_range: %v", err)
Expand Down Expand Up @@ -104,7 +105,10 @@ func (a *App) GeneratePricing(ctx context.Context, request *pricingengine.Genera
// Just forms a map[]{} based on the config in the cache
func (a *App) GeneratePricingConfig(ctx context.Context) (interface{}, error) {
log.Println("Entering GeneratePricingConfig")
a.Cache.Fetcher = config.ConfigFetcher{Path: "/config/"} // Initialise with actual path
// Initialise with actual path if not present
if a.Cache.TimeToLive == 0 {
a.Cache.Fetcher = config.ConfigFetcher{Path: "/config/"}
}
a.Cache.InitialiseWithRefresh(false, 100000) // time to live 100000s
var result map[string]interface{} = make(map[string]interface{})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package strategy

import (
"log"
Expand Down
14 changes: 7 additions & 7 deletions test/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestPriceGenerationAppWithActualConfigs(tp *testing.T){
}
tp.Run("TestPriceGenerationAppToGetValidGeneratedPriceList-FailureScenario-1", func(t *testing.T) {
resp,_ := testApp.GeneratePricing(context.Background(),&pricingengine.GeneratePricingRequest{})
println(resp)

util.AssertFalse(resp.IsEligible, t)
util.AssertEqual(len(resp.PricingList), 0, t)
util.AssertTrue(len(resp.Message) > 0, t)
Expand All @@ -35,7 +35,7 @@ func TestPriceGenerationAppWithActualConfigs(tp *testing.T){
DateOfBirth: "2006-01-02",
}
resp,_ := testApp.GeneratePricing(context.Background(),&request)
println(resp)

util.AssertFalse(resp.IsEligible, t)
util.AssertEqual(len(resp.PricingList), 0, t)
util.AssertTrue(len(resp.Message) > 0, t)
Expand All @@ -49,7 +49,7 @@ func TestPriceGenerationAppWithActualConfigs(tp *testing.T){
InsuranceGroup: 20,
}
resp,_ := testApp.GeneratePricing(context.Background(),&request)
println(resp)

util.AssertFalse(resp.IsEligible, t)
util.AssertEqual(len(resp.PricingList), 0, t)
util.AssertTrue(len(resp.Message) > 0, t)
Expand All @@ -64,7 +64,7 @@ func TestPriceGenerationAppWithActualConfigs(tp *testing.T){
LicenseHeldSince: "2006-01-02",
}
resp,_ := testApp.GeneratePricing(context.Background(),&request)
println(resp)

util.AssertFalse(resp.IsEligible, t)
util.AssertEqual(len(resp.PricingList), 0, t)
util.AssertTrue(len(resp.Message) > 0, t)
Expand All @@ -79,7 +79,7 @@ func TestPriceGenerationAppWithActualConfigs(tp *testing.T){
LicenseHeldSince: "2006-01-02",
}
resp,_ := testApp.GeneratePricing(context.Background(),&request)
println(resp)

util.AssertFalse(resp.IsEligible, t)
util.AssertEqual(len(resp.PricingList), 0, t)
util.AssertTrue(len(resp.Message) > 0, t)
Expand All @@ -95,7 +95,7 @@ func TestPriceGenerationAppWithActualConfigs(tp *testing.T){
LicenseHeldSince: "2006-01-02",
}
resp,_ := testApp.GeneratePricing(context.Background(),&request)
println(resp)

util.AssertTrue(resp.IsEligible, t)
util.AssertEqual(len(resp.PricingList), 2, t)
util.AssertEqual(resp.Message, "Success", t)
Expand All @@ -119,7 +119,7 @@ func TestPriceGenerationAppWithActualConfigs(tp *testing.T){
LicenseHeldSince: "2020-01-02",
}
resp,_ := testApp.GeneratePricing(context.Background(),&request)
println(resp)

util.AssertTrue(resp.IsEligible, t)
util.AssertEqual(len(resp.PricingList), 2, t)
util.AssertEqual(resp.Message, "Success", t)
Expand Down

0 comments on commit 7e0fe15

Please sign in to comment.