Functional Weave
Code in Python

retail.coupon-validate@1.0.1

vectors.json

14,493 bytes · view raw

[
  {"name": "an ordinary valid coupon on an ordinary basket", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": true, "reasons": [], "eligibleLines": [0, 1]}},
  {"name": "the first day is valid", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-01"], "expect": {"valid": true, "reasons": [], "eligibleLines": [0, 1]}},
  {"name": "the last day is valid, inclusive", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-30"], "expect": {"valid": true, "reasons": [], "eligibleLines": [0, 1]}},
  {"name": "the day before the start is not yet valid", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-08-31"], "expect": {"valid": false, "reasons": ["not-yet-valid"], "eligibleLines": [0, 1]}},
  {"name": "the day after the end has expired", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-10-01"], "expect": {"valid": false, "reasons": ["expired"], "eligibleLines": [0, 1]}},
  {"name": "one redemption left is still usable", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 999, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": true, "reasons": [], "eligibleLines": [0, 1]}},
  {"name": "the global limit reached", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 1000, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": false, "reasons": ["usage-limit-reached"], "eligibleLines": [0, 1]}},
  {"name": "this customer has already used it once", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 1, "2026-09-15"], "expect": {"valid": false, "reasons": ["customer-limit-reached"], "eligibleLines": [0, 1]}},
  {"name": "spend exactly at the minimum is enough", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2300, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": true, "reasons": [], "eligibleLines": [0, 1]}},
  {"name": "one penny under the minimum is not", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2301, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": false, "reasons": ["minimum-spend-not-met"], "eligibleLines": [0, 1]}},
  {"name": "category-only coupon: minimum spend counted on eligible lines only", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "eligible", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": ["homeware"], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": false, "reasons": ["minimum-spend-not-met"], "eligibleLines": [1]}},
  {"name": "category-only coupon: minimum spend counted on the whole basket", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": ["homeware"], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": true, "reasons": [], "eligibleLines": [1]}},
  {"name": "an excluded SKU is not eligible", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": ["TEA-1"], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": true, "reasons": [], "eligibleLines": [1]}},
  {"name": "SKU and category lists are a union", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": ["TEA-1"], "categories": ["homeware"], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": true, "reasons": [], "eligibleLines": [0, 1]}},
  {"name": "an exclusion beats an inclusion", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": ["TEA-1"], "categories": [], "excludedSkus": [], "excludedCategories": ["grocery"]}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expect": {"valid": false, "reasons": ["no-eligible-items"], "eligibleLines": []}},
  {"name": "an empty basket has nothing eligible", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": null, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [], 0, "2026-09-15"], "expect": {"valid": false, "reasons": ["no-eligible-items"], "eligibleLines": []}},
  {"name": "an empty basket also misses a minimum spend", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [], 0, "2026-09-15"], "expect": {"valid": false, "reasons": ["no-eligible-items", "minimum-spend-not-met"], "eligibleLines": []}},
  {"name": "every failure is reported, in the fixed order", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 5000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 1000, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 3, "2026-10-01"], "expect": {"valid": false, "reasons": ["expired", "usage-limit-reached", "customer-limit-reached", "minimum-spend-not-met"], "eligibleLines": [0, 1]}},
  {"name": "null limits mean no limits", "args": [{"code": "SAVE10", "validFrom": null, "validTo": null, "minimumSpend": null, "minimumSpendOn": "basket", "maxUses": null, "timesUsed": 50000, "maxUsesPerCustomer": null, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 99, "1999-01-01"], "expect": {"valid": true, "reasons": [], "eligibleLines": [0, 1]}},
  {"name": "a minimum spend in another currency is an error", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "EUR"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-15"], "expectError": "currency mismatch"},
  {"name": "a malformed date is an error", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-9-15"], "expectError": "onDate must be an ISO date (YYYY-MM-DD)"},
  {"name": "negative customer uses is an error", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], -1, "2026-09-15"], "expectError": "customerUses must not be negative"},
  {"name": "a trailing newline is not part of an ISO date (onDate)", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "2026-09-16\n"], "expectError": "onDate must be an ISO date (YYYY-MM-DD)"},
  {"name": "non-ASCII digits are not an ISO date (onDate)", "args": [{"code": "SAVE10", "validFrom": "2026-09-01", "validTo": "2026-09-30", "minimumSpend": {"minor": 2000, "currency": "GBP"}, "minimumSpendOn": "basket", "maxUses": 1000, "timesUsed": 10, "maxUsesPerCustomer": 1, "skus": [], "categories": [], "excludedSkus": [], "excludedCategories": []}, [{"sku": "TEA-1", "category": "grocery", "total": {"minor": 1500, "currency": "GBP"}}, {"sku": "MUG-2", "category": "homeware", "total": {"minor": 800, "currency": "GBP"}}], 0, "٢٠٢٦-09-16"], "expectError": "onDate must be an ISO date (YYYY-MM-DD)"}
]