Weigh the Evidence for a Claim

Grace’s question can wait for now. Before you can say whether a change is ready to go live, you need to know what each piece of evidence is worth. A tidy description, a careful read, an order that went through, and a green suite can all feel like proof, and each one proves less than it feels.

You’ll gather each kind of evidence the shop offers for Quill’s spending and refund claims and say what it can and can’t rule out, then decide how much evidence two very different changes need. The principle is that evidence counts for exactly what it covers, and how much you need follows from the risk. Start with the claim and the code it’s about.

Read and Run One Claim

Every review starts from somebody’s claim, so first find out what a claim alone is worth. This lesson’s claim comes from Quill’s pull request #32, on quill/gift-cards-v2. It’s the gift card branch from Intent and Acceptance with your report’s two gaps fixed, and Margaret’s refunds build on it, though her branch stays closed until the course project.

This course uses the second-draft-books clone, the map.md beside it, and the ~/checks/ folder you’ve built up since the first course on The Second Draft. It also assumes Intermediate JavaScript: modules, nested data, higher-order functions, classes, and custom errors. Put the shop on Quill’s branch:

If you took the last course, open a terminal in your second-draft-books folder and run only the last three commands.

If you’re arriving directly, install Git and a current version of Node.js. The examples use Node 26. Then run all the commands, and create an empty map.md in your home folder, outside the repository:

Language: Windows PowerShell
PS> git clone https://github.com/realjs/second-draft-books.git
PS> cd second-draft-books
PS> mkdir $HOME\checks
PS> git status
PS> git switch quill/gift-cards-v2
PS> npm run seed
Language: Shell
$ git clone https://github.com/realjs/second-draft-books.git
$ cd second-draft-books
$ mkdir ~/checks
$ git status
$ git switch quill/gift-cards-v2
$ npm run seed

git status must end with nothing to commit, working tree clean before you switch. If it lists a changed file, commit it on the branch you’re on, or undo it with git restore. After the switch, git log --oneline -1 starts with 7b683f0, and npm run seed prints Restored fictional shop records. No email was sent and no card was charged.

Arriving directly, you won’t have your gift card tests from Intent and Acceptance, so read their results in the next section.

Open docs/pulls/32.md. Quill writes that “exhausted cards and spends above a balance decline,” and that refunds go “to the original tenders,” the gift card and the ordinary card that paid, guarding “both contributions and the issued gift-card value.” Edsger replies that the tests “are examples, not an exhaustive enumeration of sequences.”

A description is its author’s claim, and on its own it rules out nothing. Break it into claims to check, as you did with Code Mentor’s answers in the first course. Quill’s description holds two: spends decline when they should, and refunds go back where they came from, within limits.

Reading the code checks what it says. Here’s the spending half, spendGiftCard(), which runs from line 30 to line 40, shown with line 34 wrapped:

Language: JavaScript Filename: src/payments/gift-cards.js
export function spendGiftCard(state, input, total) {
    if (!input.giftCode) return { amount: 0, code: '' };
    const card = findGiftCard(state, input.giftCode);
    if (card.balance === 0) throw new Error('Gift card is exhausted');
    const amount = input.giftAmount === undefined
        ? Math.min(card.balance, total)
        : input.giftAmount;
    requirePence(amount, 'Gift payment');
    if (amount > total) throw new Error('Gift payment exceeds order');
    if (amount > card.balance) throw new Error('Gift payment exceeds balance');
    card.balance -= amount;
    return { amount, code: card.code };
}

Line 33 declines a card at zero, and line 37 a spend above the balance. The read rules out “the check was never written.” It can’t show what the shop does, and it says nothing about refunds. A careful read also feels stronger than it is, because you run it in your head on the inputs you thought of.

One run shows what the shop does. Start the shop with npm start, open http://127.0.0.1:3000/admin/, and as Nadia Patel, order The Long Way Home with GIFT-1000 in Gift card code and Gift contribution left empty. The desk shows Saved order-2, and the balance list shows GIFT-1000: £0.00. Order one Small Maps with the same card, and the desk answers Gift card is exhausted.

