@shopware/composables 0.0.0-canary-20250116155626
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/LICENSE +21 -0
- package/README.md +172 -0
- package/composables/index.ts +1 -0
- package/dist/index.d.mts +2239 -0
- package/dist/index.d.ts +2239 -0
- package/dist/index.mjs +2686 -0
- package/nuxt.config.ts +14 -0
- package/package.json +83 -0
- package/src/_test/index.ts +1 -0
- package/src/_test/useSetup.ts +43 -0
- package/src/cms/README.md +9 -0
- package/src/cms/cmsAssociations.ts +28 -0
- package/src/cms/index.ts +2 -0
- package/src/cms/useCmsElementConfig.test.ts +145 -0
- package/src/cms/useCmsElementConfig.ts +29 -0
- package/src/cms/useCmsElementImage.test.ts +179 -0
- package/src/cms/useCmsElementImage.ts +103 -0
- package/src/cms/useCmsElementProductBox.test.ts +15 -0
- package/src/cms/useCmsElementProductBox.ts +25 -0
- package/src/createShopwareContext.test.ts +23 -0
- package/src/createShopwareContext.ts +43 -0
- package/src/devtools/plugin.ts +201 -0
- package/src/helpers/ContextError.spec.ts +20 -0
- package/src/helpers/ContextError.ts +6 -0
- package/src/index.test.ts +54 -0
- package/src/index.ts +111 -0
- package/src/mocks/Cart.ts +774 -0
- package/src/mocks/CmsPage.ts +544 -0
- package/src/mocks/CmsProductBox.ts +377 -0
- package/src/mocks/Configurator.ts +123 -0
- package/src/mocks/Country.ts +184 -0
- package/src/mocks/CrossSellingResponse.ts +552 -0
- package/src/mocks/LandingPage.ts +62 -0
- package/src/mocks/Menu.ts +598 -0
- package/src/mocks/Order.ts +1151 -0
- package/src/mocks/Product.ts +473 -0
- package/src/mocks/ProductTierPrices.ts +771 -0
- package/src/mocks/Salutations.ts +51 -0
- package/src/mocks/Search.ts +518 -0
- package/src/types/cmsBlockTypes.ts +80 -0
- package/src/types/cmsElementTypes.ts +381 -0
- package/src/types/cmsSectionTypes.ts +15 -0
- package/src/types/index.ts +52 -0
- package/src/useAddToCart/useAddToCart.test.ts +39 -0
- package/src/useAddToCart/useAddToCart.ts +90 -0
- package/src/useAddress/useAddress.test.ts +134 -0
- package/src/useAddress/useAddress.ts +202 -0
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +137 -0
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.ts +225 -0
- package/src/useBreadcrumbs/useBreadcrumbs.test.ts +71 -0
- package/src/useBreadcrumbs/useBreadcrumbs.ts +89 -0
- package/src/useCart/useCart.test.ts +251 -0
- package/src/useCart/useCart.ts +314 -0
- package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +122 -0
- package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.ts +80 -0
- package/src/useCartItem/useCartItem.test.ts +168 -0
- package/src/useCartItem/useCartItem.ts +157 -0
- package/src/useCartNotification/useCartNotification.test.ts +129 -0
- package/src/useCartNotification/useCartNotification.ts +63 -0
- package/src/useCategory/useCategory.test.ts +14 -0
- package/src/useCategory/useCategory.ts +32 -0
- package/src/useCategorySearch/useCategorySearch.test.ts +98 -0
- package/src/useCategorySearch/useCategorySearch.ts +81 -0
- package/src/useCheckout/useCheckout.test.ts +104 -0
- package/src/useCheckout/useCheckout.ts +163 -0
- package/src/useCmsBlock/useCmsBlock.test.ts +25 -0
- package/src/useCmsBlock/useCmsBlock.ts +36 -0
- package/src/useCmsMeta/useCmsMeta.test.ts +17 -0
- package/src/useCmsMeta/useCmsMeta.ts +46 -0
- package/src/useCmsSection/useCmsSection.test.ts +18 -0
- package/src/useCmsSection/useCmsSection.ts +39 -0
- package/src/useCmsTranslations/useCmsTranslations.test.ts +10 -0
- package/src/useCmsTranslations/useCmsTranslations.ts +9 -0
- package/src/useContext/useContext.ts +36 -0
- package/src/useCountries/useCountries.test.ts +64 -0
- package/src/useCountries/useCountries.ts +64 -0
- package/src/useCustomerOrders/useCustomerOrders.test.ts +47 -0
- package/src/useCustomerOrders/useCustomerOrders.ts +89 -0
- package/src/useCustomerPassword/useCustomerPassword.test.ts +164 -0
- package/src/useCustomerPassword/useCustomerPassword.ts +57 -0
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +41 -0
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.ts +45 -0
- package/src/useInternationalization/useInternationalization.test.ts +155 -0
- package/src/useInternationalization/useInternationalization.ts +159 -0
- package/src/useLandingSearch/useLandingSearch.test.ts +30 -0
- package/src/useLandingSearch/useLandingSearch.ts +58 -0
- package/src/useListing/useListing.test.ts +249 -0
- package/src/useListing/useListing.ts +592 -0
- package/src/useLocalWishlist/useLocalWishlist.test.ts +54 -0
- package/src/useLocalWishlist/useLocalWishlist.ts +95 -0
- package/src/useNavigation/useNavigation.test.ts +68 -0
- package/src/useNavigation/useNavigation.ts +83 -0
- package/src/useNavigationContext/useNavigationContext.test.ts +48 -0
- package/src/useNavigationContext/useNavigationContext.ts +39 -0
- package/src/useNavigationSearch/useNavigationSearch.test.ts +110 -0
- package/src/useNavigationSearch/useNavigationSearch.ts +60 -0
- package/src/useNewsletter/useNewsletter.test.ts +55 -0
- package/src/useNewsletter/useNewsletter.ts +109 -0
- package/src/useNotifications/useNotifications.test.ts +56 -0
- package/src/useNotifications/useNotifications.ts +119 -0
- package/src/useOrderDetails/useOrderDetails.test.ts +224 -0
- package/src/useOrderDetails/useOrderDetails.ts +329 -0
- package/src/useOrderPayment/useOrderPayment.test.ts +80 -0
- package/src/useOrderPayment/useOrderPayment.ts +119 -0
- package/src/usePrice/usePrice.test.ts +97 -0
- package/src/usePrice/usePrice.ts +106 -0
- package/src/useProduct/useProduct.test.ts +36 -0
- package/src/useProduct/useProduct.ts +56 -0
- package/src/useProductAssociations/useProductAssociations.spec.ts +105 -0
- package/src/useProductAssociations/useProductAssociations.ts +107 -0
- package/src/useProductConfigurator/useProductConfigurator.spec.ts +77 -0
- package/src/useProductConfigurator/useProductConfigurator.ts +134 -0
- package/src/useProductPrice/useProductPrice.test.ts +126 -0
- package/src/useProductPrice/useProductPrice.ts +131 -0
- package/src/useProductReviews/useProductReviews.test.ts +45 -0
- package/src/useProductReviews/useProductReviews.ts +80 -0
- package/src/useProductSearch/useProductSearch.test.ts +37 -0
- package/src/useProductSearch/useProductSearch.ts +58 -0
- package/src/useProductSearchSuggest/useProductSearchSuggest.test.ts +19 -0
- package/src/useProductSearchSuggest/useProductSearchSuggest.ts +67 -0
- package/src/useProductWishlist/useProductWishlist.test.ts +63 -0
- package/src/useProductWishlist/useProductWishlist.ts +74 -0
- package/src/useSalutations/useSalutations.spec.ts +37 -0
- package/src/useSalutations/useSalutations.ts +55 -0
- package/src/useSessionContext/useSessionContext.test.ts +221 -0
- package/src/useSessionContext/useSessionContext.ts +281 -0
- package/src/useShopwareContext/useShopwareContext.test.ts +8 -0
- package/src/useShopwareContext/useShopwareContext.ts +31 -0
- package/src/useSyncWishlist/useSyncWishlist.test.ts +117 -0
- package/src/useSyncWishlist/useSyncWishlist.ts +117 -0
- package/src/useUrlResolver/useUrlResolver.test.ts +25 -0
- package/src/useUrlResolver/useUrlResolver.ts +31 -0
- package/src/useUser/useUser.test.ts +290 -0
- package/src/useUser/useUser.ts +321 -0
- package/src/useWishlist/useWishlist.test.ts +178 -0
- package/src/useWishlist/useWishlist.ts +128 -0
- package/types/api-types.ts +11 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { useSetup } from "../_test";
|
|
3
|
+
import { useNotifications } from "./useNotifications";
|
|
4
|
+
|
|
5
|
+
describe("useNotifications", () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
vi.useFakeTimers();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
vi.restoreAllMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should trigger sample notification flow", async () => {
|
|
15
|
+
const { vm } = useSetup(useNotifications);
|
|
16
|
+
|
|
17
|
+
vm.pushError("Error message");
|
|
18
|
+
vm.pushSuccess("Success message");
|
|
19
|
+
vm.pushInfo("Info message");
|
|
20
|
+
vm.pushWarning("Warning message", { persistent: true });
|
|
21
|
+
|
|
22
|
+
expect(vm.notifications.length).toBe(4);
|
|
23
|
+
vm.removeOne(vm.notifications[0].id);
|
|
24
|
+
expect(vm.notifications.length).toBe(3);
|
|
25
|
+
vm.removeAll();
|
|
26
|
+
expect(vm.notifications.length).toBe(0);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("notification timeout", async () => {
|
|
30
|
+
const { vm } = useSetup(useNotifications);
|
|
31
|
+
|
|
32
|
+
vm.pushError("Error message", { timeout: 100 });
|
|
33
|
+
vi.runAllTimers();
|
|
34
|
+
expect(vm.notifications.length).toBe(0);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("injected empty swNotifications", () => {
|
|
38
|
+
const { vm } = useSetup(useNotifications, {
|
|
39
|
+
swNotifications: { value: null },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(vm.notifications).toEqual([]);
|
|
43
|
+
vm.removeOne(2332);
|
|
44
|
+
expect(vm.notifications).toEqual([]);
|
|
45
|
+
vm.pushSuccess("test");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("injected empty swNotifications and push success", () => {
|
|
49
|
+
const { vm } = useSetup(useNotifications, {
|
|
50
|
+
swNotifications: { value: null },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
vm.pushSuccess("test");
|
|
54
|
+
expect(vm.notifications.length).toBe(1);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { computed, inject, provide, ref } from "vue";
|
|
2
|
+
import type { ComputedRef, Ref } from "vue";
|
|
3
|
+
|
|
4
|
+
type NotificationType = "info" | "warning" | "success" | "danger";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export type Notification = {
|
|
10
|
+
type: NotificationType;
|
|
11
|
+
message: string;
|
|
12
|
+
id: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export type NotificationOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
type?: NotificationType;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
persistent?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export type UseNotificationsReturn = {
|
|
31
|
+
/**
|
|
32
|
+
* List of active notifications
|
|
33
|
+
*/
|
|
34
|
+
notifications: ComputedRef<Notification[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Removes a specific notification by its ID
|
|
37
|
+
*/
|
|
38
|
+
removeOne(id: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Resets the notification list - clear all notifications
|
|
41
|
+
*/
|
|
42
|
+
removeAll(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Push an info notification to the current list
|
|
45
|
+
*/
|
|
46
|
+
pushInfo(message: string, options?: NotificationOptions): void;
|
|
47
|
+
/**
|
|
48
|
+
* Pushes a warning notification to the current list
|
|
49
|
+
*/
|
|
50
|
+
pushWarning(message: string, options?: NotificationOptions): void;
|
|
51
|
+
/**
|
|
52
|
+
* Pushes an error notification to the current list
|
|
53
|
+
*/
|
|
54
|
+
pushError(message: string, options?: NotificationOptions): void;
|
|
55
|
+
/**
|
|
56
|
+
* Pushes a success notification to the current list
|
|
57
|
+
*/
|
|
58
|
+
pushSuccess(message: string, options?: NotificationOptions): void;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Composable for managing notifications (flash messages) on frontend.
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export function useNotifications(): UseNotificationsReturn {
|
|
66
|
+
const _notifications: Ref<Notification[]> = inject(
|
|
67
|
+
"swNotifications",
|
|
68
|
+
ref([]),
|
|
69
|
+
);
|
|
70
|
+
provide("swNotifications", _notifications);
|
|
71
|
+
|
|
72
|
+
function removeOne(notificationId: number) {
|
|
73
|
+
_notifications.value =
|
|
74
|
+
_notifications.value?.filter(({ id }) => id !== notificationId) || [];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function removeAll() {
|
|
78
|
+
_notifications.value = [];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function geterateId() {
|
|
82
|
+
return +`${new Date().getTime()}${Math.random() * 1000}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function pushNotification(
|
|
86
|
+
message: string,
|
|
87
|
+
options: Required<Pick<NotificationOptions, "type">> & NotificationOptions,
|
|
88
|
+
) {
|
|
89
|
+
const timeout = options.timeout || 2500;
|
|
90
|
+
const persistent = !!options.persistent;
|
|
91
|
+
_notifications.value = _notifications.value || [];
|
|
92
|
+
|
|
93
|
+
const messageId = geterateId();
|
|
94
|
+
_notifications.value.push({
|
|
95
|
+
id: messageId,
|
|
96
|
+
type: options.type,
|
|
97
|
+
message,
|
|
98
|
+
});
|
|
99
|
+
if (!persistent) {
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
removeOne(messageId);
|
|
102
|
+
}, timeout);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
removeOne,
|
|
108
|
+
removeAll,
|
|
109
|
+
pushInfo: (message: string, options = {}) =>
|
|
110
|
+
pushNotification(message, { ...options, type: "info" }),
|
|
111
|
+
pushSuccess: (message: string, options = {}) =>
|
|
112
|
+
pushNotification(message, { ...options, type: "success" }),
|
|
113
|
+
pushWarning: (message: string, options = {}) =>
|
|
114
|
+
pushNotification(message, { ...options, type: "warning" }),
|
|
115
|
+
pushError: (message: string, options = {}) =>
|
|
116
|
+
pushNotification(message, { ...options, type: "danger" }),
|
|
117
|
+
notifications: computed(() => _notifications.value || []),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { useSetup } from "../_test";
|
|
3
|
+
import Order from "../mocks/Order";
|
|
4
|
+
import { useOrderDetails } from "./useOrderDetails";
|
|
5
|
+
|
|
6
|
+
describe("useOrderDetails", () => {
|
|
7
|
+
it("init details", async () => {
|
|
8
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
9
|
+
injections.apiClient.invoke.mockResolvedValue({ data: Order });
|
|
10
|
+
|
|
11
|
+
await vm.loadOrderDetails();
|
|
12
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
13
|
+
expect.stringContaining("readOrder"),
|
|
14
|
+
expect.objectContaining({}),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expect(vm.personalDetails).toEqual({
|
|
18
|
+
email: Order.orders.elements[0].orderCustomer.email,
|
|
19
|
+
firstName: Order.orders.elements[0].orderCustomer.firstName,
|
|
20
|
+
lastName: Order.orders.elements[0].orderCustomer.lastName,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(vm.billingAddress).toEqual(
|
|
24
|
+
Order.orders.elements[0].addresses.find(
|
|
25
|
+
({ id }: { id: string }) =>
|
|
26
|
+
id === Order.orders.elements[0].billingAddressId,
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should handle setting the order payment", async () => {
|
|
32
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
33
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
34
|
+
await vm.handlePayment();
|
|
35
|
+
|
|
36
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
37
|
+
expect.stringContaining("handlePaymentMethod"),
|
|
38
|
+
expect.objectContaining({
|
|
39
|
+
body: {
|
|
40
|
+
errorUrl: undefined,
|
|
41
|
+
finishUrl: undefined,
|
|
42
|
+
orderId: "123-test",
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should cancel the order", async () => {
|
|
49
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
50
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
51
|
+
await vm.cancel();
|
|
52
|
+
|
|
53
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
54
|
+
expect.stringContaining("cancelOrder"),
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
body: {
|
|
57
|
+
orderId: "123-test",
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("changePaymentMethod", async () => {
|
|
64
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
65
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
66
|
+
await vm.changePaymentMethod("test");
|
|
67
|
+
|
|
68
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
69
|
+
expect.stringContaining("orderSetPayment"),
|
|
70
|
+
expect.objectContaining({
|
|
71
|
+
body: {
|
|
72
|
+
orderId: "123-test",
|
|
73
|
+
paymentMethodId: "test",
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("getMediaFile", async () => {
|
|
80
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
81
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
82
|
+
await vm.getMediaFile("file-123");
|
|
83
|
+
|
|
84
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
85
|
+
expect.stringContaining("orderDownloadFile"),
|
|
86
|
+
expect.objectContaining({
|
|
87
|
+
accept: "application/octet-stream",
|
|
88
|
+
pathParams: {
|
|
89
|
+
orderId: "123-test",
|
|
90
|
+
downloadId: "file-123",
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("getDocumentFile", async () => {
|
|
97
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
98
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
99
|
+
await vm.getDocumentFile("file-123", "code-123");
|
|
100
|
+
|
|
101
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
102
|
+
expect.stringContaining("download"),
|
|
103
|
+
expect.objectContaining({
|
|
104
|
+
pathParams: {
|
|
105
|
+
documentId: "file-123",
|
|
106
|
+
deepLinkCode: "code-123",
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("getPaymentMethods", async () => {
|
|
113
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
114
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
115
|
+
await vm.getPaymentMethods();
|
|
116
|
+
|
|
117
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
118
|
+
expect.stringContaining("readPaymentMethod"),
|
|
119
|
+
expect.objectContaining({
|
|
120
|
+
body: {
|
|
121
|
+
onlyAvailable: true,
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("paymentChangeable", async () => {
|
|
128
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test", {}));
|
|
129
|
+
injections.apiClient.invoke.mockResolvedValue({ data: Order });
|
|
130
|
+
expect(vm.paymentChangeable).toEqual(false);
|
|
131
|
+
await vm.loadOrderDetails();
|
|
132
|
+
expect(vm.paymentChangeable).toEqual(true);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should return current payment method", async () => {
|
|
136
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
137
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
138
|
+
data: {
|
|
139
|
+
orders: {
|
|
140
|
+
elements: [
|
|
141
|
+
{
|
|
142
|
+
transactions: [
|
|
143
|
+
{
|
|
144
|
+
paymentMethod: {
|
|
145
|
+
shortName: "invoice_payment",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
paymentMethod: {
|
|
150
|
+
shortName: "cash_payment",
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
await vm.loadOrderDetails();
|
|
160
|
+
expect(vm.paymentMethod?.shortName).toEqual("cash_payment");
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("should return current delivery method", async () => {
|
|
164
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
165
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
166
|
+
data: {
|
|
167
|
+
orders: {
|
|
168
|
+
elements: [
|
|
169
|
+
{
|
|
170
|
+
deliveries: [
|
|
171
|
+
{
|
|
172
|
+
shippingMethod: {
|
|
173
|
+
name: "test",
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
shippingMethod: {
|
|
178
|
+
name: "Standard",
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
await vm.loadOrderDetails();
|
|
188
|
+
expect(vm.shippingMethod?.name).toEqual("Standard");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should return undefined if payment method does not exists", async () => {
|
|
192
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
193
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
194
|
+
data: {
|
|
195
|
+
orders: {
|
|
196
|
+
elements: [
|
|
197
|
+
{
|
|
198
|
+
transactions: [],
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
await vm.loadOrderDetails();
|
|
205
|
+
expect(vm.paymentMethod?.shortName).toEqual(undefined);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("should return undefined if shipping method does not exists", async () => {
|
|
209
|
+
const { vm, injections } = useSetup(() => useOrderDetails("123-test"));
|
|
210
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
211
|
+
data: {
|
|
212
|
+
orders: {
|
|
213
|
+
elements: [
|
|
214
|
+
{
|
|
215
|
+
deliveries: [],
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
await vm.loadOrderDetails();
|
|
222
|
+
expect(vm.shippingMethod?.name).toEqual(undefined);
|
|
223
|
+
});
|
|
224
|
+
});
|