In Watch Your Test Fail First, your tests for Nadia’s refund failed on main for the right reason, and in the last exercise yours caught every broken stock adjustment. Grace now has a request that needs every step of this course at once.
In this project, you’ll take one sentence from Grace to a verdict on a change someone else wrote. You’ll write the intent, criteria, and tests yourself, and only then judge the gift card pull request Quill has opened. Start with what Grace asked for, and with what the shop can already do.
Read Grace’s Request
Grace’s message is one line long:
Customers buy one, and spend it over several visits.
The shop has never sold gift cards, but its code already has room for them. Start from main, the way you started refund-tests. In your second-draft-books folder, check for a clean tree first, so nothing uncommitted travels with the switch:
$ git status
On branch refund-tests
nothing to commit, working tree clean
$ git switch main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ npm run seed
You may be on another branch. If git status lists a changed file, commit it on the branch you’re on, or undo it with git restore, before you switch. Then open data/seed.json. Its last record is a card nobody can spend yet:
data/seed.json
"giftCards": [{ "code": "GIFT-1000", "originalValue": 1000, "balance": 1000 }]
The payment code already has a place for a second tender, or payment method. This is the whole of payOrder() on main:
src/payments/charges.js
export function payOrder(state, order) {
let charge = chargeWithRetry(state, order);
order.chargeId = charge.id;
order.cardPaid = order.total;
order.giftPaid = 0;
return charge;
}
Every order records cardPaid and giftPaid, and giftPaid is always 0. In the same way, refundDestination() in src/refunds/destination.js returns { card: refund.amount, gift: 0 }, so every refund goes back to the ordinary card. The gift card fields are there, but they aren’t used yet. You can leave the retry and gateway code behind chargeWithRetry() unread, since it charges the ordinary card.
Quill, the team’s AI coding agent, has already opened a pull request for gift cards: #31, on the branch quill/gift-cards. Leave it unread for now. If you read Quill’s code first, its choices become your answers to Grace’s questions, and you’d be checking the change against itself.
For this project, take how an order names a card as fixed, so that your tests can run against any gift card change. An order’s input gets giftCode, the card’s code, and an optional giftAmount, the amount to take from the card in whole pence. Everything else about the behavior is Grace’s to decide.