Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Observe Before and After

Grace wants to know whether Quill’s quill/gift-cards-v2 changes anything for customers who never use a gift card. A run is evidence only for what you look at, so you list where a feature writes, copy those places aside before and after the change on the same inputs, and explain every difference.

Key Points

What a script prints is a small part of what the shop did. Nadia Patel’s order of Small Maps with READ20, and its return, print the same two lines on main and on quill/gift-cards-v2.

List where the feature writes before you run it. createOrder() reserves the book, charges the card, saves the order, queues an email, and logs an entry. createRefund() adds the gateway’s refund to the card, the stock it puts back, and the refund record. All eight live in data/shop.json, and the emails also go to outbox/. The call runCommand() makes to settleGateway() is a stub that writes nothing.

Copy those places on the code before the change, too. Seed the shop before each run, so both runs start from the same records. On the branch alone, the new fields would look as if they’d always been there. Give each copy its own name: reusing a name replaces that copy.

Write down what you expect before you compare. git diff --stat main quill/gift-cards-v2 lists 13 changed files, and three are on this run’s path.

In src/storage/commands.js, settleGateway() still gets the order’s id. In src/payments/charges.js, with no gift card, payOrder() keeps main’s cardPaid and giftPaid values and adds three fields to each order it pays.

In src/refunds/destination.js, the refund still sends all 600p to the card. So expect, on order-2, "giftCode": "", "giftRefunded": 0 and "cardRefunded": 600, and nothing else.

Compare the copies with git diff --no-index. Git ignores data/*.json and outbox/*.json. With --no-index, git diff compares any two folders, and it prints only what differs: no outbox/ files means the emails match, and every other place on your list matches too, apart from one hunk in order-2.

There, "giftPaid": 0 only gains a comma. giftCode and giftRefunded match your note, but "cardRefunded" says 0, not the 600 you expected.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Most customers at The Second Draft never use a gift card. Does Quill’s gift card branch change anything for them? That’s Grace’s question. Nadia Patel orders Small Maps with the READ20 code, then returns it.

00:14 A saved script places both, like your outside-failure check. On main, it prints that order-2 paid 600 pence and refund-1 sent 600 back. Quill’s branch prints the same.

00:28 You can’t say nothing changed yet. A run is evidence only for what you look at.

00:35 Before you run anything, list where the feature writes, from createOrder(). It reserves the book, charges the card, saves the order, queues an email, and logs an entry.

00:48 The refund adds the gateway’s refund to the card, the stock it puts back, and the refund record. All eight live in the shop’s data file, and the emails also go to the outbox folder.

01:00 The settleGateway() call in runCommand() is a stub that writes nothing. The printed lines show none of this.

01:08 A second script copies the data file and outbox into a folder named after the run. Start before the change. Switch to main, seed the shop so both runs start from the same records, run the order, and save the copy as main.

01:24 Why copy main at all? On Quill’s branch alone, the new fields would look as if they’d always been there. Then repeat the four steps on Quill’s branch, saving the copy as v2.

01:39 First, write down what you expect. Three of thirteen changed files are on this run’s path. settleGateway() still gets the order’s id. With no gift card, payOrder() keeps its old values and adds three fields.

01:52 The refund sends all 600 to the card, so cardRefunded should say 600.

01:59 Git ignores the shop’s data and outbox files. The no-index option lets git diff compare any two folders. It prints only what differs. The outbox doesn’t appear, so the emails match.

02:12 Every place but the orders matches. They differ in one hunk, on Nadia’s order, paid 600 by card.

02:21 giftPaid only gains a comma. giftCode and giftRefunded match your note. But cardRefunded says zero.

02:31 Is each difference intended? Pull request 32 states the intent: refunds go back to the original tenders. Refunds need each tender’s share, so payOrder() records the gift card’s, even as an empty code and zero.

02:46 That fits the intent. cardRefunded doesn’t match your note. The gateway sent Nadia’s card 600. With no gift card, refundDestination() returns on line 7, before line 23 updates the field.

03:01 A search finds one read, on line 11, below that early return, so only gift card orders use it. Nadia sees no change. But pull request 32 doesn’t explain the zero.

03:13 That’s a question for Quill.

03:17 A diff can’t show whether either version is right. And no error doesn’t mean the money rule held: wrong code could save a refund bigger than the payment, and nothing would complain.

03:29 So check the rule against the stored data. A third script adds up the gateway refunds on each order’s card payment, and compares the refunds with what was paid.

03:39 On v2, order-2 refunded 600 of 600, and the card got 600 of 600. The rule held.

03:49 In your map, keep observed apart from assumed. You observed one ordinary order and its return, which showed three new fields and a refund within what was paid.

04:00 You didn’t observe the staff desk, a partial return, several books, or a different discount code, or none. Those stay assumed. Grace’s answer for this order is no change Nadia sees, plus one question for Quill.

04:16 A run is evidence only for what you look at. So list where a feature writes, copy those places before and after on the same inputs, and explain every difference.

04:28 In Exercise: Explain Every Difference, you’ll compare two runs and decide which differences a change meant to make.

Become a Member to join the conversation.