@shopware/composables 1.10.0 → 1.11.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.
Files changed (44) hide show
  1. package/README.md +7 -28
  2. package/dist/index.d.mts +23 -7
  3. package/dist/index.d.ts +23 -7
  4. package/dist/index.mjs +24 -19
  5. package/package.json +12 -11
  6. package/src/cms/useCmsElementConfig.test.ts +8 -0
  7. package/src/cms/useCmsElementConfig.ts +3 -0
  8. package/src/cms/useCmsElementImage.test.ts +23 -0
  9. package/src/cms/useCmsElementProductBox.test.ts +21 -0
  10. package/src/devtools/plugin.ts +1 -2
  11. package/src/mocks/Configurator.ts +36 -36
  12. package/src/useAddToCart/useAddToCart.test.ts +18 -1
  13. package/src/useAddress/useAddress.test.ts +41 -2
  14. package/src/useAddress/useAddress.ts +1 -1
  15. package/src/useCart/useCart.test.ts +30 -0
  16. package/src/useCartNotification/useCartNotification.test.ts +30 -0
  17. package/src/useCheckout/useCheckout.test.ts +43 -1
  18. package/src/useCmsMeta/useCmsMeta.test.ts +26 -0
  19. package/src/useCountries/useCountries.test.ts +14 -0
  20. package/src/useLocalWishlist/useLocalWishlist.test.ts +44 -5
  21. package/src/useLocalWishlist/useLocalWishlist.ts +3 -2
  22. package/src/useNavigationContext/useNavigationContext.test.ts +25 -24
  23. package/src/useNewsletter/useNewsletter.test.ts +16 -0
  24. package/src/useNewsletter/useNewsletter.ts +3 -3
  25. package/src/useOrderDetails/useOrderDetails.test.ts +92 -3
  26. package/src/useOrderDetails/useOrderDetails.ts +7 -3
  27. package/src/useOrderPayment/useOrderPayment.test.ts +55 -1
  28. package/src/usePrice/usePrice.test.ts +10 -0
  29. package/src/usePrice/usePrice.ts +2 -7
  30. package/src/useProduct/useProduct.test.ts +14 -1
  31. package/src/useProductAssociations/useProductAssociations.spec.ts +1 -0
  32. package/src/useProductConfigurator/useProductConfigurator.spec.ts +38 -0
  33. package/src/useProductConfigurator/useProductConfigurator.ts +1 -1
  34. package/src/useProductPrice/useProductPrice.test.ts +7 -7
  35. package/src/useProductPrice/useProductPrice.ts +12 -4
  36. package/src/useProductReviews/useProductReviews.test.ts +15 -3
  37. package/src/useSalutations/useSalutations.spec.ts +13 -0
  38. package/src/useSessionContext/useSessionContext.test.ts +122 -4
  39. package/src/useSessionContext/useSessionContext.ts +13 -1
  40. package/src/useSyncWishlist/useSyncWishlist.test.ts +60 -8
  41. package/src/useUrlResolver/useUrlResolver.test.ts +6 -12
  42. package/src/useUrlResolver/useUrlResolver.ts +4 -6
  43. package/src/useUser/useUser.test.ts +107 -15
  44. package/src/useWishlist/useWishlist.test.ts +124 -26
