diff --git a/pkg/voucher/parser_test.go b/pkg/voucher/parser_test.go index c618e69..d9f4de4 100644 --- a/pkg/voucher/parser_test.go +++ b/pkg/voucher/parser_test.go @@ -28,6 +28,32 @@ func TestParseRules_SimpleSku(t *testing.T) { } } +func TestRuleCartTotal(t *testing.T) { + rs, err := ParseRules("min_total>=500000") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if len(rs.Conditions) != 1 { + t.Fatalf("expected 1 condition got %d", len(rs.Conditions)) + } + c := rs.Conditions[0] + if c.Kind != RuleMinTotal { + t.Fatalf("expected kind cart total got %s", c.Kind) + } + ctx := EvalContext{ + Items: []Item{ + Item{ + Sku: "123", + }, + }, + CartTotalInc: 400000, + } + applied := rs.Applies(ctx) + if applied { + t.Fatalf("expected") + } +} + func TestParseRules_CategoryAndSkuMixedSeparators(t *testing.T) { rs, err := ParseRules(" category=Shoes|Bags ; sku= A | B , min_total>=1000\nmin_item_price>=500") if err != nil {