@shopbite-de/storefront 1.25.0 → 1.26.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.
@@ -0,0 +1,58 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { withRetries } from "../../app/utils/retry";
3
+
4
+ describe("withRetries", () => {
5
+ beforeEach(() => {
6
+ vi.useFakeTimers();
7
+ });
8
+
9
+ afterEach(() => {
10
+ vi.useRealTimers();
11
+ });
12
+
13
+ it("returns the first successful result without waiting", async () => {
14
+ const request = vi.fn().mockResolvedValue("ok");
15
+
16
+ await expect(withRetries(request, [1000, 3000])).resolves.toBe("ok");
17
+ expect(request).toHaveBeenCalledTimes(1);
18
+ });
19
+
20
+ it("tries again after each delay until a request succeeds", async () => {
21
+ const request = vi
22
+ .fn()
23
+ .mockRejectedValueOnce(new Error("first"))
24
+ .mockRejectedValueOnce(new Error("second"))
25
+ .mockResolvedValue("ok");
26
+
27
+ const result = withRetries(request, [1000, 3000]);
28
+
29
+ await vi.advanceTimersByTimeAsync(999);
30
+ expect(request).toHaveBeenCalledTimes(1);
31
+ await vi.advanceTimersByTimeAsync(1);
32
+ expect(request).toHaveBeenCalledTimes(2);
33
+ await vi.advanceTimersByTimeAsync(3000);
34
+ await expect(result).resolves.toBe("ok");
35
+ expect(request).toHaveBeenCalledTimes(3);
36
+ });
37
+
38
+ it("throws the error of the last attempt", async () => {
39
+ const request = vi
40
+ .fn()
41
+ .mockRejectedValueOnce(new Error("first"))
42
+ .mockRejectedValueOnce(new Error("last"));
43
+
44
+ const result = withRetries(request, [1000]);
45
+ const assertion = expect(result).rejects.toThrow("last");
46
+
47
+ await vi.advanceTimersByTimeAsync(1000);
48
+ await assertion;
49
+ expect(request).toHaveBeenCalledTimes(2);
50
+ });
51
+
52
+ it("does not retry without delays", async () => {
53
+ const request = vi.fn().mockRejectedValue(new Error("down"));
54
+
55
+ await expect(withRetries(request, [])).rejects.toThrow("down");
56
+ expect(request).toHaveBeenCalledTimes(1);
57
+ });
58
+ });
@@ -1 +0,0 @@
1
- export { useCheckoutStore } from "../stores/checkout";
@@ -1,22 +0,0 @@
1
- const stepRoutes = [
2
- "/bestellung/warenkorb",
3
- "/bestellung/zahlung-versand",
4
- "/bestellung/bestaetigen",
5
- ] as const;
6
-
7
- export const useCheckoutStore = defineStore("checkout", () => {
8
- const step = ref(0);
9
-
10
- function setStep(index: number) {
11
- step.value = index;
12
- }
13
-
14
- async function navigateToStep(index: number) {
15
- if (index < 0 || index >= stepRoutes.length) return;
16
- if (index <= step.value) {
17
- await navigateTo(stepRoutes[index]);
18
- }
19
- }
20
-
21
- return { step, setStep, navigateToStep };
22
- });