Give a Verdict the Author Can Use

In the last exercise, you planned a thirty-minute review and wrote a triage note saying what you’d read closely and what you’d skim. But the author is waiting for comments on specific lines and a decision they can act on.

In this lesson, you’ll write review comments that say where a problem is, what’s wrong, why it matters, and how much it matters. You’ll end each review with a verdict that follows from those comments and says what you checked. You’ll start with a review the shop already has: Edsger’s note on pull request #24.

Point at the Line and Say Why It Matters

A review comment is useful when the author can act on it without coming back to ask what you meant. Open docs/pulls/24.md and read Edsger’s review of Margaret’s “tidy up refund totals”:

The ordinary single-book return still passes. I have not tried an order containing a complimentary book. The architecture note wasn’t updated.

Every sentence in it is true, and the second is the most useful line in the file, because it names exactly what he didn’t try. But it doesn’t tell Margaret whether anything is wrong. A comment like this, or like “The refund logic here looks wrong,” points toward a problem and leaves the author to guess the rest, so the fix misses the point or the comment gets ignored.

So review #24 as if it were still open, starting from its intent. Margaret’s description calls it a tidy-up that uses “the subtotal shown in the staff record,” so it shouldn’t change any refund. Here’s its diff:

Language: Shell
$ git show --oneline 2f48539 -- src/refunds/allocation.js
2f48539 tidy up refund totals (review #24)
diff --git a/src/refunds/allocation.js b/src/refunds/allocation.js
index 58bd604..270aeb0 100644
--- a/src/refunds/allocation.js
+++ b/src/refunds/allocation.js
@@ -1,7 +1,7 @@
 // Attribute the amount actually paid to the books being returned.
 // Complimentary books have a catalogue value but contributed no payment.
 export function refundValue(order, returnedValue) {
-    let denominator = order.paidItemsSubtotal;
+    let denominator = order.grossSubtotal;
     if (denominator === 0) return 0;
     return Math.round(order.total * returnedValue / denominator);
 }

The comment on lines 1 and 2 says the customer paid nothing for complimentary books. The new line 4 selects a subtotal whose name doesn’t say whether they’re in it. If you aren’t sure what the two subtotals hold, the button below sends Code Mentor the diff with this question:

Check its answer against the data. Lines 28 to 33 of data/seed.json list the three books in order-1, one of them complimentary, and its two subtotals.

Then run the case Edsger didn’t try. Your fix from the second course stayed on its own branch, so main still has #24’s line. From your second-draft-books folder, run npm run seed. Then run the check you saved in that course, node ~/checks/refund.mjs, or node $HOME\checks\refund.mjs in Windows PowerShell. If you don’t have it, save it from here first:

Language: JavaScript Filename: ~/checks/refund.mjs
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';

const file = resolve('src/refunds/create.js');
const refunds = await import(pathToFileURL(file));

const text = await readFile('data/seed.json', 'utf8');
const state = JSON.parse(text);

const refund = refunds.createRefund(state, {
    orderId: 'order-1',
    items: [{ bookId: 'book-1', quantity: 1 }]
});
console.log('Expected: 600p');
console.log('Actual: ' + refund.amount + 'p');
process.exitCode = refund.amount === 600 ? 0 : 1;

It imports src/refunds/create.js as a module, returns Small Maps from a fresh copy of order-1, and prints what the refund should be and what it is.

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

Become a Member to join the conversation.