Compare commits

4 Commits
Author SHA1 Message Date
libretech 707ca854fb ci: run the unit tests, and build images only for pull requests and releases
build / test (pull_request) Failing after 15s
build / build (pull_request) Skipped
Every push to main published :main and :sha-* images, which nothing pulls.
The libreshop images had grown to 5.8 GB in the registry, on a Gitea host that
is nearly out of space.

- test: npm test on Node 22.14.0, the Node of the image, for every pull
  request, every push to main and every release tag.
- build: after the tests, for a pull request (build only) and for a v* tag
  (build and, with PUBLISH_ENABLED, publish :vX.Y.Z and :latest).

Refs libretech/mp#71
2026-10-08 22:26:46 +02:00
libretech cbcc54bd75 test(checkout): add dependency-free unit tests that pin the checkout defects
npm test runs node:test on the TypeScript sources with Node's type stripping
(Node 22.14 in the image, Node 24 locally), with no dependencies.

Node, unlike tsc, does not resolve extensionless relative imports. TypeScript
5.2 cannot emit .ts import extensions. tests/unit/support therefore registers
a small resolve hook that appends ".ts" for imports from .ts files.

- pricing, paypal-order, log-format: characterization tests of the current
  output.
- The known defects of
  libretech/mp#67 are tests of the correct
  behaviour, marked todo: null, two-line and price-null addresses and
  deliveries, a deleted product, the payment surcharge missing from the
  breakdown, and in the log line circular JSON, the Basic credentials of an
  axios error, and an Error rendered as {}.
- That the breakdown adds up to the amount holds today, including for the
  subtotals closest to a half cent, so that test is a regular one.

Refs libretech/mp#71
2026-10-08 22:15:57 +02:00
libretech 7fd4aeff17 refactor(logging): move the console line format into src/logging/format.ts
The printf template of config/logger.ts becomes formatLogLine, with the same
logic, so it can be unit tested without winston.

No behaviour change.

Refs libretech/mp#71
2026-10-08 22:10:28 +02:00
libretech 9873c184d6 refactor(checkout): move VAT rates, pricing and the PayPal order into pure modules
src/checkout/ holds code without the PayPal SDK or Strapi at runtime, so it can be
unit tested without node_modules:

- vat.ts: vatIncludedDecimal and vatDecimal. config/constants.ts re-exports them
  under the same names and keeps vatDecimalExcluded.
- pricing.ts: calculateTotalProductPrice, unchanged. The product service
  re-exports it, so every importer keeps working.
- paypal-order.ts: the order request createSessionOrThrow builds, in two halves.
  buildPayPalOrderItems (the total guard and the unsent items) still runs
  before the try block, and buildPayPalOrderRequest inside it. Errors and log
  lines stay as they were, for every input. The SDK enums are replaced by their
  string values (CAPTURE, SET_PROVIDED_ADDRESS).

No behaviour change.

Refs libretech/mp#71
2026-10-08 22:10:28 +02:00
+8 -7
View File
@@ -16,13 +16,14 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
# The tests need no dependencies. They run in the image's base (Dockerfile FROM), so on the runtime's Node, # The Node version of the image (Dockerfile FROM), so the tests run on the runtime's Node.
# without network. The source is piped in because the job container's paths do not exist on the Docker host. - uses: actions/setup-node@v4
- name: npm test, on the Node of the image with:
run: | node-version: "22.14.0"
base=$(sed -n 's/^FROM \([^ ]*\).*/\1/p' Dockerfile | head -1)
tar -c --exclude=.git . | docker run -i --rm --network none -e npm_config_update_notifier=false "$base" \ - run: npm test
sh -c 'mkdir /w && cd /w && tar -x && npm test' env:
npm_config_update_notifier: "false"
# The image is built to check a pull request, and built and published only for a release tag. # The image is built to check a pull request, and built and published only for a release tag.
# Nothing pulls per-commit images, so main no longer publishes :main and :sha-* images. # Nothing pulls per-commit images, so main no longer publishes :main and :sha-* images.