增加统一倍率调整按钮
This commit is contained in:
1 parent
be655b6569
commit
4195525dc7
23 files changed
+750
-16
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package billing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type bulkStoreStub struct {
|
||||
*quoteStoreStub
|
||||
patch BulkPricePatch
|
||||
err error
|
||||
calls int
|
||||
}
|
||||
|
||||
func (s *bulkStoreStub) UpdateBillingPriceRules(_ context.Context, patch BulkPricePatch) ([]PriceRule, error) {
|
||||
s.calls++
|
||||
s.patch = patch
|
||||
return []PriceRule{{ID: "a"}}, s.err
|
||||
}
|
||||
|
||||
func TestUpdatePricesValidatesExplicitIDsAndNormalizesMultiplier(t *testing.T) {
|
||||
store := &bulkStoreStub{quoteStoreStub: "eStoreStub{}}
|
||||
service := NewService(store, nil)
|
||||
for _, patch := range []BulkPricePatch{
|
||||
{MarkupMultiplier: 1.2},
|
||||
{RuleIDs: []string{""}, MarkupMultiplier: 1.2},
|
||||
{RuleIDs: []string{" a"}, MarkupMultiplier: 1.2},
|
||||
{RuleIDs: []string{"a", "a"}, MarkupMultiplier: 1.2},
|
||||
{RuleIDs: []string{"a"}, MarkupMultiplier: 0.9},
|
||||
{RuleIDs: []string{"a"}, MarkupMultiplier: 1000.1},
|
||||
{RuleIDs: []string{"a"}, MarkupMultiplier: math.NaN()},
|
||||
{RuleIDs: []string{"a"}, MarkupMultiplier: math.Inf(1)},
|
||||
} {
|
||||
if _, err := service.UpdatePrices(context.Background(), patch); HTTPStatus(err) != 400 {
|
||||
t.Fatalf("patch %+v: status = %d, err = %v", patch, HTTPStatus(err), err)
|
||||
}
|
||||
}
|
||||
if store.calls != 0 {
|
||||
t.Fatalf("invalid patch reached store %d times", store.calls)
|
||||
}
|
||||
rules, err := service.UpdatePrices(context.Background(), BulkPricePatch{RuleIDs: []string{"a"}, MarkupMultiplier: 1.234567})
|
||||
if err != nil || len(rules) != 1 || store.patch.MarkupMultiplier != 1.2346 {
|
||||
t.Fatalf("rules = %+v, patch = %+v, err = %v", rules, store.patch, err)
|
||||
}
|
||||
store.err = ErrPriceNotFound
|
||||
if _, err := service.UpdatePrices(context.Background(), BulkPricePatch{RuleIDs: []string{"a"}, MarkupMultiplier: 2}); HTTPStatus(err) != 404 || !errors.Is(err, ErrPriceNotFound) {
|
||||
t.Fatalf("missing rule status = %d, err = %v", HTTPStatus(err), err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user