@shopware/composables 1.9.1 → 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.
- package/README.md +12 -5
- package/dist/index.d.mts +116 -34
- package/dist/index.d.ts +116 -34
- package/dist/index.mjs +117 -74
- package/package.json +13 -12
- package/src/cms/cmsAssociations.ts +5 -1
- package/src/cms/useCmsElementConfig.test.ts +8 -0
- package/src/cms/useCmsElementConfig.ts +4 -1
- package/src/cms/useCmsElementImage.test.ts +23 -0
- package/src/cms/useCmsElementProductBox.test.ts +21 -0
- package/src/devtools/plugin.ts +1 -2
- package/src/mocks/Configurator.ts +36 -36
- package/src/types/cmsBlockTypes.ts +2 -0
- package/src/types/cmsElementTypes.ts +24 -18
- package/src/useAddToCart/useAddToCart.test.ts +18 -1
- package/src/useAddress/useAddress.test.ts +41 -2
- package/src/useAddress/useAddress.ts +1 -1
- package/src/useCart/useCart.test.ts +42 -0
- package/src/useCart/useCart.ts +17 -0
- package/src/useCartNotification/useCartNotification.test.ts +30 -0
- package/src/useCheckout/useCheckout.test.ts +43 -1
- package/src/useCmsMeta/useCmsMeta.test.ts +26 -0
- package/src/useCountries/useCountries.test.ts +14 -0
- package/src/useCustomerOrders/useCustomerOrders.ts +1 -1
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +19 -21
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.ts +23 -30
- package/src/useLandingSearch/useLandingSearch.test.ts +1 -1
- package/src/useLandingSearch/useLandingSearch.ts +1 -1
- package/src/useListing/useListing.test.ts +73 -0
- package/src/useListing/useListing.ts +10 -3
- package/src/useLocalWishlist/useLocalWishlist.test.ts +44 -5
- package/src/useLocalWishlist/useLocalWishlist.ts +3 -2
- package/src/useNavigationContext/useNavigationContext.test.ts +25 -24
- package/src/useNewsletter/useNewsletter.test.ts +16 -0
- package/src/useNewsletter/useNewsletter.ts +13 -0
- package/src/useOrderDetails/useOrderDetails.test.ts +92 -3
- package/src/useOrderDetails/useOrderDetails.ts +12 -14
- package/src/useOrderPayment/useOrderPayment.test.ts +55 -1
- package/src/useOrderPayment/useOrderPayment.ts +1 -0
- package/src/usePrice/usePrice.test.ts +10 -0
- package/src/usePrice/usePrice.ts +2 -7
- package/src/useProduct/useProduct.test.ts +14 -1
- package/src/useProductAssociations/useProductAssociations.spec.ts +1 -0
- package/src/useProductConfigurator/useProductConfigurator.spec.ts +38 -0
- package/src/useProductConfigurator/useProductConfigurator.ts +1 -1
- package/src/useProductPrice/useProductPrice.test.ts +7 -7
- package/src/useProductPrice/useProductPrice.ts +12 -4
- package/src/useProductReviews/useProductReviews.test.ts +15 -3
- package/src/useProductWishlist/useProductWishlist.ts +2 -2
- package/src/useSalutations/useSalutations.spec.ts +13 -0
- package/src/useSessionContext/useSessionContext.test.ts +122 -4
- package/src/useSessionContext/useSessionContext.ts +14 -2
- package/src/useSyncWishlist/useSyncWishlist.test.ts +94 -25
- package/src/useSyncWishlist/useSyncWishlist.ts +27 -8
- package/src/useUrlResolver/useUrlResolver.test.ts +6 -12
- package/src/useUrlResolver/useUrlResolver.ts +4 -6
- package/src/useUser/useUser.test.ts +233 -18
- package/src/useUser/useUser.ts +6 -1
- package/src/useWishlist/useWishlist.test.ts +133 -26
- package/src/useWishlist/useWishlist.ts +22 -6
|
@@ -2,16 +2,16 @@ const Configurator = [
|
|
|
2
2
|
{
|
|
3
3
|
translated: {
|
|
4
4
|
name: "Colour",
|
|
5
|
-
description:
|
|
5
|
+
description: undefined,
|
|
6
6
|
position: 1,
|
|
7
7
|
customFields: {},
|
|
8
8
|
},
|
|
9
9
|
createdAt: "2020-08-06T06:26:29.726+00:00",
|
|
10
|
-
updatedAt:
|
|
10
|
+
updatedAt: undefined,
|
|
11
11
|
name: "Colour",
|
|
12
12
|
displayType: "text",
|
|
13
13
|
sortingType: "alphanumeric",
|
|
14
|
-
description:
|
|
14
|
+
description: undefined,
|
|
15
15
|
position: 1,
|
|
16
16
|
filterable: true,
|
|
17
17
|
visibleOnProductDetailPage: true,
|
|
@@ -23,47 +23,47 @@ const Configurator = [
|
|
|
23
23
|
groupId: "15de997512de4e229d2db1b72aca16f5",
|
|
24
24
|
name: "red",
|
|
25
25
|
position: 13,
|
|
26
|
-
colorHexCode:
|
|
27
|
-
mediaId:
|
|
28
|
-
group:
|
|
29
|
-
media:
|
|
30
|
-
customFields:
|
|
26
|
+
colorHexCode: undefined,
|
|
27
|
+
mediaId: undefined,
|
|
28
|
+
group: undefined,
|
|
29
|
+
media: undefined,
|
|
30
|
+
customFields: undefined,
|
|
31
31
|
id: "cc02c6cf39ad43d5856a25f8928490bf",
|
|
32
32
|
apiAlias: "property_group_option",
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
translated: { name: "blue", position: 17, customFields: {} },
|
|
36
36
|
createdAt: "2020-08-06T06:26:29.667+00:00",
|
|
37
|
-
updatedAt:
|
|
37
|
+
updatedAt: undefined,
|
|
38
38
|
groupId: "15de997512de4e229d2db1b72aca16f5",
|
|
39
39
|
name: "blue",
|
|
40
40
|
position: 17,
|
|
41
|
-
colorHexCode:
|
|
42
|
-
mediaId:
|
|
43
|
-
group:
|
|
44
|
-
media:
|
|
45
|
-
customFields:
|
|
41
|
+
colorHexCode: undefined,
|
|
42
|
+
mediaId: undefined,
|
|
43
|
+
group: undefined,
|
|
44
|
+
media: undefined,
|
|
45
|
+
customFields: undefined,
|
|
46
46
|
id: "862a4c3c1326423a874b25b6d9ae2101",
|
|
47
47
|
apiAlias: "property_group_option",
|
|
48
48
|
},
|
|
49
49
|
],
|
|
50
|
-
customFields:
|
|
50
|
+
customFields: undefined,
|
|
51
51
|
id: "15de997512de4e229d2db1b72aca16f5",
|
|
52
52
|
apiAlias: "property_group",
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
translated: {
|
|
56
56
|
name: "Size",
|
|
57
|
-
description:
|
|
57
|
+
description: undefined,
|
|
58
58
|
position: 1,
|
|
59
59
|
customFields: {},
|
|
60
60
|
},
|
|
61
61
|
createdAt: "2020-08-06T06:26:29.930+00:00",
|
|
62
|
-
updatedAt:
|
|
62
|
+
updatedAt: undefined,
|
|
63
63
|
name: "Size",
|
|
64
64
|
displayType: "text",
|
|
65
65
|
sortingType: "alphanumeric",
|
|
66
|
-
description:
|
|
66
|
+
description: undefined,
|
|
67
67
|
position: 1,
|
|
68
68
|
filterable: true,
|
|
69
69
|
visibleOnProductDetailPage: true,
|
|
@@ -75,46 +75,46 @@ const Configurator = [
|
|
|
75
75
|
groupId: "6d71c64e67d64876b9c7fbb97fcba3c6",
|
|
76
76
|
name: "L",
|
|
77
77
|
position: 24,
|
|
78
|
-
colorHexCode:
|
|
79
|
-
mediaId:
|
|
80
|
-
group:
|
|
81
|
-
media:
|
|
82
|
-
customFields:
|
|
78
|
+
colorHexCode: undefined,
|
|
79
|
+
mediaId: undefined,
|
|
80
|
+
group: undefined,
|
|
81
|
+
media: undefined,
|
|
82
|
+
customFields: undefined,
|
|
83
83
|
id: "f13d254355cc41e28637e3428e23f279",
|
|
84
84
|
apiAlias: "property_group_option",
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
translated: { name: "M", position: 23, customFields: {} },
|
|
88
88
|
createdAt: "2020-08-06T06:26:29.877+00:00",
|
|
89
|
-
updatedAt:
|
|
89
|
+
updatedAt: undefined,
|
|
90
90
|
groupId: "6d71c64e67d64876b9c7fbb97fcba3c6",
|
|
91
91
|
name: "M",
|
|
92
92
|
position: 23,
|
|
93
|
-
colorHexCode:
|
|
94
|
-
mediaId:
|
|
95
|
-
group:
|
|
96
|
-
media:
|
|
97
|
-
customFields:
|
|
93
|
+
colorHexCode: undefined,
|
|
94
|
+
mediaId: undefined,
|
|
95
|
+
group: undefined,
|
|
96
|
+
media: undefined,
|
|
97
|
+
customFields: undefined,
|
|
98
98
|
id: "24495f5441004fb9bcde8e1645714063",
|
|
99
99
|
apiAlias: "property_group_option",
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
translated: { name: "S", position: 22, customFields: {} },
|
|
103
103
|
createdAt: "2020-08-06T06:26:29.923+00:00",
|
|
104
|
-
updatedAt:
|
|
104
|
+
updatedAt: undefined,
|
|
105
105
|
groupId: "6d71c64e67d64876b9c7fbb97fcba3c6",
|
|
106
106
|
name: "S",
|
|
107
107
|
position: 22,
|
|
108
|
-
colorHexCode:
|
|
109
|
-
mediaId:
|
|
110
|
-
group:
|
|
111
|
-
media:
|
|
112
|
-
customFields:
|
|
108
|
+
colorHexCode: undefined,
|
|
109
|
+
mediaId: undefined,
|
|
110
|
+
group: undefined,
|
|
111
|
+
media: undefined,
|
|
112
|
+
customFields: undefined,
|
|
113
113
|
id: "dcd3a971b122413785ed56a5782ed5b7",
|
|
114
114
|
apiAlias: "property_group_option",
|
|
115
115
|
},
|
|
116
116
|
],
|
|
117
|
-
customFields:
|
|
117
|
+
customFields: undefined,
|
|
118
118
|
id: "6d71c64e67d64876b9c7fbb97fcba3c6",
|
|
119
119
|
apiAlias: "property_group",
|
|
120
120
|
},
|
|
@@ -31,7 +31,7 @@ type ElementFieldConfig = {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// Text
|
|
34
|
-
export type CmsElementText = Schemas["CmsSlot"] & {
|
|
34
|
+
export type CmsElementText = Omit<Schemas["CmsSlot"], "config"> & {
|
|
35
35
|
type: "text" | typeof String;
|
|
36
36
|
slot: typeof String;
|
|
37
37
|
config: TextElementConfig;
|
|
@@ -46,7 +46,7 @@ export type CmsElementText = Schemas["CmsSlot"] & {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
// HTML
|
|
49
|
-
export type CmsElementHtml = Schemas["CmsSlot"] & {
|
|
49
|
+
export type CmsElementHtml = Omit<Schemas["CmsSlot"], "config"> & {
|
|
50
50
|
type: "html";
|
|
51
51
|
data: {
|
|
52
52
|
content: string;
|
|
@@ -68,7 +68,7 @@ type ImageElementConfig = {
|
|
|
68
68
|
horizontalAlign: ElementConfig<VerticalAlign>;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
export type CmsElementImage = Schemas["CmsSlot"] & {
|
|
71
|
+
export type CmsElementImage = Omit<Schemas["CmsSlot"], "config"> & {
|
|
72
72
|
type: "image";
|
|
73
73
|
config: ImageElementConfig;
|
|
74
74
|
data: {
|
|
@@ -102,7 +102,7 @@ type ImageSliderElementConfig = ImageElementConfig &
|
|
|
102
102
|
>;
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
export type CmsElementImageSlider = Schemas["CmsSlot"] & {
|
|
105
|
+
export type CmsElementImageSlider = Omit<Schemas["CmsSlot"], "config"> & {
|
|
106
106
|
type: "image-slider";
|
|
107
107
|
config: ImageSliderElementConfig;
|
|
108
108
|
data: {
|
|
@@ -128,7 +128,7 @@ type ImageGalleryElementConfig = ImageSliderElementConfig & {
|
|
|
128
128
|
zoom: ElementConfig<boolean>;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
export type CmsElementImageGallery = Schemas["CmsSlot"] & {
|
|
131
|
+
export type CmsElementImageGallery = Omit<Schemas["CmsSlot"], "config"> & {
|
|
132
132
|
type: "image-gallery";
|
|
133
133
|
config: ImageGalleryElementConfig;
|
|
134
134
|
data: {
|
|
@@ -161,7 +161,7 @@ type YouTubeVideoElementConfig = {
|
|
|
161
161
|
needsConfirmation: ElementConfig<boolean>;
|
|
162
162
|
advancedPrivacyMode: ElementConfig<boolean>;
|
|
163
163
|
};
|
|
164
|
-
export type CmsElementYoutubeVideo = Schemas["CmsSlot"] & {
|
|
164
|
+
export type CmsElementYoutubeVideo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
165
165
|
type: "youtube-video";
|
|
166
166
|
config: YouTubeVideoElementConfig;
|
|
167
167
|
data: {
|
|
@@ -189,7 +189,7 @@ type VimeoVideoElementConfig = {
|
|
|
189
189
|
needsConfirmation: ElementConfig<boolean>;
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
export type CmsElementVimeoVideo = Schemas["CmsSlot"] & {
|
|
192
|
+
export type CmsElementVimeoVideo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
193
193
|
type: "vimeo-video";
|
|
194
194
|
config: VimeoVideoElementConfig;
|
|
195
195
|
data: {
|
|
@@ -208,7 +208,7 @@ type ProductBoxElementConfig = {
|
|
|
208
208
|
product: ElementConfig<string>;
|
|
209
209
|
};
|
|
210
210
|
|
|
211
|
-
export type CmsElementProductBox = Schemas["CmsSlot"] & {
|
|
211
|
+
export type CmsElementProductBox = Omit<Schemas["CmsSlot"], "config"> & {
|
|
212
212
|
type: "product-box";
|
|
213
213
|
config: ProductBoxElementConfig;
|
|
214
214
|
data: {
|
|
@@ -234,7 +234,7 @@ type ProductSliderElementConfig = {
|
|
|
234
234
|
productStreamSorting: ElementConfig<string>;
|
|
235
235
|
};
|
|
236
236
|
|
|
237
|
-
export type CmsElementProductSlider = Schemas["CmsSlot"] & {
|
|
237
|
+
export type CmsElementProductSlider = Omit<Schemas["CmsSlot"], "config"> & {
|
|
238
238
|
type: "product-slider";
|
|
239
239
|
config: ProductSliderElementConfig;
|
|
240
240
|
data: {
|
|
@@ -256,7 +256,7 @@ type CmsSidebarFilterElementConfig = {
|
|
|
256
256
|
verticalAlign: ElementConfig<VerticalAlign>;
|
|
257
257
|
};
|
|
258
258
|
|
|
259
|
-
export type CmsElementSidebarFilter = Schemas["CmsSlot"] & {
|
|
259
|
+
export type CmsElementSidebarFilter = Omit<Schemas["CmsSlot"], "config"> & {
|
|
260
260
|
type: "sidebar-filter";
|
|
261
261
|
config: CmsSidebarFilterElementConfig;
|
|
262
262
|
};
|
|
@@ -273,7 +273,7 @@ type CmsProductListingElementConfig = {
|
|
|
273
273
|
propertyWhitelist: ElementConfig<string[]>;
|
|
274
274
|
};
|
|
275
275
|
|
|
276
|
-
export type CmsElementProductListing = Schemas["CmsSlot"] & {
|
|
276
|
+
export type CmsElementProductListing = Omit<Schemas["CmsSlot"], "config"> & {
|
|
277
277
|
type: "product-listing";
|
|
278
278
|
config: CmsProductListingElementConfig;
|
|
279
279
|
data: {
|
|
@@ -286,7 +286,10 @@ export type CmsElementProductListing = Schemas["CmsSlot"] & {
|
|
|
286
286
|
|
|
287
287
|
type CategoryNavigationElementConfig = unknown;
|
|
288
288
|
|
|
289
|
-
export type CmsElementCategoryNavigation =
|
|
289
|
+
export type CmsElementCategoryNavigation = Omit<
|
|
290
|
+
Schemas["CmsSlot"],
|
|
291
|
+
"config"
|
|
292
|
+
> & {
|
|
290
293
|
type: "category-navigation";
|
|
291
294
|
config: CategoryNavigationElementConfig;
|
|
292
295
|
};
|
|
@@ -296,7 +299,10 @@ type ProductDescriptionReviewsElementConfig = {
|
|
|
296
299
|
alignment: ElementConfig<VerticalAlign>;
|
|
297
300
|
};
|
|
298
301
|
|
|
299
|
-
export type CmsElementProductDescriptionReviews =
|
|
302
|
+
export type CmsElementProductDescriptionReviews = Omit<
|
|
303
|
+
Schemas["CmsSlot"],
|
|
304
|
+
"config"
|
|
305
|
+
> & {
|
|
300
306
|
type: "product-description-reviews";
|
|
301
307
|
config: ProductDescriptionReviewsElementConfig;
|
|
302
308
|
data: {
|
|
@@ -314,7 +320,7 @@ export type CmsElementProductDescriptionReviews = Schemas["CmsSlot"] & {
|
|
|
314
320
|
|
|
315
321
|
type BuyBoxElementConfig = ProductDescriptionReviewsElementConfig;
|
|
316
322
|
// buy box has the same interface in data as product description reviews! unify later
|
|
317
|
-
export type CmsElementBuyBox = Schemas["CmsSlot"] & {
|
|
323
|
+
export type CmsElementBuyBox = Omit<Schemas["CmsSlot"], "config"> & {
|
|
318
324
|
type: "buy-box";
|
|
319
325
|
config: BuyBoxElementConfig;
|
|
320
326
|
data: {
|
|
@@ -337,7 +343,7 @@ type CrossSellingElementConfig = {
|
|
|
337
343
|
displayMode: ElementConfig<DisplayMode>;
|
|
338
344
|
};
|
|
339
345
|
|
|
340
|
-
export type CmsElementCrossSelling = Schemas["CmsSlot"] & {
|
|
346
|
+
export type CmsElementCrossSelling = Omit<Schemas["CmsSlot"], "config"> & {
|
|
341
347
|
type: "cross-selling";
|
|
342
348
|
config: CrossSellingElementConfig;
|
|
343
349
|
data: {
|
|
@@ -356,14 +362,14 @@ type FormElementConfig = {
|
|
|
356
362
|
defaultMailReceiver: ElementConfig<boolean>;
|
|
357
363
|
};
|
|
358
364
|
|
|
359
|
-
export type CmsElementForm = Schemas["CmsSlot"] & {
|
|
365
|
+
export type CmsElementForm = Omit<Schemas["CmsSlot"], "config"> & {
|
|
360
366
|
type: "form";
|
|
361
367
|
config: FormElementConfig;
|
|
362
368
|
data: Schemas["Salutation"][];
|
|
363
369
|
};
|
|
364
370
|
|
|
365
371
|
// Product Name
|
|
366
|
-
export type CmsElementProductName = Schemas["CmsSlot"] & {
|
|
372
|
+
export type CmsElementProductName = Omit<Schemas["CmsSlot"], "config"> & {
|
|
367
373
|
type: "product-name";
|
|
368
374
|
config: TextElementConfig;
|
|
369
375
|
fieldConfig: ElementFieldConfig[];
|
|
@@ -377,7 +383,7 @@ export type CmsElementProductName = Schemas["CmsSlot"] & {
|
|
|
377
383
|
};
|
|
378
384
|
|
|
379
385
|
// Manufacturer Logo
|
|
380
|
-
export type CmsElementManufacturerLogo = Schemas["CmsSlot"] & {
|
|
386
|
+
export type CmsElementManufacturerLogo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
381
387
|
type: "manufacturer-logo";
|
|
382
388
|
config: ImageElementConfig;
|
|
383
389
|
data: {
|
|
@@ -4,7 +4,7 @@ import { useSetup } from "../_test";
|
|
|
4
4
|
import ProductMocked from "../mocks/Product";
|
|
5
5
|
import { useAddToCart } from "./useAddToCart";
|
|
6
6
|
|
|
7
|
-
describe("
|
|
7
|
+
describe("useAddToCart", () => {
|
|
8
8
|
vi.mock("../useCart/useCart.ts", () => ({
|
|
9
9
|
useCart() {
|
|
10
10
|
return {
|
|
@@ -29,11 +29,28 @@ describe("useB2bQuoteManagement", () => {
|
|
|
29
29
|
expect(vm.quantity).toBe(1);
|
|
30
30
|
expect(vm.count).toBe(1);
|
|
31
31
|
expect(vm.isInCart).toBe(true);
|
|
32
|
+
expect(vm.getStock).toBe(ProductMocked.stock);
|
|
33
|
+
expect(vm.getAvailableStock).toBe(ProductMocked.availableStock);
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
it("add product to cart - empty cart", async () => {
|
|
35
37
|
const { vm } = await useSetup(() => useAddToCart(ref()));
|
|
36
38
|
expect(vm.count).toBe(0);
|
|
39
|
+
expect(vm.isInCart).toBe(false);
|
|
37
40
|
await expect(vm.addToCart()).rejects.toThrow();
|
|
38
41
|
});
|
|
42
|
+
|
|
43
|
+
it("add product to cart - product not in cart", async () => {
|
|
44
|
+
const productNotInCart = { ...ProductMocked, id: "other-product-id" };
|
|
45
|
+
const { vm } = await useSetup(() => useAddToCart(ref(productNotInCart)));
|
|
46
|
+
expect(vm.count).toBe(0);
|
|
47
|
+
expect(vm.isInCart).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("add product to cart - quantity resets after add", async () => {
|
|
51
|
+
const { vm } = await useSetup(() => useAddToCart(ref(ProductMocked)));
|
|
52
|
+
vm.quantity = 3;
|
|
53
|
+
await vm.addToCart();
|
|
54
|
+
expect(vm.quantity).toBe(1);
|
|
55
|
+
});
|
|
39
56
|
});
|
|
@@ -6,6 +6,7 @@ import { useSetup } from "../_test";
|
|
|
6
6
|
import { useAddress } from "./useAddress";
|
|
7
7
|
|
|
8
8
|
const MOCKED_ADDRESS = {
|
|
9
|
+
id: "address-id",
|
|
9
10
|
countryId: "6777d83705454d078fc9a7419296c7dc",
|
|
10
11
|
countryStateId: "",
|
|
11
12
|
salutationId: "d5e543063dd642b48ef94b02d68e5785",
|
|
@@ -19,13 +20,17 @@ const MOCKED_ADDRESS = {
|
|
|
19
20
|
describe("useAddress", () => {
|
|
20
21
|
it("load customer address", async () => {
|
|
21
22
|
const { vm, injections } = await useSetup(useAddress);
|
|
22
|
-
injections.apiClient.invoke.mockResolvedValue({
|
|
23
|
-
|
|
23
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
24
|
+
data: { elements: [MOCKED_ADDRESS] },
|
|
25
|
+
});
|
|
26
|
+
const result = await vm.loadCustomerAddresses();
|
|
24
27
|
|
|
25
28
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
26
29
|
expect.stringContaining("listAddress"),
|
|
27
30
|
expect.objectContaining({}),
|
|
28
31
|
);
|
|
32
|
+
expect(result).toEqual([MOCKED_ADDRESS]);
|
|
33
|
+
expect(vm.customerAddresses).toEqual([MOCKED_ADDRESS]);
|
|
29
34
|
});
|
|
30
35
|
|
|
31
36
|
it("load customer address - error", async () => {
|
|
@@ -49,6 +54,7 @@ describe("useAddress", () => {
|
|
|
49
54
|
});
|
|
50
55
|
|
|
51
56
|
await expect(vm.loadCustomerAddresses()).rejects.toThrowError();
|
|
57
|
+
expect(vm.customerAddresses).toEqual([]);
|
|
52
58
|
});
|
|
53
59
|
|
|
54
60
|
it("create address", async () => {
|
|
@@ -111,6 +117,39 @@ describe("useAddress", () => {
|
|
|
111
117
|
);
|
|
112
118
|
});
|
|
113
119
|
|
|
120
|
+
it("load customer address - ApiClientError non-403", async () => {
|
|
121
|
+
const { vm } = await useSetup(useAddress, {
|
|
122
|
+
apiClient: {
|
|
123
|
+
invoke: vi.fn().mockImplementation(() => {
|
|
124
|
+
throw new ApiClientError({
|
|
125
|
+
status: 500,
|
|
126
|
+
_data: {
|
|
127
|
+
errors: [{ code: "SERVER", status: 500, detail: "Error" }],
|
|
128
|
+
},
|
|
129
|
+
} as unknown as FetchResponse<{
|
|
130
|
+
errors: Array<{ title: string }>;
|
|
131
|
+
}>);
|
|
132
|
+
}),
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
await expect(vm.loadCustomerAddresses()).rejects.toThrowError();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("load customer address - non-ApiClientError", async () => {
|
|
140
|
+
const { vm } = await useSetup(useAddress, {
|
|
141
|
+
apiClient: {
|
|
142
|
+
invoke: vi.fn().mockImplementation(() => {
|
|
143
|
+
throw new Error("Network error");
|
|
144
|
+
}),
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await expect(vm.loadCustomerAddresses()).rejects.toThrowError(
|
|
149
|
+
"Network error",
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
114
153
|
it("build error message builder", async () => {
|
|
115
154
|
const { vm } = await useSetup(useAddress);
|
|
116
155
|
const message = vm.errorMessageBuilder({
|
|
@@ -190,7 +190,7 @@ export function useAddress(): UseAddressReturn {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
return {
|
|
193
|
-
customerAddresses: computed(() => _storeCustomerAddresses.value
|
|
193
|
+
customerAddresses: computed(() => _storeCustomerAddresses.value),
|
|
194
194
|
loadCustomerAddresses,
|
|
195
195
|
createCustomerAddress,
|
|
196
196
|
updateCustomerAddress,
|
|
@@ -144,6 +144,18 @@ describe("useCart", () => {
|
|
|
144
144
|
);
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
+
it("remove item by id", async () => {
|
|
148
|
+
await vm.removeItemById("01893ed931d571718e8138e7df7d68d1");
|
|
149
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
150
|
+
expect.stringContaining("removeLineItem"),
|
|
151
|
+
expect.objectContaining({
|
|
152
|
+
body: {
|
|
153
|
+
ids: ["01893ed931d571718e8138e7df7d68d1"],
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
147
159
|
it("submitPromotionCode", async () => {
|
|
148
160
|
injections.apiClient.invoke.mockResolvedValue({
|
|
149
161
|
data: {
|
|
@@ -248,4 +260,34 @@ describe("useCart", () => {
|
|
|
248
260
|
|
|
249
261
|
expect(vm.shippingCosts.length).toEqual(0);
|
|
250
262
|
});
|
|
263
|
+
|
|
264
|
+
it("should return true for isVirtualCart when all items are digital", async () => {
|
|
265
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
266
|
+
data: {
|
|
267
|
+
lineItems: [
|
|
268
|
+
{
|
|
269
|
+
type: "product",
|
|
270
|
+
good: true,
|
|
271
|
+
quantity: 1,
|
|
272
|
+
states: ["is-download"],
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
await vm.refreshCart();
|
|
278
|
+
expect(vm.isVirtualCart).toBe(true);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("consumeCartErrors returns null when no errors", async () => {
|
|
282
|
+
await vm.refreshCart();
|
|
283
|
+
expect(vm.consumeCartErrors()).toEqual(null);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it("isEmpty should return true when cart has no items", async () => {
|
|
287
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
288
|
+
data: { lineItems: [] },
|
|
289
|
+
});
|
|
290
|
+
await vm.refreshCart();
|
|
291
|
+
expect(vm.isEmpty).toBe(true);
|
|
292
|
+
});
|
|
251
293
|
});
|
package/src/useCart/useCart.ts
CHANGED
|
@@ -60,6 +60,10 @@ export type UseCartReturn = {
|
|
|
60
60
|
* Removes the provided LineItem from the cart
|
|
61
61
|
*/
|
|
62
62
|
removeItem(lineItem: Schemas["LineItem"]): Promise<Schemas["Cart"]>;
|
|
63
|
+
/**
|
|
64
|
+
* Removes the item with the provided id from the cart
|
|
65
|
+
*/
|
|
66
|
+
removeItemById(id: string): Promise<Schemas["Cart"]>;
|
|
63
67
|
/**
|
|
64
68
|
* The total price of the cart (including calculated costs like shipping)
|
|
65
69
|
*/
|
|
@@ -168,6 +172,18 @@ export function useCartFunction(): UseCartReturn {
|
|
|
168
172
|
return data;
|
|
169
173
|
}
|
|
170
174
|
|
|
175
|
+
async function removeItemById(id: string) {
|
|
176
|
+
const { data } = await apiClient.invoke(
|
|
177
|
+
"removeLineItem post /checkout/cart/line-item/delete",
|
|
178
|
+
{
|
|
179
|
+
body: { ids: [id] },
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
_storeCart.value = data;
|
|
183
|
+
setCartErrors(data);
|
|
184
|
+
return data;
|
|
185
|
+
}
|
|
186
|
+
|
|
171
187
|
async function changeProductQuantity(params: {
|
|
172
188
|
id: string;
|
|
173
189
|
quantity: number;
|
|
@@ -301,6 +317,7 @@ export function useCartFunction(): UseCartReturn {
|
|
|
301
317
|
count,
|
|
302
318
|
refreshCart,
|
|
303
319
|
removeItem,
|
|
320
|
+
removeItemById,
|
|
304
321
|
totalPrice,
|
|
305
322
|
shippingTotal,
|
|
306
323
|
subtotal,
|
|
@@ -116,6 +116,27 @@ describe("useCartNotification", () => {
|
|
|
116
116
|
]);
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
+
it("should exclude success codes from getErrorsCodes", () => {
|
|
120
|
+
vi.mocked(useCart).mockReturnValue({
|
|
121
|
+
consumeCartErrors: vi.fn(() => {
|
|
122
|
+
return JSON.parse(
|
|
123
|
+
JSON.stringify({
|
|
124
|
+
"promotion-discount-added-1326f60448d84aed964d77ca1c2dde90": {
|
|
125
|
+
message: "Discount has been added",
|
|
126
|
+
code: 0,
|
|
127
|
+
key: "promotion-discount-added-1326f60448d84aed964d77ca1c2dde90",
|
|
128
|
+
level: 0,
|
|
129
|
+
messageKey: "promotion-discount-added",
|
|
130
|
+
},
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
}),
|
|
134
|
+
} as unknown as ReturnType<typeof useCart>);
|
|
135
|
+
const { vm } = useSetup(() => useCartNotification());
|
|
136
|
+
|
|
137
|
+
expect(vm.getErrorsCodes()).toEqual([]);
|
|
138
|
+
});
|
|
139
|
+
|
|
119
140
|
it("should return empty array if errors are not present", () => {
|
|
120
141
|
vi.mocked(useCart).mockReturnValue({
|
|
121
142
|
consumeCartErrors: vi.fn(() => {
|
|
@@ -126,4 +147,13 @@ describe("useCartNotification", () => {
|
|
|
126
147
|
const { vm } = useSetup(() => useCartNotification());
|
|
127
148
|
expect(vm.getErrorsCodes()).toEqual([]);
|
|
128
149
|
});
|
|
150
|
+
|
|
151
|
+
it("should return empty array when errors is array", () => {
|
|
152
|
+
vi.mocked(useCart).mockReturnValue({
|
|
153
|
+
consumeCartErrors: vi.fn(() => []),
|
|
154
|
+
} as unknown as ReturnType<typeof useCart>);
|
|
155
|
+
|
|
156
|
+
const { vm } = useSetup(() => useCartNotification());
|
|
157
|
+
expect(vm.getErrorsCodes()).toEqual([]);
|
|
158
|
+
});
|
|
129
159
|
});
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ref } from "vue";
|
|
2
3
|
import { useSetup } from "../_test";
|
|
3
4
|
import { useCheckout } from "./useCheckout";
|
|
4
5
|
|
|
6
|
+
const sessionContextRef = ref();
|
|
7
|
+
vi.mock("../useSessionContext/useSessionContext.ts", () => ({
|
|
8
|
+
useSessionContext: () => ({
|
|
9
|
+
sessionContext: sessionContextRef,
|
|
10
|
+
selectedPaymentMethod: ref(null),
|
|
11
|
+
selectedShippingMethod: ref(null),
|
|
12
|
+
setShippingMethod: vi.fn(),
|
|
13
|
+
setPaymentMethod: vi.fn(),
|
|
14
|
+
}),
|
|
15
|
+
}));
|
|
16
|
+
|
|
5
17
|
describe("useCheckout", () => {
|
|
6
18
|
it("getShippingMethods - empty", async () => {
|
|
7
19
|
const { vm, injections } = useSetup(useCheckout);
|
|
@@ -101,4 +113,34 @@ describe("useCheckout", () => {
|
|
|
101
113
|
expect.objectContaining({}),
|
|
102
114
|
);
|
|
103
115
|
});
|
|
116
|
+
|
|
117
|
+
it("createOrder with params", async () => {
|
|
118
|
+
const { vm, injections } = useSetup(useCheckout);
|
|
119
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
120
|
+
data: { id: "order-123" },
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const result = await vm.createOrder({ customerComment: "test" });
|
|
124
|
+
|
|
125
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
126
|
+
expect.stringContaining("createOrder"),
|
|
127
|
+
expect.objectContaining({
|
|
128
|
+
body: { customerComment: "test" },
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
expect(result).toEqual({ id: "order-123" });
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("shippingAddress and billingAddress from sessionContext", () => {
|
|
135
|
+
const shippingAddr = { street: "Test St", city: "Test City" };
|
|
136
|
+
const billingAddr = { street: "Billing St", city: "Billing City" };
|
|
137
|
+
sessionContextRef.value = {
|
|
138
|
+
shippingLocation: { address: shippingAddr },
|
|
139
|
+
customer: { activeBillingAddress: billingAddr },
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const { vm } = useSetup(useCheckout);
|
|
143
|
+
expect(vm.shippingAddress).toEqual(shippingAddr);
|
|
144
|
+
expect(vm.billingAddress).toEqual(billingAddr);
|
|
145
|
+
});
|
|
104
146
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { Schemas } from "#shopware";
|
|
2
3
|
import { useSetup } from "../_test";
|
|
3
4
|
import LandingPageMock from "../mocks/LandingPage";
|
|
4
5
|
import { useCmsMeta } from "./useCmsMeta";
|
|
@@ -14,4 +15,29 @@ describe("composables - useCmsMeta", () => {
|
|
|
14
15
|
{ name: "title", content: "Landing page title" },
|
|
15
16
|
]);
|
|
16
17
|
});
|
|
18
|
+
|
|
19
|
+
it("should return empty meta when no keywords, description or title", () => {
|
|
20
|
+
const entity = {
|
|
21
|
+
translated: {},
|
|
22
|
+
name: "Entity Name",
|
|
23
|
+
} as Schemas["Category"];
|
|
24
|
+
const { vm } = useSetup(() => useCmsMeta(entity));
|
|
25
|
+
|
|
26
|
+
expect(vm.title).toEqual("Entity Name");
|
|
27
|
+
expect(vm.meta).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should return partial meta when only some fields present", () => {
|
|
31
|
+
const entity = {
|
|
32
|
+
translated: {
|
|
33
|
+
metaDescription: "Only description",
|
|
34
|
+
},
|
|
35
|
+
name: "Entity Name",
|
|
36
|
+
} as Schemas["Category"];
|
|
37
|
+
const { vm } = useSetup(() => useCmsMeta(entity));
|
|
38
|
+
|
|
39
|
+
expect(vm.meta).toEqual([
|
|
40
|
+
{ name: "description", content: "Only description" },
|
|
41
|
+
]);
|
|
42
|
+
});
|
|
17
43
|
});
|