flamingo.me/flamingo-commerce/v3@v3.11.0/price/application/service_test.go (about) 1 package application_test 2 3 import ( 4 "testing" 5 6 localeApplication "flamingo.me/flamingo/v3/core/locale/application" 7 "flamingo.me/flamingo/v3/core/locale/domain" 8 "flamingo.me/flamingo/v3/core/locale/infrastructure/fake" 9 "flamingo.me/flamingo/v3/framework/config" 10 "github.com/stretchr/testify/assert" 11 12 "flamingo.me/flamingo-commerce/v3/price/application" 13 priceDomain "flamingo.me/flamingo-commerce/v3/price/domain" 14 ) 15 16 func TestService_FormatPrice(t *testing.T) { 17 translationService := &fake.TranslationService{} 18 19 labelService := &localeApplication.LabelService{} 20 labelService.Inject(func() *domain.Label { 21 label := &domain.Label{} 22 label.Inject(translationService) 23 return label 24 }, translationService, nil, &struct { 25 DefaultLocaleCode string `inject:"config:core.locale.locale"` 26 FallbackLocalCode config.Slice `inject:"config:core.locale.fallbackLocales,optional"` 27 }{ 28 DefaultLocaleCode: "en", 29 FallbackLocalCode: config.Slice{"de"}, 30 }) 31 32 service := application.Service{} 33 service.Inject( 34 labelService, 35 &struct { 36 Config config.Map `inject:"config:locale.accounting"` 37 }{ 38 Config: config.Map{ 39 "JPY": config.Map{ 40 "precision": 0.0, 41 "decimal": "", 42 "thousand": ",", 43 "formatLong": "%s %s", 44 "formatZero": "%s%v", 45 "format": "%s%v", 46 }, 47 "default": config.Map{ 48 "precision": 2.0, 49 "decimal": ".", 50 "thousand": ",", 51 "formatLong": "%s %s", 52 "formatZero": "%s%v", 53 "format": "%s%v", 54 }, 55 }, 56 }, 57 ) 58 59 price := priceDomain.NewFromFloat(-161.92, "USD") 60 formatted := service.FormatPrice(price) 61 assert.Equal(t, "-USD161.92", formatted) 62 63 price = priceDomain.NewFromFloat(-161.92, "JPY") 64 formatted = service.FormatPrice(price) 65 assert.Equal(t, "-JPY162", formatted) 66 }