@shopbite-de/storefront 2.2.1 → 2.3.0
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.
- package/CLAUDE.md +10 -5
- package/app/app.vue +9 -6
- package/app/components/Category/Breadcrumb.vue +9 -10
- package/app/components/Checkout/Summary.vue +27 -2
- package/app/components/Header.vue +2 -2
- package/app/composables/useBusinessHours.ts +35 -14
- package/app/composables/useHolidays.ts +31 -11
- package/app/composables/useHomeMenuCategories.ts +6 -34
- package/app/composables/useLiveShopData.ts +17 -0
- package/app/composables/useNavigation.ts +14 -66
- package/app/composables/useNavigationSearch.ts +8 -31
- package/app/composables/useRestaurantSchema.ts +2 -13
- package/app/composables/useSeoUrlRoute.ts +21 -0
- package/app/composables/useShopBiteConfig.ts +50 -6
- package/app/composables/useTopSellers.ts +2 -43
- package/app/error.vue +4 -0
- package/docs/notes/2026-09-10-issue-275-accessibility.md +2 -2
- package/docs/notes/2026-09-12-issue-327-home-hero.md +1 -1
- package/docs/notes/2026-09-13-issue-332-home-info-cards.md +1 -3
- package/docs/notes/2026-09-21-issue-273-cache-and-demo-video.md +1 -1
- package/docs/notes/2026-09-21-issue-363-non-fatal-404.md +1 -1
- package/docs/notes/2026-09-23-issue-388-home-sections.md +2 -2
- package/docs/notes/2026-10-05-issue-401-restaurant-schema-ordering.md +1 -1
- package/modules/theme.ts +1 -1
- package/nuxt.config.ts +13 -0
- package/package.json +4 -4
- package/server/api/_cache/purge.post.ts +6 -3
- package/server/api/breadcrumb/[categoryId].get.ts +31 -0
- package/server/api/navigation/[type].get.ts +97 -0
- package/server/api/payment-methods.get.ts +29 -0
- package/server/api/seo-url/index.get.ts +17 -0
- package/server/api/seo-url/known.get.ts +33 -0
- package/server/api/shopbite/business-hours.get.ts +22 -0
- package/server/api/shopbite/config.get.ts +6 -0
- package/server/api/shopbite/holidays.get.ts +20 -0
- package/server/api/top-sellers.get.ts +59 -0
- package/server/utils/backoff.ts +67 -0
- package/server/utils/cachePurge.ts +45 -12
- package/server/utils/menuRoot.ts +24 -18
- package/server/utils/seoPaths.ts +130 -0
- package/server/utils/seoUrlCache.ts +98 -0
- package/server/utils/shopBiteConfig.ts +30 -0
- package/server/utils/storeApi.ts +22 -0
- package/test/layer/nuxt.config.ts +1 -1
- package/test/nuxt/CheckoutSummary.test.ts +38 -2
- package/test/nuxt/liveShopData.test.ts +114 -0
- package/test/nuxt/useShopBiteConfig.test.ts +22 -0
- package/test/nuxt/useTopSellers.test.ts +10 -27
- package/test/unit/cachePurge.spec.ts +41 -0
- package/test/unit/layoutCacheRoutes.spec.ts +566 -0
- package/test/unit/nitroStubs.ts +99 -0
- package/test/unit/seoPaths.spec.ts +117 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
mockNuxtImport,
|
|
4
|
+
mountSuspended,
|
|
5
|
+
registerEndpoint,
|
|
6
|
+
} from "@nuxt/test-utils/runtime";
|
|
7
|
+
import { defineComponent, h } from "vue";
|
|
8
|
+
import {
|
|
9
|
+
loadShopBiteConfig,
|
|
10
|
+
SHOPBITE_CONFIG_KEY,
|
|
11
|
+
} from "~/composables/useShopBiteConfig";
|
|
12
|
+
import {
|
|
13
|
+
BUSINESS_HOURS_KEY,
|
|
14
|
+
loadBusinessHours,
|
|
15
|
+
} from "~/composables/useBusinessHours";
|
|
16
|
+
import { HOLIDAYS_KEY, loadHolidays } from "~/composables/useHolidays";
|
|
17
|
+
import { useLiveShopData } from "~/composables/useLiveShopData";
|
|
18
|
+
|
|
19
|
+
const { mockRefreshNuxtData, cached } = vi.hoisted(() => ({
|
|
20
|
+
mockRefreshNuxtData: vi.fn(),
|
|
21
|
+
cached: {
|
|
22
|
+
config: vi.fn(),
|
|
23
|
+
hours: vi.fn(),
|
|
24
|
+
holidays: vi.fn(),
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
mockNuxtImport("refreshNuxtData", () => mockRefreshNuxtData);
|
|
29
|
+
|
|
30
|
+
registerEndpoint("/api/shopbite/config", () => cached.config());
|
|
31
|
+
registerEndpoint("/api/shopbite/business-hours", () => cached.hours());
|
|
32
|
+
registerEndpoint("/api/shopbite/holidays", () => cached.holidays());
|
|
33
|
+
|
|
34
|
+
const invoke = vi.fn();
|
|
35
|
+
const apiClient = { invoke } as unknown as Parameters<
|
|
36
|
+
typeof loadShopBiteConfig
|
|
37
|
+
>[0];
|
|
38
|
+
|
|
39
|
+
describe("shop data sources", () => {
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
vi.clearAllMocks();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("renders the config from the server cache, the browser asks Shopware", async () => {
|
|
45
|
+
cached.config.mockReturnValue({ isCheckoutEnabled: false });
|
|
46
|
+
invoke.mockResolvedValue({ data: { isCheckoutEnabled: true } });
|
|
47
|
+
|
|
48
|
+
expect(await loadShopBiteConfig(apiClient, true)).toEqual({
|
|
49
|
+
isCheckoutEnabled: false,
|
|
50
|
+
});
|
|
51
|
+
expect(invoke).not.toHaveBeenCalled();
|
|
52
|
+
|
|
53
|
+
expect(await loadShopBiteConfig(apiClient, false)).toEqual({
|
|
54
|
+
isCheckoutEnabled: true,
|
|
55
|
+
});
|
|
56
|
+
expect(invoke).toHaveBeenCalledWith(
|
|
57
|
+
"shopbite.config.get get /shopbite/config",
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("retries the config in the browser like the opening hours", async () => {
|
|
62
|
+
invoke
|
|
63
|
+
.mockRejectedValueOnce(new Error("offline"))
|
|
64
|
+
.mockResolvedValue({ data: { isCheckoutEnabled: true } });
|
|
65
|
+
|
|
66
|
+
expect(await loadShopBiteConfig(apiClient, false, [0])).toEqual({
|
|
67
|
+
isCheckoutEnabled: true,
|
|
68
|
+
});
|
|
69
|
+
expect(invoke).toHaveBeenCalledTimes(2);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("reads business hours and holidays from the cache on the server", async () => {
|
|
73
|
+
const hours = [{ dayOfWeek: 1, openingTime: "11:00" }];
|
|
74
|
+
const holidays = [{ start: "2026-12-24", end: "2026-12-26" }];
|
|
75
|
+
cached.hours.mockReturnValue({ businessHours: hours });
|
|
76
|
+
cached.holidays.mockReturnValue({ holidays });
|
|
77
|
+
|
|
78
|
+
expect(await loadBusinessHours(apiClient, true)).toEqual(hours);
|
|
79
|
+
expect(await loadHolidays(apiClient, true)).toEqual(holidays);
|
|
80
|
+
expect(invoke).not.toHaveBeenCalled();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("asks Shopware for business hours and holidays in the browser", async () => {
|
|
84
|
+
invoke.mockImplementation(async (operation: string) =>
|
|
85
|
+
operation.includes("business-hour")
|
|
86
|
+
? { data: { businessHours: ["h"] } }
|
|
87
|
+
: { data: { holidays: ["d"] } },
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expect(await loadBusinessHours(apiClient, false, [])).toEqual(["h"]);
|
|
91
|
+
expect(await loadHolidays(apiClient, false, [])).toEqual(["d"]);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("useLiveShopData", () => {
|
|
96
|
+
it("reloads config, hours and holidays from Shopware after hydration", async () => {
|
|
97
|
+
await mountSuspended(
|
|
98
|
+
defineComponent({
|
|
99
|
+
setup() {
|
|
100
|
+
useLiveShopData();
|
|
101
|
+
return () => h("div");
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// refreshNuxtData waits for the end of hydration; a refresh() during
|
|
107
|
+
// hydration would return the server's (cached) payload
|
|
108
|
+
expect(mockRefreshNuxtData).toHaveBeenCalledWith([
|
|
109
|
+
SHOPBITE_CONFIG_KEY,
|
|
110
|
+
BUSINESS_HOURS_KEY,
|
|
111
|
+
HOLIDAYS_KEY,
|
|
112
|
+
]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -52,4 +52,26 @@ describe("useShopBiteConfig", () => {
|
|
|
52
52
|
expect(deliveryTime.value).toBe(45);
|
|
53
53
|
expect(isCheckoutEnabled.value).toBe(true);
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
it("checks the checkout switch with Shopware before an order", async () => {
|
|
57
|
+
mockInvoke.mockResolvedValue({
|
|
58
|
+
data: { deliveryTime: 30, isCheckoutEnabled: false },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const { checkCheckoutEnabled, isCheckoutEnabled } = useShopBiteConfig();
|
|
62
|
+
|
|
63
|
+
expect(await checkCheckoutEnabled()).toBe(false);
|
|
64
|
+
expect(isCheckoutEnabled.value).toBe(false);
|
|
65
|
+
expect(mockInvoke).toHaveBeenCalledWith(
|
|
66
|
+
"shopbite.config.get get /shopbite/config",
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("reports an unknown checkout switch when Shopware fails", async () => {
|
|
71
|
+
mockInvoke.mockRejectedValue(new Error("offline"));
|
|
72
|
+
|
|
73
|
+
const { checkCheckoutEnabled } = useShopBiteConfig();
|
|
74
|
+
|
|
75
|
+
expect(await checkCheckoutEnabled([])).toBeNull();
|
|
76
|
+
});
|
|
55
77
|
});
|
|
@@ -1,44 +1,27 @@
|
|
|
1
|
-
import { describe, it, expect, vi
|
|
2
|
-
import {
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { registerEndpoint } from "@nuxt/test-utils/runtime";
|
|
3
3
|
import { useTopSellers } from "~/composables/useTopSellers";
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
mockInvoke: vi.fn(),
|
|
7
|
-
}));
|
|
5
|
+
const { topSellers } = vi.hoisted(() => ({ topSellers: vi.fn() }));
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
return () => ({
|
|
11
|
-
apiClient: {
|
|
12
|
-
invoke: mockInvoke,
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
});
|
|
7
|
+
registerEndpoint("/api/top-sellers", () => topSellers());
|
|
16
8
|
|
|
17
9
|
describe("useTopSellers", () => {
|
|
18
|
-
|
|
19
|
-
vi.clearAllMocks();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should load top sellers successfully", async () => {
|
|
10
|
+
it("should load top sellers from the server cache", async () => {
|
|
23
11
|
const mockElements = [{ id: "1", name: "Top Product" }];
|
|
24
|
-
|
|
25
|
-
data: {
|
|
26
|
-
elements: mockElements,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
12
|
+
topSellers.mockReturnValue(mockElements);
|
|
29
13
|
|
|
30
14
|
const { loadTopSellers } = useTopSellers();
|
|
31
15
|
const result = await loadTopSellers();
|
|
32
16
|
|
|
33
|
-
expect(
|
|
34
|
-
"readProduct post /product",
|
|
35
|
-
expect.any(Object),
|
|
36
|
-
);
|
|
17
|
+
expect(topSellers).toHaveBeenCalled();
|
|
37
18
|
expect(result).toEqual(mockElements);
|
|
38
19
|
});
|
|
39
20
|
|
|
40
21
|
it("should return empty array on error", async () => {
|
|
41
|
-
|
|
22
|
+
topSellers.mockImplementation(() => {
|
|
23
|
+
throw new Error("Network error");
|
|
24
|
+
});
|
|
42
25
|
|
|
43
26
|
// Silence console.error for this test
|
|
44
27
|
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
@@ -16,6 +16,20 @@ const KEYS = [
|
|
|
16
16
|
`cache:nitro:handlers:sitemap:urls.json`,
|
|
17
17
|
`cache:nitro:routes:_:llmstxt.json`,
|
|
18
18
|
];
|
|
19
|
+
// layout data of every page, purged with any target
|
|
20
|
+
const LAYOUT_KEYS = [
|
|
21
|
+
`cache:nitro:handlers:navigation:navigationmenu${PIZZA}.json`,
|
|
22
|
+
`cache:nitro:handlers:navigation:navigationmainmainnavigation.json`,
|
|
23
|
+
`cache:nitro:handlers:breadcrumb:breadcrumb${PIZZA}.json`,
|
|
24
|
+
`cache:nitro:handlers:business-hours:businesshours.json`,
|
|
25
|
+
`cache:nitro:handlers:holidays:holidays.json`,
|
|
26
|
+
`cache:nitro:handlers:payment-methods:paymentmethods.json`,
|
|
27
|
+
`cache:nitro:handlers:top-sellers:topsellers.json`,
|
|
28
|
+
`cache:nitro:functions:seo-url:3f786850e387550fdab836ed7e6dc881de23001b.json`,
|
|
29
|
+
`cache:nitro:functions:seo-paths:seo-paths.json`,
|
|
30
|
+
`cache:nitro:functions:shopbite-config:shopbite-config.json`,
|
|
31
|
+
];
|
|
32
|
+
const OTHER_FUNCTION = `cache:nitro:functions:_:abc.json`;
|
|
19
33
|
|
|
20
34
|
describe("keysToPurge", () => {
|
|
21
35
|
it("purges every Store API cache without a target", () => {
|
|
@@ -45,6 +59,33 @@ describe("keysToPurge", () => {
|
|
|
45
59
|
]);
|
|
46
60
|
});
|
|
47
61
|
|
|
62
|
+
it("purges the layout data with every target", () => {
|
|
63
|
+
const keys = [...KEYS, ...LAYOUT_KEYS, OTHER_FUNCTION];
|
|
64
|
+
for (const target of [
|
|
65
|
+
{},
|
|
66
|
+
{ products: [MARGHERITA] },
|
|
67
|
+
{ categories: [PIZZA] },
|
|
68
|
+
]) {
|
|
69
|
+
const purged = keysToPurge(keys, target);
|
|
70
|
+
expect(purged).toEqual(expect.arrayContaining(LAYOUT_KEYS));
|
|
71
|
+
expect(purged).not.toContain(OTHER_FUNCTION);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("purges only the layout data and llms.txt for a layout target", () => {
|
|
76
|
+
const keys = [...KEYS, ...LAYOUT_KEYS, OTHER_FUNCTION];
|
|
77
|
+
const layout = LAYOUT_KEYS.filter((k) => !k.includes("top-sellers"));
|
|
78
|
+
expect(keysToPurge(keys, { layout: true })).toEqual([KEYS[8], ...layout]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("adds the layout data to a menu target, not other products", () => {
|
|
82
|
+
const keys = [...KEYS, ...LAYOUT_KEYS];
|
|
83
|
+
const purged = keysToPurge(keys, { products: [SCHNITZEL], layout: true });
|
|
84
|
+
expect(purged).toEqual(expect.arrayContaining(LAYOUT_KEYS));
|
|
85
|
+
expect(purged).toContain(KEYS[1]);
|
|
86
|
+
expect(purged).not.toContain(KEYS[0]);
|
|
87
|
+
});
|
|
88
|
+
|
|
48
89
|
it("finds ids written with dashes or upper case", () => {
|
|
49
90
|
const dashed = `0197BAF0-A6A9-71EA-ADA5-9ED5C84138DE`;
|
|
50
91
|
expect(keysToPurge(KEYS, { products: [dashed] })).toContain(KEYS[0]);
|