@shopbite-de/storefront 1.31.0 → 1.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,7 +65,7 @@ jobs:
65
65
  - name: Install pnpm
66
66
  uses: pnpm/action-setup@v6
67
67
  with:
68
- version: 12.5.1
68
+ version: 12.9.1
69
69
 
70
70
  - name: Install Node.js
71
71
  uses: actions/setup-node@v7
@@ -25,7 +25,7 @@ jobs:
25
25
 
26
26
  - uses: pnpm/action-setup@v6
27
27
  with:
28
- version: 12.5.1
28
+ version: 12.9.1
29
29
 
30
30
  - uses: actions/setup-node@v7
31
31
  with:
@@ -69,7 +69,7 @@ jobs:
69
69
 
70
70
  - uses: pnpm/action-setup@v6
71
71
  with:
72
- version: 12.5.1
72
+ version: 12.9.1
73
73
 
74
74
  - uses: actions/setup-node@v7
75
75
  with:
@@ -105,7 +105,7 @@ jobs:
105
105
 
106
106
  - uses: pnpm/action-setup@v6
107
107
  with:
108
- version: 12.5.1
108
+ version: 12.9.1
109
109
 
110
110
  - uses: actions/setup-node@v7
111
111
  with:
@@ -9,11 +9,12 @@ const route = useRoute();
9
9
  // out of client-side navigations (#314).
10
10
  const { data: page, error } = await useAsyncData(
11
11
  `landingpages-${route.path}`,
12
- () => $fetch("/api/content/page", { query: { path: route.path } }),
12
+ async () =>
13
+ (await $fetch("/api/content/page", { query: { path: route.path } })).page,
13
14
  );
14
15
 
15
16
  // A failing content server is a real error and stays fatal (logged); 4xx
16
- // means there is no such page (the route rejects over-long paths with 400).
17
+ // means there is no content page (the route rejects over-long paths with 400).
17
18
  if ((error.value?.statusCode ?? 0) >= 500) {
18
19
  throw createError({
19
20
  statusCode: 500,
package/container CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopbite-de/storefront",
3
- "version": "1.31.0",
3
+ "version": "1.31.1",
4
4
  "main": "nuxt.config.ts",
5
5
  "description": "Shopware storefront for food delivery shops",
6
6
  "keywords": [
@@ -69,7 +69,7 @@
69
69
  "tailwindcss": "^4.3.3",
70
70
  "typescript": "^6.0.3",
71
71
  "vitest": "^5.0.1",
72
- "vue-tsc": "3.3.11"
72
+ "vue-tsc": "3.3.12"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "nuxt build",
File without changes
@@ -1,7 +1,8 @@
1
1
  import { queryCollection } from "@nuxt/content/server";
2
2
 
3
- // Landing page (content/*.md) by route path; see home.get.ts for why the
4
- // pages do not query the collection in the browser (#314).
3
+ // Landing page (content/*.md) by route path, `page: null` if there is none;
4
+ // see home.get.ts for why the pages do not query the collection in the
5
+ // browser (#314).
5
6
  export default defineEventHandler(async (event) => {
6
7
  const { path } = getQuery(event);
7
8
 
@@ -9,14 +10,10 @@ export default defineEventHandler(async (event) => {
9
10
  throw createError({ statusCode: 400, statusMessage: "Invalid path" });
10
11
  }
11
12
 
13
+ // No content page is a regular answer, not an error: the catch-all asks
14
+ // here first for every category page, and a 404 would show up as a failed
15
+ // request in the browser console and the RUM data on each navigation.
12
16
  const page = await queryCollection(event, "landingpages").path(path).first();
13
17
 
14
- if (!page) {
15
- throw createError({
16
- statusCode: 404,
17
- statusMessage: `Page ${path} not found!`,
18
- });
19
- }
20
-
21
- return page;
18
+ return { page: page ?? null };
22
19
  });
@@ -0,0 +1,74 @@
1
+ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ type Handler = (event: { query: Record<string, unknown> }) => Promise<unknown>;
4
+
5
+ const { mockFirst, mockPath, mockQueryCollection } = vi.hoisted(() => {
6
+ const mockFirst = vi.fn();
7
+ const mockPath = vi.fn(() => ({ first: mockFirst }));
8
+ const mockQueryCollection = vi.fn(() => ({ path: mockPath }));
9
+ return { mockFirst, mockPath, mockQueryCollection };
10
+ });
11
+
12
+ vi.mock("@nuxt/content/server", () => ({
13
+ queryCollection: mockQueryCollection,
14
+ }));
15
+
16
+ // Nitro auto-imports of the route, reduced to what it uses.
17
+ vi.stubGlobal("defineEventHandler", (handler: Handler) => handler);
18
+ vi.stubGlobal(
19
+ "getQuery",
20
+ (event: { query: Record<string, unknown> }) => event.query,
21
+ );
22
+ vi.stubGlobal(
23
+ "createError",
24
+ (input: { statusCode: number; statusMessage: string }) =>
25
+ Object.assign(new Error(input.statusMessage), input),
26
+ );
27
+
28
+ let handler: Handler;
29
+
30
+ beforeAll(async () => {
31
+ // With the stubs above the default export is the plain handler function.
32
+ handler = (await import("../../server/api/content/page.get"))
33
+ .default as unknown as Handler;
34
+ });
35
+
36
+ beforeEach(() => {
37
+ vi.clearAllMocks();
38
+ });
39
+
40
+ describe("GET /api/content/page", () => {
41
+ it("returns the content page of the path", async () => {
42
+ const page = { path: "/agb", title: "AGB" };
43
+ mockFirst.mockResolvedValue(page);
44
+
45
+ await expect(handler({ query: { path: "/agb" } })).resolves.toEqual({
46
+ page,
47
+ });
48
+ expect(mockQueryCollection).toHaveBeenCalledWith(
49
+ expect.anything(),
50
+ "landingpages",
51
+ );
52
+ expect(mockPath).toHaveBeenCalledWith("/agb");
53
+ });
54
+
55
+ it("answers page: null instead of a 404 when there is no content page", async () => {
56
+ mockFirst.mockResolvedValue(null);
57
+
58
+ await expect(
59
+ handler({ query: { path: "/speisekarte/pizza/" } }),
60
+ ).resolves.toEqual({ page: null });
61
+ });
62
+
63
+ it.each([
64
+ ["missing", undefined],
65
+ ["relative", "agb"],
66
+ ["too long", `/${"x".repeat(256)}`],
67
+ ["repeated", ["/agb", "/impressum"]],
68
+ ])("rejects a %s path with 400", async (_label, path) => {
69
+ await expect(handler({ query: { path } })).rejects.toMatchObject({
70
+ statusCode: 400,
71
+ });
72
+ expect(mockQueryCollection).not.toHaveBeenCalled();
73
+ });
74
+ });