Then, under Return a book, return book-2 from order-2. The desk shows Saved refund-1 · £22.50, and the card is back at GIFT-1000: £10.00. Stop the server with Ctrl+C.

That run is evidence for exactly what you did. You spent one card’s balance down to zero with no amount typed, got one decline, and made one full return. It doesn’t cover an amount you type in at the desk, a partial return, or a second return on the same order.

Count What Tests and Stored Data Cover

A run you did by hand is hard to repeat, so the next two kinds of evidence are ones you can rerun and reread: the tests and the records the shop saves. Start with Edsger’s and Quill’s tests:

Language: Shell
$ npm test

> [email protected] test
> node --test

✔ a gift card can be spent over two visits (2.60654ms)
✔ an exhausted card declines another spend (0.72875ms)
...
ℹ tests 24
ℹ suites 0
ℹ pass 24
ℹ fail 0
...

In Intent and Acceptance, a suite this green let a wrong return through, so read this one as “these examples work as the tests expect.” Its 24 results include test/helpers.js itself, and each is an example someone chose, as Edsger’s reply says. Every gift card refund test returns one book, once.

Your own tests add examples chosen from Grace’s criteria, so they test what was asked for rather than what was built. Copy them in, from the course’s code download if you don’t have them from Intent and Acceptance, then run them and remove the copy so the branch stays as Quill left it:

Language: Shell
$ cp ~/checks/gift-criteria.test.js test/
$ node --test test/gift-criteria.test.js
✔ 1. a card pays part of an order (3.37317ms)
...
✔ 8. a second return rounds the total (0.38424ms)
✔ 9. the desk's amount on a card at zero (0.5806ms)
ℹ tests 9
ℹ suites 0
ℹ pass 9
ℹ fail 0
...
$ rm test/gift-criteria.test.js

All eight criterion tests pass, and so does the desk case you added for Edsger. Your names and count may differ. The tests cover the criteria from your report, including two returns on a split order in test 8. They don’t cover more than two returns, a card’s balance against its .originalValue after several returns, or anything in outbox/.

Observation lets you check what the shop actually wrote. Your desk run left its records in data/shop.json, which no test touches, since each test starts from freshShop(). Search the file for gatewayRefunds:

Language: JSON Filename: data/shop.json
  "gatewayRefunds": [
    {
      "chargeId": "charge-2",
      "amount": 1250,
      "refundId": "refund-1"
    }
  ],

The ordinary card got 1250p back through the gateway, which the desk never showed. order-2 records "giftRefunded": 1000 and "cardRefunded": 1250, the gift card’s .balance is back at its .originalValue of 1000, and outbox/email-2.json tells Nadia that £22.50 came back, without saying where it went.

Observation rules out a page that disagrees with what’s stored, but it covers only the orders you put through.

Code Mentor’s answers are one more kind of evidence, as specific as the code you give it. Lines 19 to 21 of refundDestination() are where a refund reaches the gift card. The button under them sends these lines, shown with line 19 wrapped, to Code Mentor with a question:

Language: JavaScript Filename: src/refunds/destination.js
if (giftCard.balance + gift > giftCard.originalValue)
    throw new Error('Gift card exceeds issued value');
returnPayment(state, order.chargeId, card, refund.id);
giftCard.balance += gift;

A confident answer is a set of claims, worth no more than Quill’s description until you check it. “No, line 19 throws before line 21 adds to the balance” holds two claims. These lines support the first, a guard on this write path.

The second, that nothing else raises a balance, needs a search. Your desk run supports one full return, and sequences of more than two returns stay unchecked.

Match the Evidence to the Risk

You can’t gather every kind of evidence for every change, so the risk decides how far you go. In Reviewing Changes by Risk, you approved Edsger’s #40, which changes one heading on the staff desk from “Retuned” to “Returned.”

That change touches no data and no money, and a revert undoes it completely. The one-line diff, a search for the old word, a look at the page, and npm test were enough.

A gift card change carries more risk. The money moves between two tenders, the shop stores where it went, and a refund sent through the gateway can’t be taken back with a revert.

