@shopbite-de/storefront 2.5.0 → 2.6.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.
@@ -14,9 +14,15 @@ const { state, mocks } = vi.hoisted(() => ({
14
14
  validTime: false,
15
15
  shippingBlocked: false,
16
16
  customer: true,
17
+ fulfillment: "delivery" as "delivery" | "pickup",
17
18
  },
18
19
  }));
19
20
 
21
+ mockNuxtImport("useShippingLeadTime", () => () => ({
22
+ fulfillment: ref(state.fulfillment),
23
+ leadTime: ref(30),
24
+ }));
25
+
20
26
  mockNuxtImport("useOpeningHoursData", () => () => ({
21
27
  isLoading: ref(state.isLoading),
22
28
  hasFailed: ref(state.hasFailed),
@@ -44,6 +50,10 @@ mockNuxtImport("useShopBiteConfig", () => () => ({
44
50
  checkCheckoutEnabled: mocks.checkCheckoutEnabled,
45
51
  }));
46
52
 
53
+ // A successful order navigates to the confirmation page; loading that
54
+ // route after the test environment is torn down is an unhandled error.
55
+ mockNuxtImport("navigateTo", () => vi.fn());
56
+
47
57
  mockNuxtImport("useTrackEvent", () => () => ({
48
58
  trackOrder: vi.fn(),
49
59
  }));
@@ -61,9 +71,12 @@ vi.mock("@shopware/composables", async (importOriginal) => ({
61
71
 
62
72
  // Reports the time as DeliveryTimeSelect does once a time is selected.
63
73
  const DeliveryTimeSelectStub = defineComponent({
64
- emits: ["update:valid"],
74
+ emits: ["update:valid", "update:modelValue"],
65
75
  setup(_, { emit }) {
66
- onMounted(() => emit("update:valid", state.validTime));
76
+ onMounted(() => {
77
+ emit("update:modelValue", "19:15");
78
+ emit("update:valid", state.validTime);
79
+ });
67
80
  return () => h("div");
68
81
  },
69
82
  });
@@ -93,6 +106,9 @@ describe("Checkout Summary order button", () => {
93
106
  state.validTime = false;
94
107
  state.shippingBlocked = false;
95
108
  state.customer = true;
109
+ state.fulfillment = "delivery";
110
+ mocks.createOrder.mockReset();
111
+ mocks.checkCheckoutEnabled.mockReset();
96
112
  });
97
113
 
98
114
  it("shows a loading state while the opening hours are not loaded", async () => {
@@ -196,4 +212,27 @@ describe("Checkout Summary order button", () => {
196
212
  "konnte nicht geprüft werden",
197
213
  );
198
214
  });
215
+
216
+ // shopbite#6: the comment names the kind of time
217
+ it.each([
218
+ ["delivery", "Wunschlieferzeit: 19:15"],
219
+ ["pickup", "Wunschabholzeit: 19:15"],
220
+ ] as const)(
221
+ "stores the wished time of a %s order",
222
+ async (fulfillment, comment) => {
223
+ state.isLoading = false;
224
+ state.validTime = true;
225
+ state.fulfillment = fulfillment;
226
+ mocks.checkCheckoutEnabled.mockResolvedValue(true);
227
+ mocks.createOrder.mockResolvedValue({ id: "order-1" });
228
+
229
+ const button = await mountSummary();
230
+ await button.trigger("click");
231
+ await new Promise((resolve) => setTimeout(resolve, 0));
232
+
233
+ expect(mocks.createOrder).toHaveBeenCalledWith({
234
+ customerComment: comment,
235
+ });
236
+ },
237
+ );
199
238
  });
@@ -0,0 +1,181 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { nextTick, ref, type Ref } from "vue";
4
+ import DeliveryTimeSelect from "~/components/Checkout/DeliveryTimeSelect.vue";
5
+
6
+ // The time field follows the selected shipping method (shopbite#6):
7
+ // lead time and wording of delivery or pickup.
8
+ const { lead, hours } = vi.hoisted(() => ({
9
+ lead: {
10
+ fulfillment: "delivery" as "delivery" | "pickup",
11
+ leadTime: 45 as number | null,
12
+ // the refs of the mounted component, to switch the method
13
+ current: null as null | {
14
+ fulfillment: Ref<"delivery" | "pickup">;
15
+ leadTime: Ref<number | null>;
16
+ },
17
+ },
18
+ // "past": today's only interval has ended; "open": 11:00 to 22:00
19
+ hours: { mode: "past" as "past" | "open" },
20
+ }));
21
+
22
+ mockNuxtImport("useShippingLeadTime", () => () => {
23
+ lead.current = {
24
+ fulfillment: ref(lead.fulfillment),
25
+ leadTime: ref(lead.leadTime),
26
+ };
27
+ return lead.current;
28
+ });
29
+
30
+ mockNuxtImport("useOpeningHoursData", () => () => ({
31
+ isLoaded: ref(true),
32
+ hasFailed: ref(false),
33
+ retry: vi.fn(),
34
+ }));
35
+
36
+ mockNuxtImport("useHolidays", () => () => ({
37
+ isClosedHoliday: () => false,
38
+ }));
39
+
40
+ // "past": today's only interval ended an hour ago, no times are left.
41
+ mockNuxtImport("useBusinessHours", () => () => {
42
+ const interval = (date: Date) => {
43
+ if (hours.mode === "open") {
44
+ const start = new Date(date);
45
+ start.setHours(11, 0, 0, 0);
46
+ const end = new Date(date);
47
+ end.setHours(22, 0, 0, 0);
48
+ return { start, end };
49
+ }
50
+ const end = new Date(Date.now() - 60 * 60_000);
51
+ return { start: new Date(end.getTime() - 60 * 60_000), end };
52
+ };
53
+ const getEarliestSelectableTime = (now: Date, minutes: number | null) => {
54
+ const earliest = new Date(now.getTime() + (minutes ?? 30) * 60_000);
55
+ earliest.setSeconds(0, 0);
56
+ return earliest;
57
+ };
58
+ return {
59
+ businessHours: ref([
60
+ {
61
+ dayOfWeek: new Date().getDay(),
62
+ openingTime: "00:00",
63
+ closingTime: "00:01",
64
+ },
65
+ ]),
66
+ getServiceIntervals: (date: Date) => [interval(date)],
67
+ getEarliestSelectableTime,
68
+ findActiveInterval: (now: Date, minutes: number | null) => {
69
+ if (hours.mode === "past") return null;
70
+ const current = interval(now);
71
+ return getEarliestSelectableTime(now, minutes) <= current.end
72
+ ? current
73
+ : null;
74
+ },
75
+ };
76
+ });
77
+
78
+ async function mountSelect() {
79
+ return await mountSuspended(DeliveryTimeSelect);
80
+ }
81
+
82
+ describe("DeliveryTimeSelect wording per fulfillment", () => {
83
+ beforeEach(() => {
84
+ lead.fulfillment = "delivery";
85
+ lead.leadTime = 45;
86
+ hours.mode = "past";
87
+ });
88
+
89
+ it("asks for the delivery time with the delivery lead time", async () => {
90
+ const wrapper = await mountSelect();
91
+ const text = wrapper.text();
92
+
93
+ expect(wrapper.get("label").text()).toContain("Wunschlieferzeit");
94
+ expect(text).toContain("Lieferzeit ca. 45 Minuten");
95
+ expect(text).toContain("Heute sind keine Lieferzeiten mehr verfügbar.");
96
+ expect(text).not.toContain("Abhol");
97
+ });
98
+
99
+ it("asks for the pickup time with the pickup lead time", async () => {
100
+ lead.fulfillment = "pickup";
101
+ lead.leadTime = 20;
102
+
103
+ const wrapper = await mountSelect();
104
+ const text = wrapper.text();
105
+
106
+ expect(wrapper.get("label").text()).toContain("Wunschabholzeit");
107
+ expect(text).toContain("Abholbereit in ca. 20 Minuten");
108
+ expect(text).toContain("Heute sind keine Abholzeiten mehr verfügbar.");
109
+ expect(text).not.toContain("Lieferzeit");
110
+ });
111
+
112
+ it("leaves out the lead time hint while it is unknown", async () => {
113
+ lead.leadTime = null;
114
+
115
+ const wrapper = await mountSelect();
116
+
117
+ expect(wrapper.text()).not.toContain("ca.");
118
+ });
119
+ });
120
+
121
+ // Switching the shipping method moves the time to a valid 5-minute slot.
122
+ describe("DeliveryTimeSelect after a shipping method switch", () => {
123
+ beforeEach(() => {
124
+ vi.useFakeTimers({ toFake: ["Date"] });
125
+ vi.setSystemTime(new Date(2026, 10, 19, 16, 13, 20));
126
+ hours.mode = "open";
127
+ });
128
+
129
+ afterEach(() => {
130
+ vi.useRealTimers();
131
+ });
132
+
133
+ async function switchTo(fulfillment: "delivery" | "pickup", minutes: number) {
134
+ lead.current!.fulfillment.value = fulfillment;
135
+ lead.current!.leadTime.value = minutes;
136
+ await nextTick();
137
+ await nextTick();
138
+ }
139
+
140
+ function timeInput(wrapper: Awaited<ReturnType<typeof mountSelect>>) {
141
+ return wrapper.get<HTMLInputElement>('input[type="time"]');
142
+ }
143
+
144
+ it("moves a chosen pickup time to the next delivery slot", async () => {
145
+ lead.fulfillment = "pickup";
146
+ lead.leadTime = 15;
147
+ const wrapper = await mountSelect();
148
+ expect(timeInput(wrapper).element.value).toBe("16:30");
149
+ await timeInput(wrapper).setValue("16:30");
150
+
151
+ await switchTo("delivery", 30);
152
+
153
+ expect(timeInput(wrapper).element.value).toBe("16:45");
154
+ expect(wrapper.text()).not.toContain("5-Minuten-Schritten");
155
+ expect(wrapper.emitted("update:valid")!.at(-1)).toEqual([true]);
156
+ });
157
+
158
+ it("moves the prefilled delivery time to the earlier pickup slot", async () => {
159
+ lead.fulfillment = "delivery";
160
+ lead.leadTime = 30;
161
+ const wrapper = await mountSelect();
162
+ expect(timeInput(wrapper).element.value).toBe("16:45");
163
+
164
+ await switchTo("pickup", 15);
165
+
166
+ expect(timeInput(wrapper).element.value).toBe("16:30");
167
+ expect(wrapper.emitted("update:valid")!.at(-1)).toEqual([true]);
168
+ });
169
+
170
+ it("keeps a later time the guest chose", async () => {
171
+ lead.fulfillment = "delivery";
172
+ lead.leadTime = 30;
173
+ const wrapper = await mountSelect();
174
+ await timeInput(wrapper).setValue("18:00");
175
+
176
+ await switchTo("pickup", 15);
177
+ expect(timeInput(wrapper).element.value).toBe("18:00");
178
+ await switchTo("delivery", 30);
179
+ expect(timeInput(wrapper).element.value).toBe("18:00");
180
+ });
181
+ });
@@ -0,0 +1,78 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { ref } from "vue";
4
+ import Hero from "~/components/Home/Hero.vue";
5
+ import Facts from "~/components/Home/Facts.vue";
6
+
7
+ // The home page shows the lead times of the delivery and pickup methods
8
+ // (shopbite#6) and leaves out a time no shipping method has.
9
+ const { times } = vi.hoisted(() => ({
10
+ times: {
11
+ delivery: 45 as number | null,
12
+ pickup: 20 as number | null,
13
+ },
14
+ }));
15
+
16
+ mockNuxtImport("useShopBiteConfig", () => () => ({
17
+ deliveryTime: ref(times.delivery),
18
+ pickupTime: ref(times.pickup),
19
+ }));
20
+
21
+ mockNuxtImport("useStoreStatus", () => () => ({
22
+ status: ref({ open: true, closesAt: "22:00" }),
23
+ }));
24
+
25
+ mockNuxtImport("useBusinessHours", () => () => ({
26
+ businessHours: ref(null),
27
+ }));
28
+
29
+ const features = [
30
+ {
31
+ title: "Lieferung",
32
+ kind: "delivery" as const,
33
+ description: "Liefergebiet",
34
+ },
35
+ { title: "Abholung", kind: "pickup" as const, description: "Im Restaurant" },
36
+ ];
37
+
38
+ describe("lead times on the home page", () => {
39
+ beforeEach(() => {
40
+ times.delivery = 45;
41
+ times.pickup = 20;
42
+ });
43
+
44
+ it("shows delivery and pickup time in the hero", async () => {
45
+ const wrapper = await mountSuspended(Hero, { props: { title: "Pizza" } });
46
+ const text = wrapper.text();
47
+ expect(text).toContain("Lieferung ca. 45 Min");
48
+ expect(text).toContain("Abholung ca. 20 Min");
49
+ });
50
+
51
+ it("leaves out a time without a shipping method of that kind", async () => {
52
+ times.delivery = null;
53
+ const wrapper = await mountSuspended(Hero, { props: { title: "Pizza" } });
54
+ const text = wrapper.text();
55
+ expect(text).not.toContain("Lieferung ca.");
56
+ expect(text).toContain("Abholung ca. 20 Min");
57
+ });
58
+
59
+ it("fills the delivery and pickup facts", async () => {
60
+ const wrapper = await mountSuspended(Facts, { props: { features } });
61
+ const text = wrapper.text();
62
+ expect(text).toContain("In ca. 45 Minuten bei Ihnen");
63
+ expect(text).toContain("Abholbereit in ca. 20 Minuten");
64
+ });
65
+
66
+ it("keeps the content lead without a lead time", async () => {
67
+ times.delivery = null;
68
+ times.pickup = null;
69
+ const wrapper = await mountSuspended(Facts, {
70
+ props: {
71
+ features: [{ ...features[0]!, lead: "Frei Haus ab 15 €" }],
72
+ },
73
+ });
74
+ const text = wrapper.text();
75
+ expect(text).toContain("Frei Haus ab 15 €");
76
+ expect(text).not.toContain("Minuten");
77
+ });
78
+ });
@@ -66,6 +66,26 @@ describe("order pages with a preset (#445)", () => {
66
66
  });
67
67
  });
68
68
 
69
+ // shopbite#6: pickup orders store "Wunschabholzeit"
70
+ it("shows the wished pickup time", async () => {
71
+ mocks.loadOrderDetails.mockImplementation(async () => {
72
+ order.value = {
73
+ ...sampleOrder,
74
+ customerComment: "Wunschabholzeit: 18:40",
75
+ } as Schemas["Order"];
76
+ });
77
+ const wrapper = await mountSuspended(ConfirmationPreset, {
78
+ props: { orderId: "order-1", kind: "success" },
79
+ });
80
+ await flushPromises();
81
+
82
+ const facts = wrapper
83
+ .findAll("dl")[0]!
84
+ .findAll("div")
85
+ .map((row) => row.text());
86
+ expect(facts).toContain("Wunschzeit18:40");
87
+ });
88
+
69
89
  it("thanks the guest and shows the order after loading", async () => {
70
90
  mocks.loadOrderDetails.mockImplementation(async () => {
71
91
  order.value = sampleOrder;
@@ -3,9 +3,10 @@ import { mockNuxtImport } from "@nuxt/test-utils/runtime";
3
3
  import { ref } from "vue";
4
4
  import { useDeliveryTime } from "~/composables/useDeliveryTime";
5
5
 
6
- const { mockDeliveryTime, mockBusinessHours, mockHolidays } = vi.hoisted(
7
- () => ({
6
+ const { mockDeliveryTime, mockFulfillment, mockBusinessHours, mockHolidays } =
7
+ vi.hoisted(() => ({
8
8
  mockDeliveryTime: { value: 45 },
9
+ mockFulfillment: { value: "delivery" as "delivery" | "pickup" },
9
10
  mockBusinessHours: {
10
11
  value: [
11
12
  { dayOfWeek: 1, openingTime: "11:30", closingTime: "14:30" },
@@ -22,11 +23,11 @@ const { mockDeliveryTime, mockBusinessHours, mockHolidays } = vi.hoisted(
22
23
  ],
23
24
  },
24
25
  mockHolidays: { value: [] as { start: string; end: string }[] | null },
25
- }),
26
- );
26
+ }));
27
27
 
28
- mockNuxtImport("useShopBiteConfig", () => () => ({
29
- deliveryTime: mockDeliveryTime,
28
+ mockNuxtImport("useShippingLeadTime", () => () => ({
29
+ leadTime: mockDeliveryTime,
30
+ fulfillment: mockFulfillment,
30
31
  }));
31
32
 
32
33
  mockNuxtImport("useBusinessHours", () => () => ({
@@ -120,6 +121,29 @@ describe("useDeliveryTime", () => {
120
121
 
121
122
  beforeEach(() => {
122
123
  vi.clearAllMocks();
124
+ mockFulfillment.value = "delivery";
125
+ });
126
+
127
+ // shopbite#6: the lead time of the selected shipping method
128
+ it("uses the lead time of the selected shipping method", () => {
129
+ mockDeliveryTime.value = 20;
130
+ mockFulfillment.value = "pickup";
131
+ const { earliest } = useDeliveryTime(now);
132
+ expect(earliest.value.getHours()).toBe(12);
133
+ expect(earliest.value.getMinutes()).toBe(20);
134
+ });
135
+
136
+ it("speaks of pickup times for a pickup method", () => {
137
+ mockDeliveryTime.value = 30;
138
+ const late = ref(new Date("2023-10-27T22:45:00"));
139
+ mockFulfillment.value = "pickup";
140
+ expect(useDeliveryTime(late).helperText.value).toBe(
141
+ "Heute sind keine Abholzeiten mehr verfügbar.",
142
+ );
143
+ mockFulfillment.value = "delivery";
144
+ expect(useDeliveryTime(late).helperText.value).toBe(
145
+ "Heute sind keine Lieferzeiten mehr verfügbar.",
146
+ );
123
147
  });
124
148
 
125
149
  it("should calculate earliest selectable time", () => {
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { mockNuxtImport } from "@nuxt/test-utils/runtime";
3
+ import { ref } from "vue";
4
+ import { useShippingLeadTime } from "~/composables/useShippingLeadTime";
5
+
6
+ // The checkout's time choice follows the selected shipping method
7
+ // (shopbite#6).
8
+ const DELIVERY = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5b";
9
+ const PICKUP = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5c";
10
+
11
+ const { mockInvoke, selected } = vi.hoisted(() => ({
12
+ mockInvoke: vi.fn(),
13
+ selected: {
14
+ current: null as null | { value: unknown },
15
+ },
16
+ }));
17
+
18
+ mockNuxtImport("useShopwareContext", () => () => ({
19
+ apiClient: { invoke: mockInvoke },
20
+ }));
21
+
22
+ mockNuxtImport("useCheckout", () => () => ({
23
+ selectedShippingMethod: selected.current,
24
+ }));
25
+
26
+ const configData = ref<unknown>(null);
27
+ mockNuxtImport(
28
+ "useAsyncData",
29
+ () => (_key: string, fetcher: () => Promise<unknown>) => ({
30
+ data: configData,
31
+ refresh: async () => {
32
+ configData.value = await fetcher();
33
+ },
34
+ }),
35
+ );
36
+
37
+ describe("useShippingLeadTime", () => {
38
+ beforeEach(() => {
39
+ configData.value = null;
40
+ selected.current = ref({ id: DELIVERY, name: "Lieferung" });
41
+ });
42
+
43
+ it("switches between delivery and pickup with the shipping method", async () => {
44
+ configData.value = {
45
+ isCheckoutEnabled: true,
46
+ shippingMethods: [
47
+ { id: DELIVERY, fulfillment: "delivery", leadTimeMinutes: 45 },
48
+ { id: PICKUP, fulfillment: "pickup", leadTimeMinutes: 20 },
49
+ ],
50
+ };
51
+
52
+ const { fulfillment, leadTime } = useShippingLeadTime();
53
+ expect(fulfillment.value).toBe("delivery");
54
+ expect(leadTime.value).toBe(45);
55
+
56
+ selected.current!.value = { id: PICKUP, name: "Abholung" };
57
+ expect(fulfillment.value).toBe("pickup");
58
+ expect(leadTime.value).toBe(20);
59
+ });
60
+
61
+ it("defaults to delivery without a lead time before the config is loaded", () => {
62
+ const { fulfillment, leadTime } = useShippingLeadTime();
63
+ expect(fulfillment.value).toBe("delivery");
64
+ expect(leadTime.value).toBeNull();
65
+ });
66
+ });
@@ -31,15 +31,21 @@ describe("useShopBiteConfig", () => {
31
31
 
32
32
  it("should return default values when no data is loaded", () => {
33
33
  const { deliveryTime, isCheckoutEnabled } = useShopBiteConfig();
34
- expect(deliveryTime.value).toBe(30);
34
+ expect(deliveryTime.value).toBeNull();
35
35
  expect(isCheckoutEnabled.value).toBe(false);
36
36
  });
37
37
 
38
38
  it("should refresh values from API", async () => {
39
39
  mockInvoke.mockResolvedValue({
40
40
  data: {
41
- deliveryTime: 45,
42
41
  isCheckoutEnabled: true,
42
+ shippingMethods: [
43
+ {
44
+ id: "0190a3b0c1d27e0f8a9b0c1d2e3f4a5b",
45
+ fulfillment: "delivery",
46
+ leadTimeMinutes: 45,
47
+ },
48
+ ],
43
49
  },
44
50
  });
45
51
 
@@ -55,7 +61,7 @@ describe("useShopBiteConfig", () => {
55
61
 
56
62
  it("checks the checkout switch with Shopware before an order", async () => {
57
63
  mockInvoke.mockResolvedValue({
58
- data: { deliveryTime: 30, isCheckoutEnabled: false },
64
+ data: { isCheckoutEnabled: false, shippingMethods: [] },
59
65
  });
60
66
 
61
67
  const { checkCheckoutEnabled, isCheckoutEnabled } = useShopBiteConfig();
@@ -74,4 +80,52 @@ describe("useShopBiteConfig", () => {
74
80
 
75
81
  expect(await checkCheckoutEnabled([])).toBeNull();
76
82
  });
83
+
84
+ // shopbite#6: lead time per shipping method
85
+ const DELIVERY = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5b";
86
+ const PICKUP = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5c";
87
+
88
+ it("passes the lead times of the shipping methods through", async () => {
89
+ mockInvoke.mockResolvedValue({
90
+ data: {
91
+ isCheckoutEnabled: true,
92
+ shippingMethods: [
93
+ { id: DELIVERY, fulfillment: "delivery", leadTimeMinutes: 50 },
94
+ { id: PICKUP, fulfillment: "pickup", leadTimeMinutes: 15 },
95
+ ],
96
+ },
97
+ });
98
+
99
+ const { refresh, deliveryTime, pickupTime, leadTimeFor } =
100
+ useShopBiteConfig();
101
+ await refresh();
102
+
103
+ expect(deliveryTime.value).toBe(50);
104
+ expect(pickupTime.value).toBe(15);
105
+ expect(leadTimeFor({ id: PICKUP })).toEqual({
106
+ fulfillment: "pickup",
107
+ minutes: 15,
108
+ });
109
+ expect(leadTimeFor({ id: DELIVERY })).toEqual({
110
+ fulfillment: "delivery",
111
+ minutes: 50,
112
+ });
113
+ });
114
+
115
+ it("has no delivery time without a delivery method", async () => {
116
+ mockInvoke.mockResolvedValue({
117
+ data: {
118
+ isCheckoutEnabled: true,
119
+ shippingMethods: [
120
+ { id: PICKUP, fulfillment: "pickup", leadTimeMinutes: 15 },
121
+ ],
122
+ },
123
+ });
124
+
125
+ const { refresh, deliveryTime, pickupTime } = useShopBiteConfig();
126
+ await refresh();
127
+
128
+ expect(deliveryTime.value).toBeNull();
129
+ expect(pickupTime.value).toBe(15);
130
+ });
77
131
  });
@@ -0,0 +1,86 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ fulfillmentLeadTime,
4
+ parseWishedTime,
5
+ shippingLeadTime,
6
+ wishedTimeComment,
7
+ } from "../../app/utils/leadTime";
8
+
9
+ const DELIVERY = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5b";
10
+ const PICKUP = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5c";
11
+
12
+ const config = {
13
+ shippingMethods: [
14
+ { id: DELIVERY, fulfillment: "delivery" as const, leadTimeMinutes: 45 },
15
+ { id: PICKUP, fulfillment: "pickup" as const, leadTimeMinutes: 20 },
16
+ ],
17
+ };
18
+
19
+ describe("shippingLeadTime", () => {
20
+ it("takes the lead time and fulfillment the plugin reports", () => {
21
+ expect(shippingLeadTime(config, { id: DELIVERY })).toEqual({
22
+ fulfillment: "delivery",
23
+ minutes: 45,
24
+ });
25
+ expect(shippingLeadTime(config, { id: PICKUP })).toEqual({
26
+ fulfillment: "pickup",
27
+ minutes: 20,
28
+ });
29
+ });
30
+
31
+ it("has no lead time for a method the plugin does not list", () => {
32
+ expect(shippingLeadTime(config, { id: "other" })).toEqual({
33
+ fulfillment: "delivery",
34
+ minutes: null,
35
+ });
36
+ expect(shippingLeadTime(null, undefined)).toEqual({
37
+ fulfillment: "delivery",
38
+ minutes: null,
39
+ });
40
+ });
41
+ });
42
+
43
+ describe("fulfillmentLeadTime", () => {
44
+ it("returns the lead time of the first method of the fulfillment", () => {
45
+ const many = {
46
+ shippingMethods: [
47
+ ...config.shippingMethods,
48
+ { id: "x", fulfillment: "delivery" as const, leadTimeMinutes: 60 },
49
+ ],
50
+ };
51
+ expect(fulfillmentLeadTime(many, "delivery")).toBe(45);
52
+ expect(fulfillmentLeadTime(many, "pickup")).toBe(20);
53
+ });
54
+
55
+ it("is null without a method of the fulfillment", () => {
56
+ expect(
57
+ fulfillmentLeadTime(
58
+ { shippingMethods: [config.shippingMethods[1]!] },
59
+ "delivery",
60
+ ),
61
+ ).toBeNull();
62
+ expect(fulfillmentLeadTime({ shippingMethods: [] }, "pickup")).toBeNull();
63
+ expect(fulfillmentLeadTime(undefined, "delivery")).toBeNull();
64
+ });
65
+ });
66
+
67
+ describe("wished time in the customer comment", () => {
68
+ it("writes the prefix of the fulfillment", () => {
69
+ expect(wishedTimeComment("delivery", "19:15")).toBe(
70
+ "Wunschlieferzeit: 19:15",
71
+ );
72
+ expect(wishedTimeComment("pickup", "19:15")).toBe("Wunschabholzeit: 19:15");
73
+ });
74
+
75
+ it("reads both prefixes", () => {
76
+ expect(parseWishedTime("Wunschlieferzeit: 19:15")).toBe("19:15");
77
+ expect(parseWishedTime("Wunschabholzeit: 18:40")).toBe("18:40");
78
+ expect(parseWishedTime(" Wunschabholzeit:18:40 ")).toBe("18:40");
79
+ });
80
+
81
+ it("keeps other comments", () => {
82
+ expect(parseWishedTime("Bitte klingeln")).toBe("Bitte klingeln");
83
+ expect(parseWishedTime(undefined)).toBeUndefined();
84
+ expect(parseWishedTime(null)).toBeUndefined();
85
+ });
86
+ });
@@ -29,6 +29,7 @@ describe("buildLlmsTxt", () => {
29
29
  ],
30
30
  isCheckoutEnabled: true,
31
31
  deliveryTime: 30,
32
+ pickupTime: 20,
32
33
  menuUrl: "https://www.pizzeria-esempio.example/speisekarte",
33
34
  menu: [
34
35
  {
@@ -108,7 +109,7 @@ Italienisch-deutsche Küche seit 1997.
108
109
  - Online bestellen: https://www.pizzeria-esempio.example/speisekarte
109
110
  - Liefergebiet: 12345 Musterstadt, 12346 Beispieldorf
110
111
  - Lieferzeit: ca. 30 Minuten
111
- - Abholung im Restaurant möglich
112
+ - Abholung im Restaurant möglich, abholbereit in ca. 20 Minuten
112
113
 
113
114
  ## Häufige Fragen
114
115