Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

price: add basic test for formatting service #348

Merged
merged 4 commits into from
Nov 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions price/application/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package application_test

import (
"testing"

localeApplication "flamingo.me/flamingo/v3/core/locale/application"
"flamingo.me/flamingo/v3/core/locale/domain"
"flamingo.me/flamingo/v3/core/locale/infrastructure/fake"
"flamingo.me/flamingo/v3/framework/config"
"github.com/stretchr/testify/assert"

"flamingo.me/flamingo-commerce/v3/price/application"
priceDomain "flamingo.me/flamingo-commerce/v3/price/domain"
)

func TestService_FormatPrice(t *testing.T) {
translationService := &fake.TranslationService{}

labelService := &localeApplication.LabelService{}
labelService.Inject(func() *domain.Label {
label := &domain.Label{}
label.Inject(translationService)
return label
}, translationService, nil, &struct {
DefaultLocaleCode string `inject:"config:core.locale.locale"`
FallbackLocalCode config.Slice `inject:"config:core.locale.fallbackLocales,optional"`
}{
DefaultLocaleCode: "en",
FallbackLocalCode: config.Slice{"de"},
})

service := application.Service{}
service.Inject(
labelService,
&struct {
Config config.Map `inject:"config:locale.accounting"`
}{
Config: config.Map{
"default": config.Map{
"decimal": ".",
"thousand": ",",
"formatLong": "%s %s",
"formatZero": "%s%v",
"format": "%s%v",
},
},
},
)

price := priceDomain.NewFromFloat(-161.92, "USD")
formatted := service.FormatPrice(price)
assert.Equal(t, "-USD161.92", formatted)
}