diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 340fb8d..ef24a9e 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -8,7 +8,27 @@ on: branches: [main] jobs: + test: + runs-on: ubuntu-latest + container: + image: git.librete.ch/public/runner-image:v0.2.0@sha256:f60c587d3c0b0aac04a572db5349e27672bf76baec2ce547a3dcc28cebcf1b7e + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + + # The tests need no dependencies. They run in the image's base (Dockerfile FROM), so 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. + - name: npm test, on the Node of the image + run: | + 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" \ + sh -c 'mkdir /w && cd /w && tar -x && npm test' + + # 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. build: + needs: test + if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest container: image: git.librete.ch/public/runner-image:v0.2.0@sha256:f60c587d3c0b0aac04a572db5349e27672bf76baec2ce547a3dcc28cebcf1b7e @@ -21,4 +41,4 @@ jobs: registry: ${{ secrets.REGISTRY }} registry_user: ${{ secrets.REGISTRY_USER }} registry_pass: ${{ secrets.REGISTRY_PASS }} - publish: ${{ github.event_name == 'push' && vars.PUBLISH_ENABLED == 'true' }} + publish: ${{ startsWith(github.ref, 'refs/tags/v') && vars.PUBLISH_ENABLED == 'true' }} diff --git a/README.md b/README.md index 74f0a17..8dbe81d 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ Vue/Nuxt-style storefront base. Part of the [libreshop](https://git.librete.ch/libreshop) toolkit. Image -published at `git.librete.ch/libreshop/shop` on every push to `main` -and on `v*` tags. +published at `git.librete.ch/libreshop/shop` on `v*` tags; pull requests +build it without publishing. ## Source @@ -18,6 +18,11 @@ pulls `git.librete.ch/libreshop/shop:` instead of building locally. docker build -t libreshop/shop:dev . ``` +## Test + +`npm test` runs the unit tests in `tests/unit/` on Node 22.6 or later, without +installing dependencies. + ## Adapter contract See `docker-entrypoint.sh` and `Dockerfile` for the runtime surface. diff --git a/components/Input.vue b/components/Input.vue index 6be8034..8f47616 100644 --- a/components/Input.vue +++ b/components/Input.vue @@ -5,6 +5,7 @@ {{ label }} (), { - autocomplete: "off" + autocomplete: "off", + type: "text" } ); diff --git a/composables/useShopApi.ts b/composables/useShopApi.ts index 1baa4fe..c0f8877 100644 --- a/composables/useShopApi.ts +++ b/composables/useShopApi.ts @@ -9,6 +9,7 @@ import type { PaymentMethod, ApiResponse } from "~/types"; +import type { AlreadyCaptured } from "~/utils/captureResponse"; /** * Shop API composable. @@ -116,8 +117,9 @@ export function useShopApi() { }); }, - async capturePayment(uuid: string, paypalOrderId: string): Promise { - return await $fetch(`/api/orders/${uuid}/capture/${paypalOrderId}`, { + /** The paid order, or { success: true, alreadyCaptured: true } when an earlier capture of this PayPal order went through. */ + async capturePayment(uuid: string, paypalOrderId: string): Promise { + return await $fetch(`/api/orders/${uuid}/capture/${paypalOrderId}`, { method: "POST" }); }, diff --git a/nuxt.config.ts b/nuxt.config.ts index d225b10..9e04544 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -29,6 +29,7 @@ export default defineNuxtConfig({ // Server-only (private) - never exposed to client shopApiToken: "", // NUXT_SHOP_API_TOKEN cmsInternalUrl: "http://cms:5555", // NUXT_CMS_INTERNAL_URL - internal docker network URL + mailApiUrl: "http://mail:2222", // NUXT_MAIL_API_URL - mail service (libreshop/mail) on the internal docker network siteUrl: "https://muellerprints-paperwork.com", // NUXT_SITE_URL - for sitemap // Public (client + server) @@ -72,7 +73,11 @@ export default defineNuxtConfig({ // TypeScript typescript: { - strict: true + strict: true, + // The unit tests run on Node (npm test), not in the app: keep them out of the app's type check (.nuxt/tsconfig.app.json). + tsConfig: { + exclude: ["../tests/**/*"] + } }, // Tailwind diff --git a/package.json b/package.json index befa466..d75fce2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "dev": "nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", - "postinstall": "nuxt prepare" + "postinstall": "nuxt prepare", + "test": "node --experimental-strip-types --import ./tests/unit/support/register.mjs --test 'tests/unit/**/*.test.ts'" }, "dependencies": { "@headlessui/vue": "^1.7.23", diff --git a/pages/checkout/1.vue b/pages/checkout/1.vue index 3d59010..0b0ffc3 100644 --- a/pages/checkout/1.vue +++ b/pages/checkout/1.vue @@ -29,7 +29,7 @@
- +
@@ -60,6 +64,7 @@