@@ -14,20 +14,29 @@ describe("useSyncWishlist", () => {
14
14
  describe("methods", () => {
15
15
  describe("addToWishlist", () => {
16
16
  it("should add product to the wishlist", async () => {
17
- const { vm } = useSetup(() => useSyncWishlist());
17
+ const { vm, injections } = useSetup(() => useSyncWishlist());
18
+ injections.apiClient.invoke.mockResolvedValue({});
19
+
20
+ await vm.addToWishlistSync("some-id");
18
21
 
19
- await expect(vm.addToWishlistSync("some-id")).resolves.toBe(undefined);
22
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
23
+ "addProductOnWishlist post /customer/wishlist/add/{productId}",
24
+ { pathParams: { productId: "some-id" } },
25
+ );
20
26
  });
21
27
  });
22
28
 
23
29
  describe("removeFromWishlist", () => {
24
- it("should remove product from the wishlist", () => {
25
- const { vm } = useSetup(() => useSyncWishlist());
30
+ it("should remove product from the wishlist", async () => {
31
+ const { vm, injections } = useSetup(() => useSyncWishlist());
32
+ injections.apiClient.invoke.mockResolvedValue({});
33
+
34
+ await vm.removeFromWishlistSync("some-id");
26
35
 
27
- vm.getWishlistProducts();
28
- vm.removeFromWishlistSync("some-id");
29
- // Mocked value
30
- expect(vm.count).toBe(vm.count);
36
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
37
+ "deleteProductOnWishlist delete /customer/wishlist/delete/{productId}",
38
+ { pathParams: { productId: "some-id" } },
39
+ );
31
40
  });
32
41
  });
33
42
 
@@ -84,6 +93,49 @@ describe("useSyncWishlist", () => {
84
93
  );
85
94
  expect(vm.count).toBe(9);
86
95
  expect(vm.items.length).toBe(1);
96
+ expect(vm.products).toStrictEqual([{ id: "test-id" }]);
97
+ });
98
+
99
+ it("getWishlistProducts with custom criteria", async () => {
100
+ const { vm, injections } = useSetup(() => useSyncWishlist());
101
+ injections.apiClient.invoke.mockResolvedValue({
102
+ data: {
103
+ products: {
104
+ elements: [],
105
+ total: 0,
106
+ },
107
+ },
108
+ });
109
+
110
+ await vm.getWishlistProducts({ limit: 10, page: 2 });
111
+
112
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
113
+ expect.stringContaining("readCustomerWishlist"),
114
+ expect.objectContaining({
115
+ body: expect.objectContaining({
116
+ limit: 10,
117
+ page: 2,
118
+ "total-count-mode": "exact",
119
+ }),
120
+ }),
121
+ );
122
+ });
123
+
124
+ it("getWishlistProducts with null total, page, limit uses defaults", async () => {
125
+ const { vm, injections } = useSetup(() => useSyncWishlist());
126
+ injections.apiClient.invoke.mockResolvedValue({
127
+ data: {
128
+ products: {
129
+ elements: [{ id: "id-1" }],
130
+ },
131
+ },
132
+ });
133
+
134
+ await vm.getWishlistProducts();
135
+
136
+ expect(vm.count).toBe(0);
137
+ expect(vm.currentPage).toBe(1);
138
+ expect(vm.limit).toBe(15);
87
139
  });
88
140
  });
89
141
 
@@ -1,14 +1,7 @@
1
- import { buildUrlPrefix } from "@shopware/helpers";
2
- import { describe, expect, it, vi } from "vitest";
1
+ import { describe, expect, it } from "vitest";
3
2
  import { useSetup } from "../_test";
4
3
  import { useUrlResolver } from "./useUrlResolver";
5
4
 