No amount of reading, testing, or observation covers every sequence, so the risk decides which ones to aim at. Grace’s limits name them. Her criteria talk about what happens “across several returns” and a balance that must “never exceed” its issued value. For a gift card change, you need to make several returns from one split order and read its stored records after each. No test asserts that, so your map marks it not checked.

A right total can hide a wrong split, so that check compares each tender’s refunds against what it paid and the card’s balance against .originalValue. It also compares the total refunded against the payment, which it must never exceed and must equal once every book is back. A sequence worth observing is worth saving as a test, so you can rerun it.

Your evidence for #32 is good, and it still isn’t enough for Grace’s balance limit. Add an Evidence section to map.md and record each claim. Write down only the checks you ran, with your own test names and counts, and mark any result you only read here as “reported”:

Language: Markdown Text
## Evidence

### quill/gift-cards-v2 (pull #32)
Claim: exhausted cards and over-balance spends decline
- Read: spendGiftCard(), lines 33 and 37
- Ran: desk, Small Maps on GIFT-1000 at £0.00 declined
- Tests: npm test 24 of 24, mine 9 of 9 (test 4)
- Not checked: a contribution typed into the desk form
Claim: refunds go back to the original tenders, within limits
- Read: refundDestination(), lines 19 to 21, the
  issued-value guard
- Ran: desk return of order-2, 1000p to the card,
  1250p in gatewayRefunds, £22.50 in outbox/email-2.json
- Tests: mine 5, 6 and 8, the suite's three gift refund tests
- Not checked: tender split (lines 13 to 18), more than
  two returns, the balance against originalValue after
  several returns, refund emails for partial returns

Before anyone signs off on a gift card change, each “Not checked” line is either closed by a check or named in the sign-off as a risk that remains.

To weigh a change of your own, write your decision first, naming the change, its risk, your evidence, the gap, and whether that’s enough. The button below asks Code Mentor to push back like a senior colleague. Paste your decision, then revise it with the check you’d add:

Check Your Understanding

Answer these from what you ran and read:

  1. Oliver Reed pays for one Small Maps entirely with GIFT-1000 at the desk, returns it, and sees the card back at £10.00. What does that run show, and what are three things it doesn’t?
  2. Open test/gift-refunds.test.js and read the test “a partial return allocates a share to each tender,” lines 16 to 22. It passes. What does its assertion rule out, and what does it leave open?
  3. Code Mentor tells you the branch can’t push a card above its original value, because refundDestination() checks the issued value before it adds anything. What do you do with that answer before it goes into your map?
  4. One change rewords the refund email’s subject line in src/email/templates.js. Another changes how refundDestination() rounds the gift card share. Which kinds of evidence does each need, and why?
  1. The run shows that a gift-only order of one book, returned in full, puts 750p back on the card. It doesn’t cover a split payment, a partial return, a second return, or an amount you type in at the desk. It repeats the “a gift-only return” test’s example, but adds the path the test skips: the desk form, the server, and the stored records.
  2. Its one assertion rules out a wrong split for one example: 1000p from the gift card on Small Maps and The Long Way Home, Small Maps returned, a destination of 250p to the gift card and 500p to the ordinary card. It asserts nothing about the card’s stored balance or .gatewayRefunds and leaves open the second return and any other basket.
  3. Split it into claims, as you did with Code Mentor’s refund answer. Lines 19 and 21 support the guard on this write path. The word “can’t” assumes no other code raises a balance, which a search for balance checks. A run shows only the sequences you tried. Record each claim with what supports it.
  4. The subject line touches no money, and a revert undoes it, so read the diff, then issue one refund and read its record in outbox/. The rounding change moves money that a revert can’t bring back, so it needs tests and observation, with realistic orders returned in several steps and the stored refunds checked against what each tender paid.

The next item is the course’s first coding exercise, and it runs in your browser rather than in your clone. You change the file in the editor, then click Run Tests to have automated tests check it. A failing test’s message is a clue to what to change next, and Full screen gives the editor the whole window. The Contents tab, below the editor, explains the rest.

In Exercise: Match the Evidence to the Risk, you’ll decide whether the evidence for a handful of shop changes is enough for each one’s risk.

Become a Member to join the conversation.