@lookiero/checkout 0.1.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.
- package/.eslintignore +7 -0
- package/.eslintrc +72 -0
- package/.expo-shared/assets.json +4 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/actions/version/action.yaml +32 -0
- package/.github/dependabot.yaml +10 -0
- package/.github/workflows/build.yaml +71 -0
- package/.github/workflows/publish.yaml +52 -0
- package/.husky/pre-commit +4 -0
- package/.husky/prepare-commit-msg +26 -0
- package/.husky/prepush +12 -0
- package/.lintstagedrc.json +4 -0
- package/.nvmrc +1 -0
- package/.prettierignore +2 -0
- package/.prettierrc.json +6 -0
- package/@types/aurora-next.d.ts +1 -0
- package/README.md +19 -0
- package/app.config.js +4 -0
- package/app.json +31 -0
- package/assets/adaptive-icon.png +0 -0
- package/assets/favicon.png +0 -0
- package/assets/icon.png +0 -0
- package/assets/splash.png +0 -0
- package/babel.config.js +6 -0
- package/dist/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.d.ts +15 -0
- package/dist/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.js +6 -0
- package/dist/domain/checkoutBooking/model/checkoutBooking.d.ts +8 -0
- package/dist/domain/checkoutBooking/model/checkoutBooking.js +16 -0
- package/dist/domain/checkoutBooking/model/checkoutBookingBooked.d.ts +15 -0
- package/dist/domain/checkoutBooking/model/checkoutBookingBooked.js +6 -0
- package/dist/domain/checkoutBooking/model/checkoutBookings.d.ts +6 -0
- package/dist/domain/checkoutBooking/model/checkoutBookings.js +1 -0
- package/dist/domain/uiSetting/command/updateUiSetting.d.ts +14 -0
- package/dist/domain/uiSetting/command/updateUiSetting.js +9 -0
- package/dist/domain/uiSetting/model/uiSetting.d.ts +8 -0
- package/dist/domain/uiSetting/model/uiSetting.js +10 -0
- package/dist/domain/uiSetting/model/uiSettingUpdated.d.ts +13 -0
- package/dist/domain/uiSetting/model/uiSettingUpdated.js +6 -0
- package/dist/domain/uiSetting/model/uiSettings.d.ts +6 -0
- package/dist/domain/uiSetting/model/uiSettings.js +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +13 -0
- package/dist/infrastructure/delivery/_mock/bootstrap.mock.d.ts +6 -0
- package/dist/infrastructure/delivery/_mock/bootstrap.mock.js +17 -0
- package/dist/infrastructure/delivery/_mock/checkout.mock.d.ts +9 -0
- package/dist/infrastructure/delivery/_mock/checkout.mock.js +45 -0
- package/dist/infrastructure/delivery/bootstrap.d.ts +10 -0
- package/dist/infrastructure/delivery/bootstrap.js +21 -0
- package/dist/infrastructure/delivery/http/fetchHttpClient.d.ts +14 -0
- package/dist/infrastructure/delivery/http/fetchHttpClient.js +18 -0
- package/dist/infrastructure/delivery/http/httpClient.d.ts +14 -0
- package/dist/infrastructure/delivery/http/httpClient.js +1 -0
- package/dist/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.d.ts +10 -0
- package/dist/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.js +19 -0
- package/dist/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.d.ts +15 -0
- package/dist/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.js +17 -0
- package/dist/infrastructure/domain/react/useUpdateUiSetting.d.ts +17 -0
- package/dist/infrastructure/domain/react/useUpdateUiSetting.js +16 -0
- package/dist/infrastructure/domain/uiSetting/model/storageUiSettings.d.ts +18 -0
- package/dist/infrastructure/domain/uiSetting/model/storageUiSettings.js +19 -0
- package/dist/infrastructure/persistence/asyncStorageStorage.d.ts +4 -0
- package/dist/infrastructure/persistence/asyncStorageStorage.js +6 -0
- package/dist/infrastructure/persistence/storage.d.ts +6 -0
- package/dist/infrastructure/persistence/storage.js +1 -0
- package/dist/infrastructure/persistence/uiSettingData.d.ts +5 -0
- package/dist/infrastructure/persistence/uiSettingData.js +1 -0
- package/dist/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.d.ts +36 -0
- package/dist/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.js +30 -0
- package/dist/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.d.ts +60 -0
- package/dist/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.js +54 -0
- package/dist/infrastructure/projection/httpIsCheckoutEnabledByCustomerIdView.d.ts +12 -0
- package/dist/infrastructure/projection/httpIsCheckoutEnabledByCustomerIdView.js +7 -0
- package/dist/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.d.ts +10 -0
- package/dist/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.js +8 -0
- package/dist/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.d.ts +10 -0
- package/dist/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.js +8 -0
- package/dist/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.d.ts +10 -0
- package/dist/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.js +8 -0
- package/dist/infrastructure/projection/react/useViewIsCheckoutIntroVisible.d.ts +3 -0
- package/dist/infrastructure/projection/react/useViewIsCheckoutIntroVisible.js +3 -0
- package/dist/infrastructure/projection/react/useViewUiSettingByKey.d.ts +10 -0
- package/dist/infrastructure/projection/react/useViewUiSettingByKey.js +8 -0
- package/dist/infrastructure/projection/storageUiSettingByKeyView.d.ts +13 -0
- package/dist/infrastructure/projection/storageUiSettingByKeyView.js +14 -0
- package/dist/infrastructure/ui/Root.d.ts +15 -0
- package/dist/infrastructure/ui/Root.js +25 -0
- package/dist/infrastructure/ui/components/atoms/spiner/Spinner.d.ts +3 -0
- package/dist/infrastructure/ui/components/atoms/spiner/Spinner.js +11 -0
- package/dist/infrastructure/ui/components/atoms/spiner/Spinner.style.d.ts +9 -0
- package/dist/infrastructure/ui/components/atoms/spiner/Spinner.style.js +10 -0
- package/dist/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.d.ts +8 -0
- package/dist/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.js +16 -0
- package/dist/infrastructure/ui/routing/CheckoutMiddleware.d.ts +7 -0
- package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +34 -0
- package/dist/infrastructure/ui/routing/Routing.d.ts +7 -0
- package/dist/infrastructure/ui/routing/Routing.js +49 -0
- package/dist/infrastructure/ui/routing/router/Router.d.ts +1 -0
- package/dist/infrastructure/ui/routing/router/Router.js +1 -0
- package/dist/infrastructure/ui/routing/router/Router.native.d.ts +1 -0
- package/dist/infrastructure/ui/routing/router/Router.native.js +1 -0
- package/dist/infrastructure/ui/routing/routes.d.ts +6 -0
- package/dist/infrastructure/ui/routing/routes.js +7 -0
- package/dist/infrastructure/ui/test/render.d.ts +19 -0
- package/dist/infrastructure/ui/test/render.js +14 -0
- package/dist/infrastructure/ui/views/intro/Intro.d.ts +3 -0
- package/dist/infrastructure/ui/views/intro/Intro.js +20 -0
- package/dist/infrastructure/ui/views/item/Item.d.ts +3 -0
- package/dist/infrastructure/ui/views/item/Item.js +23 -0
- package/dist/infrastructure/ui/views/summary/Summary.d.ts +3 -0
- package/dist/infrastructure/ui/views/summary/Summary.js +20 -0
- package/dist/projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem.d.ts +43 -0
- package/dist/projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem.js +8 -0
- package/dist/projection/checkout/viewFirstAvailableCheckoutByCustomerId.d.ts +104 -0
- package/dist/projection/checkout/viewFirstAvailableCheckoutByCustomerId.js +43 -0
- package/dist/projection/checkout/viewIsCheckoutAccessibleByCustomerId.d.ts +16 -0
- package/dist/projection/checkout/viewIsCheckoutAccessibleByCustomerId.js +13 -0
- package/dist/projection/checkout/viewIsCheckoutEnabledByCustomerId.d.ts +23 -0
- package/dist/projection/checkout/viewIsCheckoutEnabledByCustomerId.js +8 -0
- package/dist/projection/uiSetting/viewUiSettingByKey.d.ts +28 -0
- package/dist/projection/uiSetting/viewUiSettingByKey.js +7 -0
- package/jest.config.js +9 -0
- package/jest.setup.js +3 -0
- package/package.json +75 -0
- package/src/Expo.tsx +59 -0
- package/src/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.test.ts +26 -0
- package/src/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.ts +27 -0
- package/src/domain/checkoutBooking/model/checkoutBooking.test.ts +30 -0
- package/src/domain/checkoutBooking/model/checkoutBooking.ts +31 -0
- package/src/domain/checkoutBooking/model/checkoutBookingBooked.test.ts +23 -0
- package/src/domain/checkoutBooking/model/checkoutBookingBooked.ts +23 -0
- package/src/domain/checkoutBooking/model/checkoutBookings.ts +6 -0
- package/src/domain/uiSetting/command/updateUiSetting.test.ts +19 -0
- package/src/domain/uiSetting/command/updateUiSetting.ts +23 -0
- package/src/domain/uiSetting/model/uiSetting.test.ts +26 -0
- package/src/domain/uiSetting/model/uiSetting.ts +22 -0
- package/src/domain/uiSetting/model/uiSettingUpdated.test.ts +17 -0
- package/src/domain/uiSetting/model/uiSettingUpdated.ts +19 -0
- package/src/domain/uiSetting/model/uiSettings.ts +6 -0
- package/src/index.ts +44 -0
- package/src/infrastructure/delivery/_mock/bootstrap.mock.ts +38 -0
- package/src/infrastructure/delivery/_mock/checkout.mock.ts +81 -0
- package/src/infrastructure/delivery/bootstrap.ts +42 -0
- package/src/infrastructure/delivery/http/fetchHttpClient.test.ts +51 -0
- package/src/infrastructure/delivery/http/fetchHttpClient.ts +41 -0
- package/src/infrastructure/delivery/http/httpClient.ts +18 -0
- package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.test.ts +45 -0
- package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.ts +32 -0
- package/src/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.test.ts +38 -0
- package/src/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.ts +44 -0
- package/src/infrastructure/domain/react/useUpdateUiSetting.test.ts +31 -0
- package/src/infrastructure/domain/react/useUpdateUiSetting.ts +43 -0
- package/src/infrastructure/domain/uiSetting/model/storageUiSettings.test.ts +50 -0
- package/src/infrastructure/domain/uiSetting/model/storageUiSettings.ts +50 -0
- package/src/infrastructure/persistence/asyncStorageStorage.ts +12 -0
- package/src/infrastructure/persistence/storage.ts +7 -0
- package/src/infrastructure/persistence/uiSettingData.ts +5 -0
- package/src/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.test.ts +65 -0
- package/src/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.ts +102 -0
- package/src/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.test.ts +99 -0
- package/src/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.ts +128 -0
- package/src/infrastructure/projection/httpIsCheckoutEnabledByCustomerIdView.test.ts +32 -0
- package/src/infrastructure/projection/httpIsCheckoutEnabledByCustomerIdView.ts +27 -0
- package/src/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.test.ts +51 -0
- package/src/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.ts +25 -0
- package/src/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.test.ts +28 -0
- package/src/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.ts +22 -0
- package/src/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.test.ts +44 -0
- package/src/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.ts +24 -0
- package/src/infrastructure/projection/react/useViewIsCheckoutIntroVisible.ts +5 -0
- package/src/infrastructure/projection/react/useViewUiSettingByKey.test.ts +30 -0
- package/src/infrastructure/projection/react/useViewUiSettingByKey.ts +18 -0
- package/src/infrastructure/projection/storageUiSettingByKeyView.test.ts +32 -0
- package/src/infrastructure/projection/storageUiSettingByKeyView.ts +35 -0
- package/src/infrastructure/ui/Root.tsx +53 -0
- package/src/infrastructure/ui/components/atoms/spiner/Spinner.style.ts +12 -0
- package/src/infrastructure/ui/components/atoms/spiner/Spinner.tsx +35 -0
- package/src/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.test.tsx +70 -0
- package/src/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.tsx +31 -0
- package/src/infrastructure/ui/routing/CheckoutMiddleware.test.tsx +100 -0
- package/src/infrastructure/ui/routing/CheckoutMiddleware.tsx +52 -0
- package/src/infrastructure/ui/routing/Routing.tsx +64 -0
- package/src/infrastructure/ui/routing/router/Router.native.ts +1 -0
- package/src/infrastructure/ui/routing/router/Router.ts +1 -0
- package/src/infrastructure/ui/routing/routes.ts +6 -0
- package/src/infrastructure/ui/test/render.tsx +47 -0
- package/src/infrastructure/ui/views/intro/Intro.test.tsx +15 -0
- package/src/infrastructure/ui/views/intro/Intro.tsx +27 -0
- package/src/infrastructure/ui/views/item/Item.tsx +31 -0
- package/src/infrastructure/ui/views/summary/Summary.tsx +27 -0
- package/src/projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem.test.ts +40 -0
- package/src/projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem.ts +85 -0
- package/src/projection/checkout/viewFirstAvailableCheckoutByCustomerId.test.ts +22 -0
- package/src/projection/checkout/viewFirstAvailableCheckoutByCustomerId.ts +149 -0
- package/src/projection/checkout/viewIsCheckoutAccessibleByCustomerId.test.ts +54 -0
- package/src/projection/checkout/viewIsCheckoutAccessibleByCustomerId.ts +46 -0
- package/src/projection/checkout/viewIsCheckoutEnabledByCustomerId.test.ts +20 -0
- package/src/projection/checkout/viewIsCheckoutEnabledByCustomerId.ts +51 -0
- package/src/projection/uiSetting/viewUiSettingByKey.test.ts +22 -0
- package/src/projection/uiSetting/viewUiSettingByKey.ts +47 -0
- package/tsconfig.build.json +16 -0
- package/tsconfig.json +19 -0
- package/webpack.config.js +17 -0
package/src/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BookedSizeReplaceableProductVariantsProjection,
|
|
3
|
+
BookedSizeReplaceableProductVariantsForCheckoutItemView,
|
|
4
|
+
ProductVariant,
|
|
5
|
+
Size,
|
|
6
|
+
} from "../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
|
|
7
|
+
import { HttpPostFunction } from "../delivery/http/httpClient";
|
|
8
|
+
|
|
9
|
+
interface SizeFormatDto {
|
|
10
|
+
readonly size: string;
|
|
11
|
+
readonly format: string;
|
|
12
|
+
readonly length?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface SizeDto {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly europe: SizeFormatDto;
|
|
18
|
+
readonly it: SizeFormatDto;
|
|
19
|
+
readonly lookiero: SizeFormatDto;
|
|
20
|
+
readonly uk: SizeFormatDto;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ToSizeFunction {
|
|
24
|
+
(size: SizeDto): Size;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const toSize: ToSizeFunction = (size) => ({
|
|
28
|
+
id: size.id,
|
|
29
|
+
europe: size.europe,
|
|
30
|
+
it: size.it,
|
|
31
|
+
lookiero: size.lookiero,
|
|
32
|
+
uk: size.uk,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
interface ProductVariantDto {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly size: SizeDto;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface ToProductVariantFunction {
|
|
41
|
+
(productVariant: ProductVariantDto): ProductVariant;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const toProductVariant: ToProductVariantFunction = (productVariant) => ({
|
|
45
|
+
id: productVariant.id,
|
|
46
|
+
size: toSize(productVariant.size),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
interface BookedSizeReplaceableProductVariantsDto {
|
|
50
|
+
readonly booking: string | null;
|
|
51
|
+
readonly product_variants: ProductVariantDto[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface ToBookedSizeReplaceableProductVariantsFunction {
|
|
55
|
+
(
|
|
56
|
+
bookedSizeReplaceableProductVariants: BookedSizeReplaceableProductVariantsDto,
|
|
57
|
+
): BookedSizeReplaceableProductVariantsProjection;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const toBookedSizeReplaceableProductVariants: ToBookedSizeReplaceableProductVariantsFunction = (
|
|
61
|
+
bookedSizeReplaceableProductVariants,
|
|
62
|
+
) => ({
|
|
63
|
+
booking: bookedSizeReplaceableProductVariants.booking,
|
|
64
|
+
productVariants: bookedSizeReplaceableProductVariants.product_variants.map(toProductVariant),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
interface HttpBookedSizeReplaceableProductVariantsForCheckoutItemView
|
|
68
|
+
extends BookedSizeReplaceableProductVariantsForCheckoutItemView {}
|
|
69
|
+
|
|
70
|
+
interface HttpBookedSizeReplaceableProductVariantsForCheckoutItemViewFunctionArgs {
|
|
71
|
+
readonly httpPost: HttpPostFunction;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface HttpBookedSizeReplaceableProductVariantsForCheckoutItemViewFunction {
|
|
75
|
+
(
|
|
76
|
+
args: HttpBookedSizeReplaceableProductVariantsForCheckoutItemViewFunctionArgs,
|
|
77
|
+
): HttpBookedSizeReplaceableProductVariantsForCheckoutItemView;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const httpBookedSizeReplaceableProductVariantsForCheckoutItemView: HttpBookedSizeReplaceableProductVariantsForCheckoutItemViewFunction =
|
|
81
|
+
|
|
82
|
+
({ httpPost }) =>
|
|
83
|
+
async ({ checkoutItemId }): Promise<BookedSizeReplaceableProductVariantsProjection | undefined> => {
|
|
84
|
+
try {
|
|
85
|
+
const response = await httpPost({
|
|
86
|
+
endpoint: "/view-booked-size-replaceable-product-variants-for-checkout-item",
|
|
87
|
+
body: { checkout_item_id: checkoutItemId },
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return response.status === 404
|
|
91
|
+
? undefined
|
|
92
|
+
: toBookedSizeReplaceableProductVariants((await response.json()).result);
|
|
93
|
+
} catch (ignored) {
|
|
94
|
+
throw new Error("Could not fetch BookedSizeReplaceableProductVariantsForCheckoutItem");
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export {
|
|
99
|
+
BookedSizeReplaceableProductVariantsDto,
|
|
100
|
+
toBookedSizeReplaceableProductVariants,
|
|
101
|
+
httpBookedSizeReplaceableProductVariantsForCheckoutItemView,
|
|
102
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { v4 as uuid } from "uuid";
|
|
2
|
+
import {
|
|
3
|
+
CheckoutItemStatus,
|
|
4
|
+
CheckoutStatus,
|
|
5
|
+
Currency,
|
|
6
|
+
MediaPerspective,
|
|
7
|
+
} from "../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
8
|
+
import {
|
|
9
|
+
CheckoutDto,
|
|
10
|
+
httpFirstAvailableCheckoutByCustomerIdView as sut,
|
|
11
|
+
toCheckoutProjection,
|
|
12
|
+
} from "./httpFirstAvailableCheckoutByCustomerIdView";
|
|
13
|
+
|
|
14
|
+
const customerId = "29790d24-b139-4ab8-b618-d796d101e974";
|
|
15
|
+
const checkoutResponse: { result: CheckoutDto } = {
|
|
16
|
+
result: {
|
|
17
|
+
id: uuid(),
|
|
18
|
+
status: CheckoutStatus.STARTED,
|
|
19
|
+
customer_id: uuid(),
|
|
20
|
+
box_id: uuid(),
|
|
21
|
+
booking_id: uuid(),
|
|
22
|
+
expires_on: "2022-09-20",
|
|
23
|
+
items: [
|
|
24
|
+
{
|
|
25
|
+
id: uuid(),
|
|
26
|
+
status: CheckoutItemStatus.KEPT,
|
|
27
|
+
product_variant: {
|
|
28
|
+
id: uuid(),
|
|
29
|
+
media: [
|
|
30
|
+
{
|
|
31
|
+
id: uuid(),
|
|
32
|
+
url: "https://cdn-catalog-back-prod.envs.lookiero.tech/d2/65/d2655b80-7745-4537-bb17-eb38f960a8de.jpg",
|
|
33
|
+
perspective: MediaPerspective.FRONT,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
brand: "CKS",
|
|
37
|
+
name: "Sari Tshirt lines",
|
|
38
|
+
price: {
|
|
39
|
+
amount: 3999,
|
|
40
|
+
currency: Currency.EUR,
|
|
41
|
+
},
|
|
42
|
+
size: {
|
|
43
|
+
id: uuid(),
|
|
44
|
+
lookiero: "M",
|
|
45
|
+
uk: "M",
|
|
46
|
+
it: "M",
|
|
47
|
+
europe: "M",
|
|
48
|
+
unique: false,
|
|
49
|
+
},
|
|
50
|
+
color: {
|
|
51
|
+
id: uuid(),
|
|
52
|
+
label: "black_C2",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const checkoutResponseOk: Response = {
|
|
60
|
+
ok: true,
|
|
61
|
+
status: 200,
|
|
62
|
+
json: () => Promise.resolve(checkoutResponse),
|
|
63
|
+
} as Response;
|
|
64
|
+
const checkoutResponseNotFound: Response = {
|
|
65
|
+
ok: false,
|
|
66
|
+
status: 404,
|
|
67
|
+
} as Response;
|
|
68
|
+
const checkoutResponseError: Response = {
|
|
69
|
+
ok: false,
|
|
70
|
+
} as Response;
|
|
71
|
+
|
|
72
|
+
const httpPostMock = jest.fn();
|
|
73
|
+
const view = sut({ httpPost: httpPostMock });
|
|
74
|
+
|
|
75
|
+
describe("httpFirstAvailableCheckoutByCustomerIdView", () => {
|
|
76
|
+
it("returns a Checkout projection for a 200 response", async () => {
|
|
77
|
+
httpPostMock.mockReturnValue(Promise.resolve(checkoutResponseOk));
|
|
78
|
+
|
|
79
|
+
const returnedCheckout = await view({ customerId });
|
|
80
|
+
|
|
81
|
+
expect(returnedCheckout).toStrictEqual(toCheckoutProjection(checkoutResponse.result));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("returns undefined for a 404 response", async () => {
|
|
85
|
+
httpPostMock.mockReturnValue(Promise.resolve(checkoutResponseNotFound));
|
|
86
|
+
|
|
87
|
+
const returnedCheckout = await view({ customerId });
|
|
88
|
+
|
|
89
|
+
expect(returnedCheckout).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("returns undefined for a non successfull response", async () => {
|
|
93
|
+
httpPostMock.mockReturnValue(Promise.resolve(checkoutResponseError));
|
|
94
|
+
|
|
95
|
+
const returnedCheckout = await view({ customerId });
|
|
96
|
+
|
|
97
|
+
expect(returnedCheckout).toBeUndefined();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CheckoutItemStatus,
|
|
3
|
+
CheckoutProjection,
|
|
4
|
+
CheckoutStatus,
|
|
5
|
+
Currency,
|
|
6
|
+
FirstAvailableCheckoutByCustomerIdView,
|
|
7
|
+
MediaPerspective,
|
|
8
|
+
} from "../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
9
|
+
import { HttpPostFunction } from "../delivery/http/httpClient";
|
|
10
|
+
|
|
11
|
+
interface CheckoutDto {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly customer_id: string;
|
|
14
|
+
readonly box_id: string;
|
|
15
|
+
readonly booking_id: string;
|
|
16
|
+
readonly status: CheckoutStatus;
|
|
17
|
+
readonly expires_on: string;
|
|
18
|
+
readonly items: {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly status: CheckoutItemStatus;
|
|
21
|
+
readonly product_variant: {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly media: {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly url: string;
|
|
26
|
+
readonly perspective: MediaPerspective;
|
|
27
|
+
}[];
|
|
28
|
+
readonly brand: string;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly price: {
|
|
31
|
+
readonly amount: number;
|
|
32
|
+
readonly currency: Currency;
|
|
33
|
+
readonly discounted_price?: {
|
|
34
|
+
readonly amount: number;
|
|
35
|
+
readonly percentage: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly size: {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly lookiero: string;
|
|
41
|
+
readonly uk: string;
|
|
42
|
+
readonly it: string;
|
|
43
|
+
readonly europe: string;
|
|
44
|
+
readonly unique: boolean;
|
|
45
|
+
readonly visual_order?: number;
|
|
46
|
+
};
|
|
47
|
+
readonly color: {
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly label: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
readonly replaced_for?: string;
|
|
53
|
+
}[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ToCheckoutProjectionFunction {
|
|
57
|
+
(checkoutDto: CheckoutDto): CheckoutProjection;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const toCheckoutProjection: ToCheckoutProjectionFunction = (checkoutDto) => ({
|
|
61
|
+
id: checkoutDto.id,
|
|
62
|
+
customerId: checkoutDto.customer_id,
|
|
63
|
+
boxId: checkoutDto.box_id,
|
|
64
|
+
bookingId: checkoutDto.booking_id,
|
|
65
|
+
status: checkoutDto.status,
|
|
66
|
+
expiresOn: new Date(checkoutDto.expires_on),
|
|
67
|
+
items: checkoutDto.items.map((item) => ({
|
|
68
|
+
id: item.id,
|
|
69
|
+
status: item.status,
|
|
70
|
+
replacedFor: item.replaced_for,
|
|
71
|
+
productVariant: {
|
|
72
|
+
id: item.product_variant.id,
|
|
73
|
+
media: item.product_variant.media.map((media) => ({
|
|
74
|
+
id: media.id,
|
|
75
|
+
url: media.url,
|
|
76
|
+
perspective: media.perspective,
|
|
77
|
+
})),
|
|
78
|
+
brand: item.product_variant.brand,
|
|
79
|
+
name: item.product_variant.name,
|
|
80
|
+
price: {
|
|
81
|
+
amount: item.product_variant.price.amount,
|
|
82
|
+
currency: item.product_variant.price.currency,
|
|
83
|
+
discountedPrice: item.product_variant.price.discounted_price
|
|
84
|
+
? {
|
|
85
|
+
amount: item.product_variant.price.discounted_price.amount,
|
|
86
|
+
percentage: item.product_variant.price.discounted_price.percentage,
|
|
87
|
+
}
|
|
88
|
+
: undefined,
|
|
89
|
+
},
|
|
90
|
+
size: {
|
|
91
|
+
id: item.product_variant.size.id,
|
|
92
|
+
lookiero: item.product_variant.size.lookiero,
|
|
93
|
+
uk: item.product_variant.size.uk,
|
|
94
|
+
it: item.product_variant.size.it,
|
|
95
|
+
europe: item.product_variant.size.europe,
|
|
96
|
+
unique: item.product_variant.size.unique,
|
|
97
|
+
visualOrder: item.product_variant.size.visual_order,
|
|
98
|
+
},
|
|
99
|
+
color: {
|
|
100
|
+
id: item.product_variant.color.id,
|
|
101
|
+
label: item.product_variant.color.label,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
})),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
interface HttpFirstAvailableCheckoutByCustomerIdView extends FirstAvailableCheckoutByCustomerIdView {}
|
|
108
|
+
|
|
109
|
+
interface HttpFirstAvailableCheckoutByCustomerIdViewFunctionArgs {
|
|
110
|
+
readonly httpPost: HttpPostFunction;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface HttpFirstAvailableCheckoutByCustomerIdViewFunction {
|
|
114
|
+
(args: HttpFirstAvailableCheckoutByCustomerIdViewFunctionArgs): HttpFirstAvailableCheckoutByCustomerIdView;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const httpFirstAvailableCheckoutByCustomerIdView: HttpFirstAvailableCheckoutByCustomerIdViewFunction =
|
|
118
|
+
({ httpPost }) =>
|
|
119
|
+
async ({ customerId }): Promise<CheckoutProjection | undefined> => {
|
|
120
|
+
const response = await httpPost({
|
|
121
|
+
endpoint: "/view-first-available-checkout-by-customer-id",
|
|
122
|
+
body: { customer_id: customerId },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return !response.ok || response.status === 404 ? undefined : toCheckoutProjection((await response.json()).result);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export { CheckoutDto, toCheckoutProjection, httpFirstAvailableCheckoutByCustomerIdView };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { httpIsCheckoutEnabledByCustomerIdView as sut } from "./httpIsCheckoutEnabledByCustomerIdView";
|
|
2
|
+
|
|
3
|
+
const customerId = "29790d24-b139-4ab8-b618-d796d101e974";
|
|
4
|
+
const checkoutResponseOk: Response = {
|
|
5
|
+
ok: true,
|
|
6
|
+
status: 200,
|
|
7
|
+
json: () => Promise.resolve(true),
|
|
8
|
+
} as Response;
|
|
9
|
+
const checkoutResponseError: Response = {
|
|
10
|
+
ok: false,
|
|
11
|
+
} as Response;
|
|
12
|
+
|
|
13
|
+
const httpGetMock = jest.fn();
|
|
14
|
+
const view = sut({ httpGet: httpGetMock });
|
|
15
|
+
|
|
16
|
+
describe("httpIsCheckoutEnabledByCustomerIdView", () => {
|
|
17
|
+
it("returns true/false if enabled/not for a 200 response", async () => {
|
|
18
|
+
httpGetMock.mockReturnValue(Promise.resolve(checkoutResponseOk));
|
|
19
|
+
|
|
20
|
+
const enabled = await view({ customerId });
|
|
21
|
+
|
|
22
|
+
expect(enabled).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("returns false for a non successfull response", async () => {
|
|
26
|
+
httpGetMock.mockReturnValue(Promise.resolve(checkoutResponseError));
|
|
27
|
+
|
|
28
|
+
const enabled = await view({ customerId });
|
|
29
|
+
|
|
30
|
+
expect(enabled).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IsCheckoutEnabledByCustomerIdProjection,
|
|
3
|
+
IsCheckoutEnabledByCustomerIdView,
|
|
4
|
+
} from "../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
|
|
5
|
+
import { HttpGetFunction } from "../delivery/http/httpClient";
|
|
6
|
+
|
|
7
|
+
interface HttpIsCheckoutEnabledByCustomerIdView extends IsCheckoutEnabledByCustomerIdView {}
|
|
8
|
+
|
|
9
|
+
interface HttpIsCheckoutEnabledByCustomerIdViewFunctionArgs {
|
|
10
|
+
readonly httpGet: HttpGetFunction;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface HttpIsCheckoutEnabledByCustomerIdViewFunction {
|
|
14
|
+
(args: HttpIsCheckoutEnabledByCustomerIdViewFunctionArgs): HttpIsCheckoutEnabledByCustomerIdView;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const httpIsCheckoutEnabledByCustomerIdView: HttpIsCheckoutEnabledByCustomerIdViewFunction =
|
|
18
|
+
({ httpGet }) =>
|
|
19
|
+
async ({ customerId }): Promise<IsCheckoutEnabledByCustomerIdProjection> => {
|
|
20
|
+
const response = await httpGet({
|
|
21
|
+
endpoint: `/is-new-checkout-enabled/${customerId}`,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return !response.ok ? false : await response.json();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { httpIsCheckoutEnabledByCustomerIdView };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { bootstrap } from "@lookiero/messaging-react";
|
|
2
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
3
|
+
import {
|
|
4
|
+
BookedSizeReplaceableProductVariantsProjection,
|
|
5
|
+
viewBookedSizeReplaceableProductVariantsForCheckoutItemHandler,
|
|
6
|
+
VIEW_BOOKED_SIZE_REPLACEABLE_PRODUCT_VARIANTS_FOR_CHECKOUT_ITEM,
|
|
7
|
+
} from "../../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
|
|
8
|
+
import { useViewBookedSizeReplaceableProductVariantsForCheckoutItem } from "./useViewBookedSizeReplaceableProductVariantsForCheckoutItem";
|
|
9
|
+
|
|
10
|
+
const checkoutItemId = "6f720954-8039-4bed-9596-34fc5a02131b";
|
|
11
|
+
const bookedSizeReplaceableProductVariants: BookedSizeReplaceableProductVariantsProjection = {
|
|
12
|
+
booking: "b00e2c2d-7d9c-4808-88a4-e1c845ae6889",
|
|
13
|
+
productVariants: [
|
|
14
|
+
{
|
|
15
|
+
id: "383fab95-56eb-4639-bb18-530ab792b4d3",
|
|
16
|
+
size: {
|
|
17
|
+
id: "4f8a26b8-8d2d-4012-b49a-7d2820095598",
|
|
18
|
+
europe: { size: "36", format: "36" },
|
|
19
|
+
lookiero: { size: "S", format: "S" },
|
|
20
|
+
uk: { size: "8", format: "8" },
|
|
21
|
+
it: { size: "M", format: "M" },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
const view = jest.fn().mockReturnValue(bookedSizeReplaceableProductVariants);
|
|
27
|
+
const { Component: Messaging } = bootstrap({ id: "Checkout" })
|
|
28
|
+
.query(
|
|
29
|
+
VIEW_BOOKED_SIZE_REPLACEABLE_PRODUCT_VARIANTS_FOR_CHECKOUT_ITEM,
|
|
30
|
+
viewBookedSizeReplaceableProductVariantsForCheckoutItemHandler,
|
|
31
|
+
{
|
|
32
|
+
view,
|
|
33
|
+
},
|
|
34
|
+
)
|
|
35
|
+
.build();
|
|
36
|
+
|
|
37
|
+
describe("useViewBookedSizeReplaceableProductVariantsForCheckoutItem integration hook", () => {
|
|
38
|
+
it("returns success as the query status and the result itself after rendering the hook", async () => {
|
|
39
|
+
const { result, waitFor } = renderHook(
|
|
40
|
+
() => useViewBookedSizeReplaceableProductVariantsForCheckoutItem({ checkoutItemId }),
|
|
41
|
+
{ wrapper: Messaging },
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
await waitFor(() => {
|
|
45
|
+
const [projection, status] = result.current;
|
|
46
|
+
|
|
47
|
+
expect(projection).toStrictEqual(bookedSizeReplaceableProductVariants);
|
|
48
|
+
expect(status).toBe("success");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useQuery, UseQueryFunctionResult } from "@lookiero/messaging-react";
|
|
2
|
+
import {
|
|
3
|
+
BookedSizeReplaceableProductVariantsProjection,
|
|
4
|
+
viewBookedSizeReplaceableProductVariantsForCheckoutItem,
|
|
5
|
+
} from "../../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
|
|
6
|
+
|
|
7
|
+
interface UseViewBookedSizeReplaceableProductVariantsForCheckoutItemFunctionArgs {
|
|
8
|
+
readonly checkoutItemId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface UseViewBookedSizeReplaceableProductVariantsForCheckoutItemFunction {
|
|
12
|
+
(
|
|
13
|
+
args: UseViewBookedSizeReplaceableProductVariantsForCheckoutItemFunctionArgs,
|
|
14
|
+
): UseQueryFunctionResult<BookedSizeReplaceableProductVariantsProjection>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const useViewBookedSizeReplaceableProductVariantsForCheckoutItem: UseViewBookedSizeReplaceableProductVariantsForCheckoutItemFunction =
|
|
18
|
+
({ checkoutItemId }) =>
|
|
19
|
+
useQuery({
|
|
20
|
+
query: viewBookedSizeReplaceableProductVariantsForCheckoutItem({ checkoutItemId }),
|
|
21
|
+
contextId: "Checkout",
|
|
22
|
+
options: { staleTime: Infinity },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export { useViewBookedSizeReplaceableProductVariantsForCheckoutItem };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { bootstrap } from "@lookiero/messaging-react";
|
|
2
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
3
|
+
import {
|
|
4
|
+
CheckoutProjection,
|
|
5
|
+
viewFirstAvailableCheckoutByCustomerIdHandler,
|
|
6
|
+
VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID,
|
|
7
|
+
} from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
8
|
+
import { useViewFirstAvailableCheckoutByCustomerId as sut } from "./useViewFirstAvailableCheckoutByCustomerId";
|
|
9
|
+
|
|
10
|
+
const customerId = "29790d24-b139-4ab8-b618-d796d101e974";
|
|
11
|
+
const checkoutProjection: CheckoutProjection = { id: "75574065-5838-42de-9924-c712f7854347" };
|
|
12
|
+
const view = jest.fn().mockReturnValue(checkoutProjection);
|
|
13
|
+
const { Component: Messaging } = bootstrap({ id: "Checkout" })
|
|
14
|
+
.query(VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, viewFirstAvailableCheckoutByCustomerIdHandler, { view })
|
|
15
|
+
.build();
|
|
16
|
+
|
|
17
|
+
describe("useViewFirstAvailableCheckoutByCustomerId integration hook", () => {
|
|
18
|
+
it("returns success as the query status and the result itself after rendering the hook", async () => {
|
|
19
|
+
const { result, waitFor } = renderHook(() => sut({ customerId }), { wrapper: Messaging });
|
|
20
|
+
|
|
21
|
+
await waitFor(() => {
|
|
22
|
+
const [projection, status] = result.current;
|
|
23
|
+
|
|
24
|
+
expect(projection).toStrictEqual(checkoutProjection);
|
|
25
|
+
expect(status).toBe("success");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useQuery, UseQueryFunctionResult } from "@lookiero/messaging-react";
|
|
2
|
+
import {
|
|
3
|
+
CheckoutProjection,
|
|
4
|
+
viewFirstAvailableCheckoutByCustomerId,
|
|
5
|
+
} from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
6
|
+
|
|
7
|
+
interface UseViewFirstAvailableCheckoutByCustomerIdFunctionArgs {
|
|
8
|
+
readonly customerId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface UseViewFirstAvailableCheckoutByCustomerIdFunction {
|
|
12
|
+
(args: UseViewFirstAvailableCheckoutByCustomerIdFunctionArgs): UseQueryFunctionResult<CheckoutProjection>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const useViewFirstAvailableCheckoutByCustomerId: UseViewFirstAvailableCheckoutByCustomerIdFunction = ({ customerId }) =>
|
|
16
|
+
useQuery({
|
|
17
|
+
query: viewFirstAvailableCheckoutByCustomerId({ customerId }),
|
|
18
|
+
contextId: "Checkout",
|
|
19
|
+
options: { staleTime: Infinity, retry: false },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export { useViewFirstAvailableCheckoutByCustomerId };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { bootstrap } from "@lookiero/messaging-react";
|
|
2
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
3
|
+
import {
|
|
4
|
+
CheckoutProjection,
|
|
5
|
+
viewFirstAvailableCheckoutByCustomerIdHandler,
|
|
6
|
+
VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID,
|
|
7
|
+
} from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
8
|
+
import {
|
|
9
|
+
viewIsCheckoutAccessibleByCustomerIdHandler,
|
|
10
|
+
VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID,
|
|
11
|
+
} from "../../../projection/checkout/viewIsCheckoutAccessibleByCustomerId";
|
|
12
|
+
import {
|
|
13
|
+
viewIsCheckoutEnabledByCustomerIdHandler,
|
|
14
|
+
VIEW_IS_CHECKOUT_ENABLED_BY_CUSTOMER_ID,
|
|
15
|
+
} from "../../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
|
|
16
|
+
import { useViewIsCheckoutAccessibleByCustomerId as sut } from "./useViewIsCheckoutAccessibleByCustomerId";
|
|
17
|
+
|
|
18
|
+
const customerId = "29790d24-b139-4ab8-b618-d796d101e974";
|
|
19
|
+
const checkoutProjection: CheckoutProjection = { id: "75574065-5838-42de-9924-c712f7854347" };
|
|
20
|
+
const firstAvailableCheckoutByCustomerIdViewMock = jest.fn().mockReturnValue(checkoutProjection);
|
|
21
|
+
const isCheckoutAccessibleByCustomerIdViewMock = jest.fn().mockReturnValue(checkoutProjection);
|
|
22
|
+
|
|
23
|
+
const { Component: Messaging } = bootstrap({ id: "Checkout" })
|
|
24
|
+
.query(VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, viewFirstAvailableCheckoutByCustomerIdHandler, {
|
|
25
|
+
view: firstAvailableCheckoutByCustomerIdViewMock,
|
|
26
|
+
})
|
|
27
|
+
.query(VIEW_IS_CHECKOUT_ENABLED_BY_CUSTOMER_ID, viewIsCheckoutEnabledByCustomerIdHandler, {
|
|
28
|
+
view: isCheckoutAccessibleByCustomerIdViewMock,
|
|
29
|
+
})
|
|
30
|
+
.query(VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID, viewIsCheckoutAccessibleByCustomerIdHandler, {})
|
|
31
|
+
.build();
|
|
32
|
+
|
|
33
|
+
describe("useViewIsCheckoutAccessibleByCustomerId integration hook", () => {
|
|
34
|
+
it("returns success as the query status and the result itself after rendering the hook", async () => {
|
|
35
|
+
const { result, waitFor } = renderHook(() => sut({ customerId }), { wrapper: Messaging });
|
|
36
|
+
|
|
37
|
+
await waitFor(() => {
|
|
38
|
+
const [projection, status] = result.current;
|
|
39
|
+
|
|
40
|
+
expect(projection).toBe(true);
|
|
41
|
+
expect(status).toBe("success");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useQuery, UseQueryFunctionResult } from "@lookiero/messaging-react";
|
|
2
|
+
import {
|
|
3
|
+
IsCheckoutAccessibleByCustomerIdProjection,
|
|
4
|
+
viewIsCheckoutAccessibleByCustomerId,
|
|
5
|
+
} from "../../../projection/checkout/viewIsCheckoutAccessibleByCustomerId";
|
|
6
|
+
|
|
7
|
+
interface UseViewIsCheckoutAccessibleByCustomerIdFunctionArgs {
|
|
8
|
+
readonly customerId: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface UseViewIsCheckoutAccessibleByCustomerIdFunction {
|
|
12
|
+
(
|
|
13
|
+
args: UseViewIsCheckoutAccessibleByCustomerIdFunctionArgs,
|
|
14
|
+
): UseQueryFunctionResult<IsCheckoutAccessibleByCustomerIdProjection>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const useViewIsCheckoutAccessibleByCustomerId: UseViewIsCheckoutAccessibleByCustomerIdFunction = ({ customerId }) =>
|
|
18
|
+
useQuery({
|
|
19
|
+
query: viewIsCheckoutAccessibleByCustomerId({ customerId }),
|
|
20
|
+
contextId: "Checkout",
|
|
21
|
+
options: { staleTime: Infinity },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export { useViewIsCheckoutAccessibleByCustomerId };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { bootstrap } from "@lookiero/messaging-react";
|
|
2
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
3
|
+
import {
|
|
4
|
+
UiSettingProjection,
|
|
5
|
+
viewUiSettingByKeyHandler,
|
|
6
|
+
VIEW_UI_SETTING_BY_KEY,
|
|
7
|
+
} from "../../../projection/uiSetting/viewUiSettingByKey";
|
|
8
|
+
import { useViewUiSettingByKey as sut } from "./useViewUiSettingByKey";
|
|
9
|
+
|
|
10
|
+
const uiSettingKey = "ui_setting_key";
|
|
11
|
+
const uiSettingProjection: UiSettingProjection = {
|
|
12
|
+
id: "this-should-be-a-uuid",
|
|
13
|
+
key: uiSettingKey,
|
|
14
|
+
value: "ui_setting_value",
|
|
15
|
+
};
|
|
16
|
+
const view = jest.fn().mockReturnValue(uiSettingProjection);
|
|
17
|
+
const { Component: Messaging } = bootstrap().query(VIEW_UI_SETTING_BY_KEY, viewUiSettingByKeyHandler, { view }).build();
|
|
18
|
+
|
|
19
|
+
describe("useViewUiSettingByKey integration hook", () => {
|
|
20
|
+
it("returns success as the query status and the result itself after rendering the hook", async () => {
|
|
21
|
+
const { result, waitFor } = renderHook(() => sut({ uiSettingKey }), { wrapper: Messaging });
|
|
22
|
+
|
|
23
|
+
await waitFor(() => {
|
|
24
|
+
const [projection, status] = result.current;
|
|
25
|
+
|
|
26
|
+
expect(projection).toStrictEqual(uiSettingProjection);
|
|
27
|
+
expect(status).toBe("success");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useQuery, UseQueryFunctionResult } from "@lookiero/messaging-react";
|
|
2
|
+
import { uiSettingUpdated } from "../../../domain/uiSetting/model/uiSettingUpdated";
|
|
3
|
+
import { UiSettingProjection, viewUiSettingByKey } from "../../../projection/uiSetting/viewUiSettingByKey";
|
|
4
|
+
|
|
5
|
+
interface UseViewUiSettingByKeyFunctionArgs {
|
|
6
|
+
readonly uiSettingKey: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface UseViewUiSettingByKeyFunction {
|
|
10
|
+
(args: UseViewUiSettingByKeyFunctionArgs): UseQueryFunctionResult<UiSettingProjection>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const useViewUiSettingByKey: UseViewUiSettingByKeyFunction = ({ uiSettingKey }) =>
|
|
14
|
+
useQuery({
|
|
15
|
+
query: viewUiSettingByKey({ key: uiSettingKey }),
|
|
16
|
+
invalidation: (event) => event instanceof uiSettingUpdated,
|
|
17
|
+
options: { staleTime: Infinity },
|
|
18
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { UiSettingDto } from "../persistence/uiSettingData";
|
|
2
|
+
import { storageUiSettingByKeyView as sut } from "./storageUiSettingByKeyView";
|
|
3
|
+
|
|
4
|
+
const uiSettingKey = "ui_setting_key";
|
|
5
|
+
const uiSetting: UiSettingDto = { id: "this-should-be-a-uuid", key: uiSettingKey, value: "ui_setting_value" };
|
|
6
|
+
|
|
7
|
+
const readMock = jest.fn();
|
|
8
|
+
const view = sut({ read: readMock });
|
|
9
|
+
|
|
10
|
+
describe("storageUiSettingByKeyView", () => {
|
|
11
|
+
it("returns a UiSetting projection", async () => {
|
|
12
|
+
readMock.mockReturnValue(Promise.resolve(uiSetting));
|
|
13
|
+
|
|
14
|
+
const returnedUiSetting = await view({ key: uiSettingKey });
|
|
15
|
+
|
|
16
|
+
expect(returnedUiSetting).toStrictEqual(uiSetting);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("returns undefined when ui setting key does not exist", async () => {
|
|
20
|
+
readMock.mockReturnValue(Promise.resolve(undefined));
|
|
21
|
+
|
|
22
|
+
const returnedUiSetting = await view({ key: uiSettingKey });
|
|
23
|
+
|
|
24
|
+
expect(returnedUiSetting).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("throws for an unsuccessfull response", async () => {
|
|
28
|
+
readMock.mockRejectedValue("error");
|
|
29
|
+
|
|
30
|
+
await expect(view({ key: uiSettingKey })).rejects.toThrow();
|
|
31
|
+
});
|
|
32
|
+
});
|