Your Evidence section in map.md ends in “Not checked” lines. Before anyone signs off, you either close each one with a check or name it in the sign-off as a risk that remains. A check you design after seeing the result tends to agree with what you saw. A check is evidence only if a wrong version of the code would have failed it.
In this lesson, you’ll take one claim on quill/gift-cards-v2, list the ways it could break, and write down what each attempt should show before you run it. You’ll run two of the attempts that threaten money and turn one into a saved test. The principle is to decide what would convince you before you look and aim your checks where a wrong version would fail. Start with what’s already covered.
Start Where the Author Stopped
An author’s own example is the case they’ve already run, so running it again tells you little. Grace’s criterion in docs/REQUESTS.md says that “a zero balance means no further spend is allowed.” Quill’s pull request #32 claims that exhausted cards and spends above a balance decline, and Edsger’s tests include both.
You also have your own test from Intent and Acceptance. Test 4, “a card at zero is declined,” empties GIFT-1000 on The Long Way Home and checks that the next order is refused. In that course, you learned to see a test fail first, and test 4 failed on quill/gift-cards before v2 fixed the gap.
Count all of that as covered. Confirming the author’s examples doesn’t check the change, because the bugs live in the cases nobody thought of.
To find the other cases, ask what should happen when something around the claim changes:
- Input: A different amount from the one the author tried
- Timing: The same action earlier, later, or at a limit
- Repetition: The same action again, on the state the first one left
- Outside failure: A failure elsewhere after the function has done its work
A gift card has no deadline, so none of the attacks below needs timing.
An attack is a run aimed at one of those changes, and it counts only if its expected result is written down before you run it. Here are five attacks, added under the claim in map.md. They widen the zero rule to the spend it guards, and they’re ranked by what a wrong version would cost:
Attacks on "a card pays only what it holds, and nothing at zero"
1. Outside: the change throws after spendGiftCard().
Expect: nothing saved, GIFT-1000 still 1000p.
Threatens: money in equals money out.
2. Input: 1001p from GIFT-1000 at 1000p, one penny over.
Expect: "Gift payment exceeds balance", still 1000p.
Threatens: money in equals money out.
3. Outside: the gateway declines the card remainder.
Expect: nothing saved, GIFT-1000 untouched.
Threatens: money in equals money out.
4. Input: exactly 1000p from GIFT-1000 on book-2.
Expect: saved, giftPaid 1000, balance 0.
Threatens: no money, but a good customer turned away.
5. Repetition: a second order on the emptied card.
Expect: "Gift card is exhausted".
Threatens: the zero rule, close to test 4.
The first three target failures that would move money incorrectly, so they take priority. Edsger’s test tries to spend 750p on a 200p balance. Attacks 2 and 4 check the boundary it doesn’t reach: one penny above the balance and exactly at it.
Before you run any of them, read the code they aim at. On quill/gift-cards-v2, open src/payments/gift-cards.js and find spendGiftCard(), lines 30 to 40, shown here with line 34 wrapped: