Functional Weave
Code in TypeScript

retail.promotion-apply@1.0.0

vectors.json

17,128 bytes · view raw

[
  {"name": "BOGOF on four: two free", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 4}], [{"id": "bogof-cola", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expect": {"lines": [{"sku": "COLA", "quantity": 4, "gross": {"minor": 600, "currency": "GBP"}, "discount": {"minor": 300, "currency": "GBP"}, "net": {"minor": 300, "currency": "GBP"}}], "applied": [{"id": "bogof-cola", "groups": 2, "discount": {"minor": 300, "currency": "GBP"}}], "subtotal": {"minor": 600, "currency": "GBP"}, "discount": {"minor": 300, "currency": "GBP"}, "total": {"minor": 300, "currency": "GBP"}}},
  {"name": "BOGOF on three: the odd one pays full price", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 3}], [{"id": "bogof-cola", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expect": {"lines": [{"sku": "COLA", "quantity": 3, "gross": {"minor": 450, "currency": "GBP"}, "discount": {"minor": 150, "currency": "GBP"}, "net": {"minor": 300, "currency": "GBP"}}], "applied": [{"id": "bogof-cola", "groups": 1, "discount": {"minor": 150, "currency": "GBP"}}], "subtotal": {"minor": 450, "currency": "GBP"}, "discount": {"minor": 150, "currency": "GBP"}, "total": {"minor": 300, "currency": "GBP"}}},
  {"name": "3 for 2 mix and match: the cheapest is free, and the saving is shared by price", "args": [[{"sku": "BOOK-A", "unitPrice": {"minor": 899, "currency": "GBP"}, "quantity": 1}, {"sku": "BOOK-B", "unitPrice": {"minor": 799, "currency": "GBP"}, "quantity": 1}, {"sku": "BOOK-C", "unitPrice": {"minor": 599, "currency": "GBP"}, "quantity": 1}], [{"id": "3for2-books", "kind": "free-items", "skus": ["BOOK-A", "BOOK-B", "BOOK-C"], "groupSize": 3, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expect": {"lines": [{"sku": "BOOK-A", "quantity": 1, "gross": {"minor": 899, "currency": "GBP"}, "discount": {"minor": 235, "currency": "GBP"}, "net": {"minor": 664, "currency": "GBP"}}, {"sku": "BOOK-B", "quantity": 1, "gross": {"minor": 799, "currency": "GBP"}, "discount": {"minor": 208, "currency": "GBP"}, "net": {"minor": 591, "currency": "GBP"}}, {"sku": "BOOK-C", "quantity": 1, "gross": {"minor": 599, "currency": "GBP"}, "discount": {"minor": 156, "currency": "GBP"}, "net": {"minor": 443, "currency": "GBP"}}], "applied": [{"id": "3for2-books", "groups": 1, "discount": {"minor": 599, "currency": "GBP"}}], "subtotal": {"minor": 2297, "currency": "GBP"}, "discount": {"minor": 599, "currency": "GBP"}, "total": {"minor": 1698, "currency": "GBP"}}},
  {"name": "3 for 2 on four items groups the dearest three, so the 6.00 item is free, not the 3.00 one", "args": [[{"sku": "W", "unitPrice": {"minor": 1000, "currency": "GBP"}, "quantity": 1}, {"sku": "X", "unitPrice": {"minor": 800, "currency": "GBP"}, "quantity": 1}, {"sku": "Y", "unitPrice": {"minor": 600, "currency": "GBP"}, "quantity": 1}, {"sku": "Z", "unitPrice": {"minor": 300, "currency": "GBP"}, "quantity": 1}], [{"id": "3for2", "kind": "free-items", "skus": ["W", "X", "Y", "Z"], "groupSize": 3, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expect": {"lines": [{"sku": "W", "quantity": 1, "gross": {"minor": 1000, "currency": "GBP"}, "discount": {"minor": 250, "currency": "GBP"}, "net": {"minor": 750, "currency": "GBP"}}, {"sku": "X", "quantity": 1, "gross": {"minor": 800, "currency": "GBP"}, "discount": {"minor": 200, "currency": "GBP"}, "net": {"minor": 600, "currency": "GBP"}}, {"sku": "Y", "quantity": 1, "gross": {"minor": 600, "currency": "GBP"}, "discount": {"minor": 150, "currency": "GBP"}, "net": {"minor": 450, "currency": "GBP"}}, {"sku": "Z", "quantity": 1, "gross": {"minor": 300, "currency": "GBP"}, "discount": {"minor": 0, "currency": "GBP"}, "net": {"minor": 300, "currency": "GBP"}}], "applied": [{"id": "3for2", "groups": 1, "discount": {"minor": 600, "currency": "GBP"}}], "subtotal": {"minor": 2700, "currency": "GBP"}, "discount": {"minor": 600, "currency": "GBP"}, "total": {"minor": 2100, "currency": "GBP"}}},
  {"name": "3 for 10.00 on one SKU", "args": [[{"sku": "MEAL", "unitPrice": {"minor": 399, "currency": "GBP"}, "quantity": 3}], [{"id": "meal-deal", "kind": "group-price", "skus": ["MEAL"], "groupSize": 3, "freeItems": 0, "basisPoints": 0, "amount": {"minor": 1000, "currency": "GBP"}}]], "expect": {"lines": [{"sku": "MEAL", "quantity": 3, "gross": {"minor": 1197, "currency": "GBP"}, "discount": {"minor": 197, "currency": "GBP"}, "net": {"minor": 1000, "currency": "GBP"}}], "applied": [{"id": "meal-deal", "groups": 1, "discount": {"minor": 197, "currency": "GBP"}}], "subtotal": {"minor": 1197, "currency": "GBP"}, "discount": {"minor": 197, "currency": "GBP"}, "total": {"minor": 1000, "currency": "GBP"}}},
  {"name": "3 for 10.00 mix and match, saving allocated by largest remainder", "args": [[{"sku": "MEAL-A", "unitPrice": {"minor": 399, "currency": "GBP"}, "quantity": 1}, {"sku": "MEAL-B", "unitPrice": {"minor": 350, "currency": "GBP"}, "quantity": 1}, {"sku": "MEAL-C", "unitPrice": {"minor": 450, "currency": "GBP"}, "quantity": 1}], [{"id": "meal-deal", "kind": "group-price", "skus": ["MEAL-A", "MEAL-B", "MEAL-C"], "groupSize": 3, "freeItems": 0, "basisPoints": 0, "amount": {"minor": 1000, "currency": "GBP"}}]], "expect": {"lines": [{"sku": "MEAL-A", "quantity": 1, "gross": {"minor": 399, "currency": "GBP"}, "discount": {"minor": 66, "currency": "GBP"}, "net": {"minor": 333, "currency": "GBP"}}, {"sku": "MEAL-B", "quantity": 1, "gross": {"minor": 350, "currency": "GBP"}, "discount": {"minor": 58, "currency": "GBP"}, "net": {"minor": 292, "currency": "GBP"}}, {"sku": "MEAL-C", "quantity": 1, "gross": {"minor": 450, "currency": "GBP"}, "discount": {"minor": 75, "currency": "GBP"}, "net": {"minor": 375, "currency": "GBP"}}], "applied": [{"id": "meal-deal", "groups": 1, "discount": {"minor": 199, "currency": "GBP"}}], "subtotal": {"minor": 1199, "currency": "GBP"}, "discount": {"minor": 199, "currency": "GBP"}, "total": {"minor": 1000, "currency": "GBP"}}},
  {"name": "a multibuy that would cost more than full price does not apply", "args": [[{"sku": "CHEAP", "unitPrice": {"minor": 300, "currency": "GBP"}, "quantity": 3}], [{"id": "meal-deal", "kind": "group-price", "skus": ["CHEAP"], "groupSize": 3, "freeItems": 0, "basisPoints": 0, "amount": {"minor": 1000, "currency": "GBP"}}]], "expect": {"lines": [{"sku": "CHEAP", "quantity": 3, "gross": {"minor": 900, "currency": "GBP"}, "discount": {"minor": 0, "currency": "GBP"}, "net": {"minor": 900, "currency": "GBP"}}], "applied": [], "subtotal": {"minor": 900, "currency": "GBP"}, "discount": {"minor": 0, "currency": "GBP"}, "total": {"minor": 900, "currency": "GBP"}}},
  {"name": "25% off each item rounds per item: 3 x 5.00, not 25% of 59.97", "args": [[{"sku": "SHIRT", "unitPrice": {"minor": 1999, "currency": "GBP"}, "quantity": 3}], [{"id": "shirts-25", "kind": "percent-off", "skus": ["SHIRT"], "groupSize": 1, "freeItems": 0, "basisPoints": 2500, "amount": null}]], "expect": {"lines": [{"sku": "SHIRT", "quantity": 3, "gross": {"minor": 5997, "currency": "GBP"}, "discount": {"minor": 1500, "currency": "GBP"}, "net": {"minor": 4497, "currency": "GBP"}}], "applied": [{"id": "shirts-25", "groups": 3, "discount": {"minor": 1500, "currency": "GBP"}}], "subtotal": {"minor": 5997, "currency": "GBP"}, "discount": {"minor": 1500, "currency": "GBP"}, "total": {"minor": 4497, "currency": "GBP"}}},
  {"name": "5.00 off any two", "args": [[{"sku": "X", "unitPrice": {"minor": 1200, "currency": "GBP"}, "quantity": 2}], [{"id": "x-5off", "kind": "amount-off", "skus": ["X"], "groupSize": 2, "freeItems": 0, "basisPoints": 0, "amount": {"minor": 500, "currency": "GBP"}}]], "expect": {"lines": [{"sku": "X", "quantity": 2, "gross": {"minor": 2400, "currency": "GBP"}, "discount": {"minor": 500, "currency": "GBP"}, "net": {"minor": 1900, "currency": "GBP"}}], "applied": [{"id": "x-5off", "groups": 1, "discount": {"minor": 500, "currency": "GBP"}}], "subtotal": {"minor": 2400, "currency": "GBP"}, "discount": {"minor": 500, "currency": "GBP"}, "total": {"minor": 1900, "currency": "GBP"}}},
  {"name": "an amount off never takes an item below zero", "args": [[{"sku": "Y", "unitPrice": {"minor": 300, "currency": "GBP"}, "quantity": 1}], [{"id": "y-5off", "kind": "amount-off", "skus": ["Y"], "groupSize": 1, "freeItems": 0, "basisPoints": 0, "amount": {"minor": 500, "currency": "GBP"}}]], "expect": {"lines": [{"sku": "Y", "quantity": 1, "gross": {"minor": 300, "currency": "GBP"}, "discount": {"minor": 300, "currency": "GBP"}, "net": {"minor": 0, "currency": "GBP"}}], "applied": [{"id": "y-5off", "groups": 1, "discount": {"minor": 300, "currency": "GBP"}}], "subtotal": {"minor": 300, "currency": "GBP"}, "discount": {"minor": 300, "currency": "GBP"}, "total": {"minor": 0, "currency": "GBP"}}},
  {"name": "competing offers: 3 for 2 beats 25% off, whichever is listed first", "args": [[{"sku": "WINE", "unitPrice": {"minor": 800, "currency": "GBP"}, "quantity": 3}], [{"id": "wine-25", "kind": "percent-off", "skus": ["WINE"], "groupSize": 1, "freeItems": 0, "basisPoints": 2500, "amount": null}, {"id": "wine-3for2", "kind": "free-items", "skus": ["WINE"], "groupSize": 3, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expect": {"lines": [{"sku": "WINE", "quantity": 3, "gross": {"minor": 2400, "currency": "GBP"}, "discount": {"minor": 800, "currency": "GBP"}, "net": {"minor": 1600, "currency": "GBP"}}], "applied": [{"id": "wine-3for2", "groups": 1, "discount": {"minor": 800, "currency": "GBP"}}], "subtotal": {"minor": 2400, "currency": "GBP"}, "discount": {"minor": 800, "currency": "GBP"}, "total": {"minor": 1600, "currency": "GBP"}}},
  {"name": "the best combination beats the biggest single saving first", "args": [[{"sku": "A", "unitPrice": {"minor": 1000, "currency": "GBP"}, "quantity": 1}, {"sku": "B", "unitPrice": {"minor": 1000, "currency": "GBP"}, "quantity": 2}], [{"id": "b-half", "kind": "percent-off", "skus": ["B"], "groupSize": 1, "freeItems": 0, "basisPoints": 5000, "amount": null}, {"id": "ab-bogof", "kind": "free-items", "skus": ["A", "B"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expect": {"lines": [{"sku": "A", "quantity": 1, "gross": {"minor": 1000, "currency": "GBP"}, "discount": {"minor": 500, "currency": "GBP"}, "net": {"minor": 500, "currency": "GBP"}}, {"sku": "B", "quantity": 2, "gross": {"minor": 2000, "currency": "GBP"}, "discount": {"minor": 1000, "currency": "GBP"}, "net": {"minor": 1000, "currency": "GBP"}}], "applied": [{"id": "b-half", "groups": 1, "discount": {"minor": 500, "currency": "GBP"}}, {"id": "ab-bogof", "groups": 1, "discount": {"minor": 1000, "currency": "GBP"}}], "subtotal": {"minor": 3000, "currency": "GBP"}, "discount": {"minor": 1500, "currency": "GBP"}, "total": {"minor": 1500, "currency": "GBP"}}},
  {"name": "independent offers and an unpromoted line", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 2}, {"sku": "BOOK", "unitPrice": {"minor": 899, "currency": "GBP"}, "quantity": 1}, {"sku": "MILK", "unitPrice": {"minor": 120, "currency": "GBP"}, "quantity": 1}], [{"id": "bogof-cola", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "book-10", "kind": "percent-off", "skus": ["BOOK"], "groupSize": 1, "freeItems": 0, "basisPoints": 1000, "amount": null}]], "expect": {"lines": [{"sku": "COLA", "quantity": 2, "gross": {"minor": 300, "currency": "GBP"}, "discount": {"minor": 150, "currency": "GBP"}, "net": {"minor": 150, "currency": "GBP"}}, {"sku": "BOOK", "quantity": 1, "gross": {"minor": 899, "currency": "GBP"}, "discount": {"minor": 90, "currency": "GBP"}, "net": {"minor": 809, "currency": "GBP"}}, {"sku": "MILK", "quantity": 1, "gross": {"minor": 120, "currency": "GBP"}, "discount": {"minor": 0, "currency": "GBP"}, "net": {"minor": 120, "currency": "GBP"}}], "applied": [{"id": "bogof-cola", "groups": 1, "discount": {"minor": 150, "currency": "GBP"}}, {"id": "book-10", "groups": 1, "discount": {"minor": 90, "currency": "GBP"}}], "subtotal": {"minor": 1319, "currency": "GBP"}, "discount": {"minor": 240, "currency": "GBP"}, "total": {"minor": 1079, "currency": "GBP"}}},
  {"name": "an offer for something not in the basket does nothing", "args": [[{"sku": "MILK", "unitPrice": {"minor": 120, "currency": "GBP"}, "quantity": 1}], [{"id": "bogof-cola", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expect": {"lines": [{"sku": "MILK", "quantity": 1, "gross": {"minor": 120, "currency": "GBP"}, "discount": {"minor": 0, "currency": "GBP"}, "net": {"minor": 120, "currency": "GBP"}}], "applied": [], "subtotal": {"minor": 120, "currency": "GBP"}, "discount": {"minor": 0, "currency": "GBP"}, "total": {"minor": 120, "currency": "GBP"}}},
  {"name": "no promotions at all", "args": [[{"sku": "MILK", "unitPrice": {"minor": 120, "currency": "GBP"}, "quantity": 2}], []], "expect": {"lines": [{"sku": "MILK", "quantity": 2, "gross": {"minor": 240, "currency": "GBP"}, "discount": {"minor": 0, "currency": "GBP"}, "net": {"minor": 240, "currency": "GBP"}}], "applied": [], "subtotal": {"minor": 240, "currency": "GBP"}, "discount": {"minor": 0, "currency": "GBP"}, "total": {"minor": 240, "currency": "GBP"}}},
  {"name": "two identical offers: the first listed wins the tie", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 2}], [{"id": "p1", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "p2", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expect": {"lines": [{"sku": "COLA", "quantity": 2, "gross": {"minor": 300, "currency": "GBP"}, "discount": {"minor": 150, "currency": "GBP"}, "net": {"minor": 150, "currency": "GBP"}}], "applied": [{"id": "p1", "groups": 1, "discount": {"minor": 150, "currency": "GBP"}}], "subtotal": {"minor": 300, "currency": "GBP"}, "discount": {"minor": 150, "currency": "GBP"}, "total": {"minor": 150, "currency": "GBP"}}},
  {"name": "an empty basket is an error", "args": [[], [{"id": "bogof-cola", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expectError": "a basket needs at least one line"},
  {"name": "mixed currencies are an error", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 1}, {"sku": "BIER", "unitPrice": {"minor": 200, "currency": "EUR"}, "quantity": 1}], []], "expectError": "currency mismatch: GBP and EUR"},
  {"name": "a free-items offer with every item free is an error", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 2}], [{"id": "bad", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 2, "basisPoints": 0, "amount": null}]], "expectError": "promotion \"bad\": freeItems must be from 1 to groupSize - 1"},
  {"name": "a group price without an amount is an error", "args": [[{"sku": "MEAL", "unitPrice": {"minor": 399, "currency": "GBP"}, "quantity": 3}], [{"id": "deal", "kind": "group-price", "skus": ["MEAL"], "groupSize": 3, "freeItems": 0, "basisPoints": 0, "amount": null}]], "expectError": "promotion \"deal\" needs an amount"},
  {"name": "a zero quantity is an error", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 0}], []], "expectError": "quantity must be 1 or more"},
  {"name": "duplicate promotion ids are an error", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 2}], [{"id": "p1", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "p1", "kind": "percent-off", "skus": ["COLA"], "groupSize": 1, "freeItems": 0, "basisPoints": 1000, "amount": null}]], "expectError": "duplicate promotion id \"p1\""},
  {"name": "seven offers competing for the same items is an error", "args": [[{"sku": "COLA", "unitPrice": {"minor": 150, "currency": "GBP"}, "quantity": 2}], [{"id": "p1", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "p2", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "p3", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "p4", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "p5", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "p6", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}, {"id": "p7", "kind": "free-items", "skus": ["COLA"], "groupSize": 2, "freeItems": 1, "basisPoints": 0, "amount": null}]], "expectError": "more than 6 promotions compete for the same items"}
]