Test the checkout code; publish images only for releases (#5)
- src/checkout/ (PayPal order request, pricing, VAT) and src/logging/format.ts hold the checkout's pure code, moved out of PayPalApi, the product service and config without a behaviour change. - npm test runs node:test on the TypeScript sources (type stripping), with no dependencies: 21 tests, 13 pin today's output, 8 describe the correct behaviour for the known defects of libretech/mp#67 and are marked todo. - CI: the tests run in the image's base (node:22.14.0-alpine) for every pull request, push to main and release tag. The image is built for pull requests and built and published only for v* tags; main no longer publishes :main and :sha-* images. Refs libretech/mp#71 Co-authored-by: Michael Czechowski <mail@librete.ch>
This commit was merged in pull request #5.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { calculateTotalProductPrice } from "../../src/checkout/pricing.ts";
|
||||
|
||||
// Characterization: what calculateTotalProductPrice returns today.
|
||||
|
||||
test("adds up the cover, pages and ruling prices", () => {
|
||||
assert.equal(calculateTotalProductPrice({ cover: { price: 14.9 }, pages: { price: 3 }, ruling: { price: 0.5 } }), 18.4);
|
||||
});
|
||||
|
||||
test("prices a standalone product from its cover alone", () => {
|
||||
assert.equal(calculateTotalProductPrice({ cover: { price: 9.5 } }), 9.5);
|
||||
});
|
||||
|
||||
test("counts a missing component or price as 0", () => {
|
||||
assert.equal(calculateTotalProductPrice({ cover: null, pages: { price: null }, ruling: undefined }), 0);
|
||||
});
|
||||
|
||||
test("returns 0 for a missing product instead of throwing", () => {
|
||||
assert.equal(calculateTotalProductPrice(null), 0);
|
||||
assert.equal(calculateTotalProductPrice(undefined), 0);
|
||||
});
|
||||
|
||||
test("does not round the sum", () => {
|
||||
assert.equal(calculateTotalProductPrice({ cover: { price: 0.1 }, pages: { price: 0.2 } }), 0.30000000000000004);
|
||||
});
|
||||
Reference in New Issue
Block a user