Functional Weave
Code in TypeScript

retail.gift-card-balance@1.0.0

vectors.json

3,057 bytes · view raw

[
  {"name": "the card covers the bill and keeps the change", "args": [{"minor": 5000, "currency": "GBP"}, {"minor": 3000, "currency": "GBP"}], "expect": {"applied": {"minor": 3000, "currency": "GBP"}, "remainingBalance": {"minor": 2000, "currency": "GBP"}, "stillDue": {"minor": 0, "currency": "GBP"}, "fullyPaid": true}},
  {"name": "partial redemption: the card is emptied and the rest is still due", "args": [{"minor": 2000, "currency": "GBP"}, {"minor": 3550, "currency": "GBP"}], "expect": {"applied": {"minor": 2000, "currency": "GBP"}, "remainingBalance": {"minor": 0, "currency": "GBP"}, "stillDue": {"minor": 1550, "currency": "GBP"}, "fullyPaid": false}},
  {"name": "balance equal to the bill empties the card exactly", "args": [{"minor": 2500, "currency": "GBP"}, {"minor": 2500, "currency": "GBP"}], "expect": {"applied": {"minor": 2500, "currency": "GBP"}, "remainingBalance": {"minor": 0, "currency": "GBP"}, "stillDue": {"minor": 0, "currency": "GBP"}, "fullyPaid": true}},
  {"name": "one penny short leaves one penny to pay", "args": [{"minor": 999, "currency": "GBP"}, {"minor": 1000, "currency": "GBP"}], "expect": {"applied": {"minor": 999, "currency": "GBP"}, "remainingBalance": {"minor": 0, "currency": "GBP"}, "stillDue": {"minor": 1, "currency": "GBP"}, "fullyPaid": false}},
  {"name": "an empty card pays nothing", "args": [{"minor": 0, "currency": "GBP"}, {"minor": 1000, "currency": "GBP"}], "expect": {"applied": {"minor": 0, "currency": "GBP"}, "remainingBalance": {"minor": 0, "currency": "GBP"}, "stillDue": {"minor": 1000, "currency": "GBP"}, "fullyPaid": false}},
  {"name": "nothing due leaves the balance alone", "args": [{"minor": 5000, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}], "expect": {"applied": {"minor": 0, "currency": "GBP"}, "remainingBalance": {"minor": 5000, "currency": "GBP"}, "stillDue": {"minor": 0, "currency": "GBP"}, "fullyPaid": true}},
  {"name": "both zero", "args": [{"minor": 0, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}], "expect": {"applied": {"minor": 0, "currency": "GBP"}, "remainingBalance": {"minor": 0, "currency": "GBP"}, "stillDue": {"minor": 0, "currency": "GBP"}, "fullyPaid": true}},
  {"name": "yen has no minor unit, same arithmetic", "args": [{"minor": 3000, "currency": "JPY"}, {"minor": 4500, "currency": "JPY"}], "expect": {"applied": {"minor": 3000, "currency": "JPY"}, "remainingBalance": {"minor": 0, "currency": "JPY"}, "stillDue": {"minor": 1500, "currency": "JPY"}, "fullyPaid": false}},
  {"name": "a negative balance is an error", "args": [{"minor": -1, "currency": "GBP"}, {"minor": 1000, "currency": "GBP"}], "expectError": "balance must not be negative"},
  {"name": "a negative amount due is an error, not a silent top-up", "args": [{"minor": 1000, "currency": "GBP"}, {"minor": -500, "currency": "GBP"}], "expectError": "amountDue must not be negative"},
  {"name": "a euro card cannot pay a sterling bill", "args": [{"minor": 1000, "currency": "EUR"}, {"minor": 500, "currency": "GBP"}], "expectError": "currency mismatch: GBP and EUR"}
]