6
- vi.mock("@shopware/helpers", async () => {
7
- return {
8
- buildUrlPrefix: vi.fn(),
9
- };
10
- });
11
-
12
5
  describe("useUrlResolver", () => {
13
6
  it("resolve url", async () => {
14
7
  const { vm } = await useSetup(useUrlResolver);
@@ -16,10 +9,11 @@ describe("useUrlResolver", () => {
16
9
  expect(() => vm.resolveUrl("x".repeat(2084))).toThrow();
17
10
  });
18
11
 
19
- it("resolve url with navigation pattern", async () => {
20
- const { vm } = await useSetup(useUrlResolver);
21
- vm.resolveUrl("/de/navigation/123");
12
+ it("resolve url with navigation pattern and urlPrefix", async () => {
13
+ const { vm } = await useSetup(useUrlResolver, {
14
+ urlPrefix: "shop",
15
+ } as Parameters<typeof useSetup>[1]);
22
16
 
23
- expect(buildUrlPrefix).toHaveBeenCalled();
17
+ expect(vm.resolveUrl("/en/navigation/123")).toBe("/shop/en/navigation/123");
24
18
  });
25
19
  });
@@ -2,7 +2,8 @@ import { buildUrlPrefix } from "@shopware/helpers";
2
2
  import { inject } from "vue";
3
3
 
4
4
  export function useUrlResolver() {
5
- const getUrlPrefix = () => inject("urlPrefix", "");
5
+ const urlPrefix = inject("urlPrefix", "");
6
+ const getUrlPrefix = () => urlPrefix;
6
7
 
7
8
  const resolveUrl = (url: string) => {
8
9
  // @see: https://codeql.github.com/codeql-query-help/javascript/js-polynomial-redos/
@@ -11,14 +12,11 @@ export function useUrlResolver() {
11
12
  }
12
13
 
13
14
  const navigationPattern = /[a-zA-Z0-9]+\/navigation\/[a-zA-Z0-9]+/;
14
- const urlPrefix = getUrlPrefix();
15
+ const prefix = getUrlPrefix();
15
16
 
16
17
  if (navigationPattern.test(url)) {
17
18
  const newUrl = url.split("/").slice(1);
18
-
19
- if (newUrl.length > 0) {
20
- return `${buildUrlPrefix(newUrl.join("/"), urlPrefix)}`;
21
- }
19
+ return buildUrlPrefix(newUrl.join("/"), prefix).path;
22
20
  }
23
21
 
24
22
  return url;
@@ -73,8 +73,10 @@ describe("useUser", () => {
73
73
 
74
74
  it("register function", async () => {
75
75
  const { vm, injections } = useSetup(() => useUser());
76
- injections.apiClient.invoke.mockResolvedValue({ data: {} });
77
- await vm.register(REGISTRATION_DATA);
76
+ const registeredCustomer = { id: "reg-1", email: "test@test.testwwww" };
77
+ injections.apiClient.invoke.mockResolvedValue({ data: registeredCustomer });
78
+
79
+ const result = await vm.register(REGISTRATION_DATA);
78
80
 
79
81
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
80
82
  expect.stringContaining("register"),
@@ -85,6 +87,7 @@ describe("useUser", () => {
85
87
  },
86
88
  }),
87
89
  );
90
+ expect(result).toEqual(registeredCustomer);
88
91
  });
89
92
 
90
93
  it("register function with refresh", async () => {
@@ -138,26 +141,32 @@ describe("useUser", () => {
138
141
 
139
142
  it("logout", async () => {
140
143
  const { vm, injections } = useSetup(() => useUser());
141
- injections.apiClient.invoke.mockResolvedValue({ data: {} });
142
- await vm.logout();
144
+ const logoutResponse = { data: { redirectUrl: "/" } };
145
+ injections.apiClient.invoke.mockResolvedValue(logoutResponse);
146
+
147
+ const result = await vm.logout();
143
148
 
144
149
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
145
150
  expect.stringContaining("logoutCustomer"),
146
151
  );
152
+ expect(result).toEqual(logoutResponse.data);
147
153
  });
148
154
 
149
155
  it("refreshUser", async () => {
150
156
  const { vm, injections } = useSetup(() => useUser());
151
- injections.apiClient.invoke.mockResolvedValue({ data: {} });
152
- await vm.refreshUser();
157
+ const customerData = { id: "cust-1", email: "test@test.com" };
158
+ injections.apiClient.invoke.mockResolvedValue({ data: customerData });
159
+
160
+ const result = await vm.refreshUser();
153
161
 
154
162
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
155
163
  expect.stringContaining("readCustomer"),
156
164
  expect.anything(),
157
165
  );
166
+ expect(result).toEqual(customerData);
158
167
  });
159
168
 
160
- it("refreshUser - error", async () => {
169
+ it("refreshUser - error clears user", async () => {
161
170
  const { vm } = useSetup(() => useUser(), {
162
171
  apiClient: {
163
172
  invoke: vi.fn().mockImplementation(() => {
@@ -165,10 +174,10 @@ describe("useUser", () => {
165
174
  }),
166
175
  },
167
176
  });
177
+ userFromContextRef.value = { id: "existing", active: true, guest: false };
168
178
 
169
- await expect(async () => {
170
- await vm.refreshUser();
171
- }).rejects.toThrowError();
179
+ await expect(vm.refreshUser()).rejects.toThrowError();
180
+ expect(vm.user).toBeUndefined();
172
181
  });
173
182
 
174
183
  it("loadCountry", async () => {
@@ -324,8 +333,12 @@ describe("useUser", () => {
324
333
 
325
334
  it("loadSalutation", async () => {
326
335
  const { vm, injections } = useSetup(() => useUser());
327
- injections.apiClient.invoke.mockResolvedValue({ data: {} });
328
- await vm.loadSalutation("test");
336
+ const salutationData = { elements: [{ id: "test", name: "test" }] };
337
+ injections.apiClient.invoke.mockResolvedValue({
338
+ data: salutationData,
339
+ });
340
+
341
+ const result = await vm.loadSalutation("test");
329
342
 
330
343
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
331
344
  expect.stringContaining("readSalutation"),
@@ -341,13 +354,19 @@ describe("useUser", () => {
341
354
  },
342
355
  }),
343
356
  );
357
+ expect(vm.salutation).toEqual({ id: "test", name: "test" });
358
+ expect(result).toEqual(salutationData);
359
+ });
344
360
 
361
+ it("loadSalutation with empty elements sets salutation to null", async () => {
362
+ const { vm, injections } = useSetup(() => useUser());
345
363
  injections.apiClient.invoke.mockResolvedValue({
346
- data: { elements: [{ id: "test", name: "test" }] },
364
+ data: { elements: [] },
347
365
  });
348
- await vm.loadSalutation("test");
349
366
 
350
- expect(vm.salutation).toEqual({ id: "test", name: "test" });
367
+ await vm.loadSalutation("non-existent");
368
+
369
+ expect(vm.salutation).toBeNull();
351
370
  });
352
371
 
353
372
  it("userDefaultPaymentMethod - should fallback to legacy defaultPaymentMethod when lastPaymentMethod is not available", () => {
@@ -372,6 +391,19 @@ describe("useUser", () => {
372
391
  userFromContextRef.value = undefined;
373
392
  });
374
393
 
394
+ it("isLoggedIn - false when user has id but active is false", () => {
395
+ const { vm } = useSetup(() => useUser());
396
+ userFromContextRef.value = {
397
+ id: "user-1",
398
+ active: false,
399
+ guest: false,
400
+ };
401
+
402
+ expect(vm.isLoggedIn).toBe(false);
403
+
404
+ userFromContextRef.value = undefined;
405
+ });
406
+
375
407
  it("userDefaultPaymentMethod - should return null when no payment methods are available", () => {
376
408
  const { vm } = useSetup(() => useUser());
377
409
 
@@ -388,6 +420,66 @@ describe("useUser", () => {
388
420
  userFromContextRef.value = undefined;
389
421
  });
390
422
 
423
+ it("register function with inactive user", async () => {
424
+ const { vm, injections } = useSetup(() => useUser());
425
+ injections.apiClient.invoke.mockResolvedValue({
426
+ data: { active: false, id: "inactive-1" },
427
+ });
428
+ const result = await vm.register(REGISTRATION_DATA);
429
+ expect(result).toEqual({ active: false, id: "inactive-1" });
430
+ expect(vm.isLoggedIn).toBe(false);
431
+ });
432
+
433
+ it("loadCountry with empty elements", async () => {
434
+ const { vm, injections } = useSetup(() => useUser());
435
+ injections.apiClient.invoke.mockResolvedValue({
436
+ data: { elements: [] },
437
+ });
438
+ await vm.loadCountry("non-existent");
439
+ expect(vm.country).toBeNull();
440
+ });
441
+
442
+ it("isCustomerSession and isGuestSession", () => {
443
+ const { vm } = useSetup(() => useUser());
444
+ userFromContextRef.value = { id: "cust-1", active: true, guest: false };
445
+ expect(vm.isCustomerSession).toBe(true);
446
+ expect(vm.isGuestSession).toBe(false);
447
+
448
+ userFromContextRef.value = { id: "guest-1", active: true, guest: true };
449
+ expect(vm.isCustomerSession).toBe(false);
450
+ expect(vm.isGuestSession).toBe(true);
451
+ });
452
+
453
+ it("userDefaultBillingAddress and userDefaultShippingAddress", () => {
454
+ const { vm } = useSetup(() => useUser());
455
+
456
+ expect(vm.userDefaultBillingAddress).toBeNull();
457
+ expect(vm.userDefaultShippingAddress).toBeNull();
458
+
459
+ userFromContextRef.value = {
460
+ id: "cust-1",
461
+ defaultBillingAddress: { city: "Berlin" },
462
+ defaultShippingAddress: { city: "Munich" },
463
+ };
464
+ expect(vm.userDefaultBillingAddress).toStrictEqual({ city: "Berlin" });
465
+ expect(vm.userDefaultShippingAddress).toStrictEqual({ city: "Munich" });
466
+ });
467
+
468
+ it("defaultBillingAddressId and defaultShippingAddressId", () => {
469
+ const { vm } = useSetup(() => useUser());
470
+
471
+ expect(vm.defaultBillingAddressId).toBeNull();
472
+ expect(vm.defaultShippingAddressId).toBeNull();
473
+
474
+ userFromContextRef.value = {
475
+ id: "cust-1",
476
+ defaultBillingAddressId: "billing-1",
477
+ defaultShippingAddressId: "shipping-1",
478
+ };
479
+ expect(vm.defaultBillingAddressId).toBe("billing-1");
480
+ expect(vm.defaultShippingAddressId).toBe("shipping-1");
481
+ });
482
+
391
483
  it("userDefaultPaymentMethod - should fallback when lastPaymentMethod.translated is falsy", () => {
392
484
  const { vm } = useSetup(() => useUser());
393
485
 
@@ -1,4 +1,4 @@
1
- import { describe, expect, it, vi } from "vitest";
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
2
  import { computed, ref } from "vue";
3
3
  import { useSyncWishlist, useUser, useWishlist } from "#imports";
4
4
  import type { Schemas } from "#shopware";
@@ -10,33 +10,38 @@ const getMockedUser = (isLoggedIn: boolean, isGuestSession: boolean) =>
10
10
  isGuestSession: ref(isGuestSession),
11
11
  }) as ReturnType<typeof useUser>;
12
12
 
13
+ const defaultLocalItems = [
14
+ "local-testId-1",
15
+ "local-testId-2",
16
+ "local-testId-3",
17
+ "local-testId-4",
18
+ "local-testId-5",
19
+ "local-testId-6",
20
+ "local-testId-7",
21
+ "local-testId-8",
22
+ "local-testId-9",
23
+ "local-testId-10",
24
+ "local-testId-11",
25
+ "local-testId-12",
26
+ "local-testId-13",
27
+ "local-testId-14",
28
+ "local-testId-15",
29
+ "local-testId-16",
30
+ "local-testId-17",
31
+ ];
32
+ let mockLocalItems: string[] = [...defaultLocalItems];
33
+
13
34
  vi.mock("../useLocalWishlist/useLocalWishlist.ts", () => ({
14
35
  useLocalWishlist() {
15
36
  return {
16
37
  getWishlistProducts: () => undefined,
17
38
  items: {
18
- value: [
19
- "local-testId-1",
20
- "local-testId-2",
21
- "local-testId-3",
22
- "local-testId-4",
23
- "local-testId-5",
24
- "local-testId-6",
25
- "local-testId-7",
26
- "local-testId-8",
27
- "local-testId-9",
28
- "local-testId-10",
29
- "local-testId-11",
30
- "local-testId-12",
31
- "local-testId-13",
32
- "local-testId-14",
33
- "local-testId-15",
34
- "local-testId-16",
35
- "local-testId-17",
36
- ],
39
+ get value() {
40
+ return [...mockLocalItems];
41
+ },
37
42
  },
38
43
  clearWishlist: () => undefined,
39
- count: ref(17),
44
+ count: ref(mockLocalItems.length),
40
45
  };
41
46
  },
42
47
  }));
@@ -44,6 +49,10 @@ vi.mock("../useLocalWishlist/useLocalWishlist.ts", () => ({
44
49
  vi.mock("../useSyncWishlist/useSyncWishlist.ts");
45
50
  vi.mock("../useUser/useUser.ts");
46
51
 
52
+ beforeEach(() => {
53
+ mockLocalItems = [...defaultLocalItems];
54
+ });
55
+
47
56
  describe("useWishlist - not logged in user", () => {
48
57
  it("should merge wishlist products", () => {
49
58
  vi.mocked(useUser).mockReturnValue(getMockedUser(false, true));
@@ -116,13 +125,58 @@ describe("useWishlist - not logged in user", () => {
116
125
 
117
126
  expect(Number(vm.currentPage)).toBe(2);
118
127
  });
128
+
129
+ it("should handle query without limit property", async () => {
130
+ vi.mocked(useUser).mockReturnValue(getMockedUser(false, true));
131
+ vi.mocked(useSyncWishlist).mockReturnValue({
132
+ getWishlistProducts: () => new Promise<void>((resolve) => resolve()),
133
+ items: computed((): string[] => []),
134
+ addToWishlistSync: () => undefined,
135
+ mergeWishlistProducts: () => undefined,
136
+ removeFromWishlistSync: () => undefined,
137
+ count: computed(() => 0),
138
+ currentPage: computed(() => 1),
139
+ limit: computed(() => 15),
140
+ products: computed((): Schemas["Product"][] => []),
141
+ isLoading: computed(() => false),
142
+ });
143
+ const { vm } = useSetup(() => useWishlist());
144
+
145
+ await vm.getWishlistProducts({ page: 2 });
146
+
147
+ expect(Number(vm.totalPagesCount)).toBe(2);
148
+ });
149
+
150
+ it("should update limit when query has limit", async () => {
151
+ vi.mocked(useUser).mockReturnValue(getMockedUser(false, true));
152
+ vi.mocked(useSyncWishlist).mockReturnValue({
153
+ getWishlistProducts: () => new Promise<void>((resolve) => resolve()),
154
+ items: computed((): string[] => []),
155
+ addToWishlistSync: () => undefined,
156
+ mergeWishlistProducts: () => undefined,
157
+ removeFromWishlistSync: () => undefined,
158
+ count: computed(() => 0),
159
+ currentPage: computed(() => 1),
160
+ limit: computed(() => 10),
161
+ products: computed((): Schemas["Product"][] => []),
162
+ isLoading: computed(() => false),
163
+ });
164
+ const { vm } = useSetup(() => useWishlist());
165
+
166
+ await vm.getWishlistProducts({ limit: 10 });
167
+
168
+ expect(Number(vm.totalPagesCount)).toBe(2);
169
+ });
119
170
  });
120
171
 
121
172
  describe("useWishlist - logged in user", () => {
122
- it("should merge wishlist products", () => {
173
+ it("should merge wishlist products", async () => {
174
+ const mergeWishlistProductsSyncSpy = vi.fn().mockResolvedValue(undefined);
175
+ const getWishlistProductsSyncSpy = vi.fn().mockResolvedValue(undefined);
176
+ const removeFromWishlistSyncSpy = vi.fn().mockResolvedValue(undefined);
123
177
  vi.mocked(useUser).mockReturnValue(getMockedUser(true, false));
124
178
  vi.mocked(useSyncWishlist).mockReturnValue({
125
- getWishlistProducts: () => new Promise<void>((resolve) => resolve()),
179
+ getWishlistProducts: getWishlistProductsSyncSpy,
126
180
  items: computed((): string[] => {
127
181
  return [
128
182
  "local-test-1",
@@ -143,8 +197,8 @@ describe("useWishlist - logged in user", () => {
143
197
  ];
144
198
  }),
145
199
  addToWishlistSync: () => undefined,
146
- mergeWishlistProducts: () => undefined,
147
- removeFromWishlistSync: () => undefined,
200
+ mergeWishlistProducts: mergeWishlistProductsSyncSpy,
201
+ removeFromWishlistSync: removeFromWishlistSyncSpy,
148
202
  count: computed(() => 15),
149
203
  currentPage: computed(() => 1),
150
204
  limit: computed(() => 15),
@@ -155,8 +209,27 @@ describe("useWishlist - logged in user", () => {
155
209
 
156
210
  vm.clearWishlist();
157
211
  vm.getWishlistProducts();
158
- vm.mergeWishlistProducts();
212
+ await vm.mergeWishlistProducts();
159
213
 
214
+ expect(mergeWishlistProductsSyncSpy).toHaveBeenCalledWith([
215
+ "local-testId-1",
216
+ "local-testId-2",
217
+ "local-testId-3",
218
+ "local-testId-4",
219
+ "local-testId-5",
220
+ "local-testId-6",
221
+ "local-testId-7",
222
+ "local-testId-8",
223
+ "local-testId-9",
224
+ "local-testId-10",
225
+ "local-testId-11",
226
+ "local-testId-12",
227
+ "local-testId-13",
228
+ "local-testId-14",
229
+ "local-testId-15",
230
+ "local-testId-16",
231
+ "local-testId-17",
232
+ ]);
160
233
  expect(vm.items.length).toBe(15);
161
234
  expect(vm.count).toBe(15);
162
235
  });
@@ -184,4 +257,29 @@ describe("useWishlist - logged in user", () => {
184
257
  "local-test-15",
185
258
  ]);
186
259
  });
260
+
261
+ it("mergeWishlistProducts when local wishlist is empty skips merge", async () => {
262
+ const mergeWishlistProductsSyncSpy = vi.fn().mockResolvedValue(undefined);
263
+ const getWishlistProductsSyncSpy = vi.fn().mockResolvedValue(undefined);
264
+ mockLocalItems = [];
265
+ vi.mocked(useUser).mockReturnValue(getMockedUser(true, false));
266
+ vi.mocked(useSyncWishlist).mockReturnValue({
267
+ getWishlistProducts: getWishlistProductsSyncSpy,
268
+ items: computed((): string[] => []),
269
+ addToWishlistSync: () => undefined,
270
+ mergeWishlistProducts: mergeWishlistProductsSyncSpy,
271
+ removeFromWishlistSync: () => undefined,
272
+ count: computed(() => 0),
273
+ currentPage: computed(() => 1),
274
+ limit: computed(() => 15),
275
+ products: computed((): Schemas["Product"][] => []),
276
+ isLoading: computed(() => false),
277
+ });
278
+ const { vm } = useSetup(() => useWishlist());
279
+
280
+ await vm.mergeWishlistProducts();
281
+
282
+ expect(mergeWishlistProductsSyncSpy).not.toHaveBeenCalled();
283
+ expect(getWishlistProductsSyncSpy).toHaveBeenCalled();
284
+ });
187
285
  });