@shopbite-de/storefront 2.5.0 → 2.6.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.
@@ -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