@lookiero/checkout 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/dist/infrastructure/delivery/_mock/bootstrap.mock.js +2 -1
  2. package/dist/infrastructure/delivery/bootstrap.d.ts +2 -1
  3. package/dist/infrastructure/delivery/bootstrap.js +3 -2
  4. package/dist/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.js +2 -1
  5. package/dist/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.js +2 -1
  6. package/dist/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.js +2 -1
  7. package/dist/infrastructure/projection/react/useViewUiSettingByKey.js +3 -1
  8. package/dist/infrastructure/ui/Root.js +8 -10
  9. package/dist/infrastructure/ui/components/atoms/spinner/Spinner.js +9 -0
  10. package/dist/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.js +4 -4
  11. package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +12 -9
  12. package/dist/infrastructure/ui/routing/Routing.js +11 -14
  13. package/dist/infrastructure/ui/views/intro/Intro.js +5 -7
  14. package/dist/infrastructure/ui/views/item/Item.js +6 -8
  15. package/dist/infrastructure/ui/views/summary/Summary.js +5 -7
  16. package/package.json +6 -3
  17. package/.eslintignore +0 -7
  18. package/.eslintrc +0 -72
  19. package/.expo-shared/assets.json +0 -4
  20. package/.github/CODEOWNERS +0 -1
  21. package/.github/actions/version/action.yaml +0 -32
  22. package/.github/dependabot.yaml +0 -10
  23. package/.github/workflows/build.yaml +0 -71
  24. package/.github/workflows/publish.yaml +0 -52
  25. package/.husky/pre-commit +0 -4
  26. package/.husky/prepare-commit-msg +0 -26
  27. package/.husky/prepush +0 -12
  28. package/.lintstagedrc.json +0 -4
  29. package/.nvmrc +0 -1
  30. package/.prettierignore +0 -2
  31. package/.prettierrc.json +0 -6
  32. package/@types/aurora-next.d.ts +0 -1
  33. package/app.config.js +0 -4
  34. package/app.json +0 -31
  35. package/assets/adaptive-icon.png +0 -0
  36. package/assets/favicon.png +0 -0
  37. package/assets/icon.png +0 -0
  38. package/assets/splash.png +0 -0
  39. package/babel.config.js +0 -6
  40. package/dist/infrastructure/ui/components/atoms/spiner/Spinner.js +0 -11
  41. package/dist/infrastructure/ui/test/render.d.ts +0 -19
  42. package/dist/infrastructure/ui/test/render.js +0 -14
  43. package/jest.config.js +0 -9
  44. package/jest.setup.js +0 -3
  45. package/src/Expo.tsx +0 -59
  46. package/src/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.test.ts +0 -26
  47. package/src/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.ts +0 -35
  48. package/src/domain/checkoutBooking/model/checkoutBooking.test.ts +0 -30
  49. package/src/domain/checkoutBooking/model/checkoutBooking.ts +0 -33
  50. package/src/domain/checkoutBooking/model/checkoutBookingBooked.test.ts +0 -23
  51. package/src/domain/checkoutBooking/model/checkoutBookingBooked.ts +0 -23
  52. package/src/domain/checkoutBooking/model/checkoutBookings.ts +0 -8
  53. package/src/domain/uiSetting/command/updateUiSetting.test.ts +0 -19
  54. package/src/domain/uiSetting/command/updateUiSetting.ts +0 -25
  55. package/src/domain/uiSetting/model/uiSetting.test.ts +0 -26
  56. package/src/domain/uiSetting/model/uiSetting.ts +0 -24
  57. package/src/domain/uiSetting/model/uiSettingUpdated.test.ts +0 -17
  58. package/src/domain/uiSetting/model/uiSettingUpdated.ts +0 -21
  59. package/src/domain/uiSetting/model/uiSettings.ts +0 -8
  60. package/src/index.ts +0 -44
  61. package/src/infrastructure/delivery/_mock/bootstrap.mock.ts +0 -38
  62. package/src/infrastructure/delivery/_mock/checkout.mock.ts +0 -81
  63. package/src/infrastructure/delivery/bootstrap.ts +0 -42
  64. package/src/infrastructure/delivery/http/fetchHttpClient.test.ts +0 -51
  65. package/src/infrastructure/delivery/http/fetchHttpClient.ts +0 -41
  66. package/src/infrastructure/delivery/http/httpClient.ts +0 -18
  67. package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.test.ts +0 -45
  68. package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.ts +0 -34
  69. package/src/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.test.ts +0 -38
  70. package/src/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.ts +0 -46
  71. package/src/infrastructure/domain/react/useSetCheckoutIntroShown.test.ts +0 -34
  72. package/src/infrastructure/domain/react/useSetCheckoutIntroShown.ts +0 -30
  73. package/src/infrastructure/domain/react/useUpdateUiSetting.test.ts +0 -31
  74. package/src/infrastructure/domain/react/useUpdateUiSetting.ts +0 -45
  75. package/src/infrastructure/domain/uiSetting/model/storageUiSettings.test.ts +0 -50
  76. package/src/infrastructure/domain/uiSetting/model/storageUiSettings.ts +0 -52
  77. package/src/infrastructure/persistence/asyncStorageStorage.ts +0 -13
  78. package/src/infrastructure/persistence/storage.ts +0 -9
  79. package/src/infrastructure/persistence/uiSettingData.ts +0 -7
  80. package/src/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.test.ts +0 -65
  81. package/src/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.ts +0 -102
  82. package/src/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.test.ts +0 -99
  83. package/src/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.ts +0 -128
  84. package/src/infrastructure/projection/httpIsCheckoutEnabledByCustomerIdView.test.ts +0 -32
  85. package/src/infrastructure/projection/httpIsCheckoutEnabledByCustomerIdView.ts +0 -27
  86. package/src/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.test.ts +0 -51
  87. package/src/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.ts +0 -25
  88. package/src/infrastructure/projection/react/useViewCheckoutIntroShown.test.ts +0 -41
  89. package/src/infrastructure/projection/react/useViewCheckoutIntroShown.ts +0 -9
  90. package/src/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.test.ts +0 -28
  91. package/src/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.ts +0 -22
  92. package/src/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.test.ts +0 -44
  93. package/src/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.ts +0 -24
  94. package/src/infrastructure/projection/react/useViewUiSettingByKey.test.ts +0 -30
  95. package/src/infrastructure/projection/react/useViewUiSettingByKey.ts +0 -24
  96. package/src/infrastructure/projection/storageUiSettingByKeyView.test.ts +0 -32
  97. package/src/infrastructure/projection/storageUiSettingByKeyView.ts +0 -37
  98. package/src/infrastructure/ui/Root.tsx +0 -53
  99. package/src/infrastructure/ui/components/atoms/spiner/Spinner.style.ts +0 -12
  100. package/src/infrastructure/ui/components/atoms/spiner/Spinner.tsx +0 -35
  101. package/src/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.test.tsx +0 -70
  102. package/src/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.tsx +0 -31
  103. package/src/infrastructure/ui/routing/CheckoutMiddleware.test.tsx +0 -100
  104. package/src/infrastructure/ui/routing/CheckoutMiddleware.tsx +0 -52
  105. package/src/infrastructure/ui/routing/Routing.tsx +0 -64
  106. package/src/infrastructure/ui/routing/router/Router.native.ts +0 -1
  107. package/src/infrastructure/ui/routing/router/Router.ts +0 -1
  108. package/src/infrastructure/ui/routing/routes.ts +0 -6
  109. package/src/infrastructure/ui/settings/UISettings.ts +0 -5
  110. package/src/infrastructure/ui/test/render.tsx +0 -47
  111. package/src/infrastructure/ui/views/intro/Intro.test.tsx +0 -15
  112. package/src/infrastructure/ui/views/intro/Intro.tsx +0 -27
  113. package/src/infrastructure/ui/views/item/Item.tsx +0 -31
  114. package/src/infrastructure/ui/views/summary/Summary.tsx +0 -27
  115. package/src/projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem.test.ts +0 -40
  116. package/src/projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem.ts +0 -85
  117. package/src/projection/checkout/viewFirstAvailableCheckoutByCustomerId.test.ts +0 -22
  118. package/src/projection/checkout/viewFirstAvailableCheckoutByCustomerId.ts +0 -149
  119. package/src/projection/checkout/viewIsCheckoutAccessibleByCustomerId.test.ts +0 -54
  120. package/src/projection/checkout/viewIsCheckoutAccessibleByCustomerId.ts +0 -46
  121. package/src/projection/checkout/viewIsCheckoutEnabledByCustomerId.test.ts +0 -20
  122. package/src/projection/checkout/viewIsCheckoutEnabledByCustomerId.ts +0 -51
  123. package/src/projection/uiSetting/viewUiSettingByKey.test.ts +0 -22
  124. package/src/projection/uiSetting/viewUiSettingByKey.ts +0 -55
  125. package/tsconfig.build.json +0 -16
  126. package/tsconfig.json +0 -19
  127. package/webpack.config.js +0 -17
  128. /package/dist/infrastructure/ui/components/atoms/{spiner → spinner}/Spinner.d.ts +0 -0
  129. /package/dist/infrastructure/ui/components/atoms/{spiner → spinner}/Spinner.style.d.ts +0 -0
  130. /package/dist/infrastructure/ui/components/atoms/{spiner → spinner}/Spinner.style.js +0 -0
@@ -1,52 +0,0 @@
1
- import { UiSetting } from "../../../../domain/uiSetting/model/uiSetting";
2
- import { UiSettingGetFunction, UiSettingSaveFunction } from "../../../../domain/uiSetting/model/uiSettings";
3
- import { ReadFunction, WriteFunction } from "../../../persistence/storage";
4
- import { UiSettingDto } from "../../../persistence/uiSettingData";
5
-
6
- const toDomain = (uiSettingDto: UiSettingDto): UiSetting => ({
7
- aggregateId: uiSettingDto.id,
8
- key: uiSettingDto.key,
9
- value: uiSettingDto.value,
10
- domainEvents: [],
11
- });
12
-
13
- const fromDomain = (uiSetting: UiSetting): UiSettingDto => ({
14
- id: uiSetting.aggregateId,
15
- key: uiSetting.key,
16
- value: uiSetting.value,
17
- });
18
-
19
- interface StorageUiSettingsGetFunctionArgs {
20
- readonly read: ReadFunction<UiSettingDto>;
21
- }
22
-
23
- interface StorageUiSettingsGetFunction {
24
- (args: StorageUiSettingsGetFunctionArgs): UiSettingGetFunction;
25
- }
26
-
27
- const getUiSetting: StorageUiSettingsGetFunction =
28
- ({ read }) =>
29
- async (uiSettingKey) => {
30
- const uiSettingDto = await read(uiSettingKey);
31
-
32
- if (!uiSettingDto) {
33
- throw new Error(`UiSetting not found: ${uiSettingKey}`);
34
- }
35
-
36
- return toDomain(uiSettingDto);
37
- };
38
-
39
- interface StorageUiSettingsSaveFunctionArgs {
40
- readonly write: WriteFunction<UiSettingDto>;
41
- }
42
-
43
- interface StorageUiSettingsSaveFunction {
44
- (args: StorageUiSettingsSaveFunctionArgs): UiSettingSaveFunction;
45
- }
46
-
47
- const saveUiSetting: StorageUiSettingsSaveFunction =
48
- ({ write }) =>
49
- async (aggregateRoot) =>
50
- await write(aggregateRoot.key, fromDomain(aggregateRoot));
51
-
52
- export { getUiSetting, saveUiSetting };
@@ -1,13 +0,0 @@
1
- import AsyncStorage from "@react-native-async-storage/async-storage";
2
- import { ReadFunction, WriteFunction } from "./storage";
3
- import { UiSettingDto } from "./uiSettingData";
4
-
5
- const read: ReadFunction<UiSettingDto> = async (key) => {
6
- const value = await AsyncStorage.getItem(key);
7
-
8
- return value ? JSON.parse(value) : undefined;
9
- };
10
-
11
- const write: WriteFunction<UiSettingDto> = async (key, value) => AsyncStorage.setItem(key, JSON.stringify(value));
12
-
13
- export { read, write };
@@ -1,9 +0,0 @@
1
- interface ReadFunction<T> {
2
- (key: string): Promise<T | undefined>;
3
- }
4
-
5
- interface WriteFunction<T> {
6
- (key: string, value: T): Promise<void>;
7
- }
8
-
9
- export { ReadFunction, WriteFunction };
@@ -1,7 +0,0 @@
1
- interface UiSettingDto {
2
- readonly id: string;
3
- readonly key: string;
4
- readonly value: unknown;
5
- }
6
-
7
- export { UiSettingDto };
@@ -1,65 +0,0 @@
1
- import {
2
- BookedSizeReplaceableProductVariantsDto,
3
- httpBookedSizeReplaceableProductVariantsForCheckoutItemView,
4
- toBookedSizeReplaceableProductVariants,
5
- } from "./httpBookedSizeReplaceableProductVariantsForCheckoutItemView";
6
-
7
- const checkoutItemId = "6f720954-8039-4bed-9596-34fc5a02131b";
8
- const bookedSizeReplaceableProductVariantsResponse: { result: BookedSizeReplaceableProductVariantsDto } = {
9
- result: {
10
- booking: "b00e2c2d-7d9c-4808-88a4-e1c845ae6889",
11
- product_variants: [
12
- {
13
- id: "383fab95-56eb-4639-bb18-530ab792b4d3",
14
- size: {
15
- id: "4f8a26b8-8d2d-4012-b49a-7d2820095598",
16
- europe: { size: "36", format: "36" },
17
- lookiero: { size: "S", format: "S" },
18
- uk: { size: "8", format: "8" },
19
- it: { size: "M", format: "M" },
20
- },
21
- },
22
- ],
23
- },
24
- };
25
- const bookedSizeReplaceableProductVariantsResponseOk: Response = {
26
- ok: true,
27
- status: 200,
28
- json: () => Promise.resolve(bookedSizeReplaceableProductVariantsResponse),
29
- } as Response;
30
- const bookedSizeReplaceableProductVariantsResponseNotFound: Response = {
31
- ok: false,
32
- status: 404,
33
- } as Response;
34
- const bookedSizeReplaceableProductVariantsResponseError: Response = {
35
- ok: false,
36
- } as Response;
37
-
38
- const httpPostMock = jest.fn();
39
- const view = httpBookedSizeReplaceableProductVariantsForCheckoutItemView({ httpPost: httpPostMock });
40
-
41
- describe("httpBookedSizeReplaceableProductVariantsForCheckoutItemView", () => {
42
- it("returns a BookedSizeReplaceableProductVariants projection for a 200 response", async () => {
43
- httpPostMock.mockReturnValue(Promise.resolve(bookedSizeReplaceableProductVariantsResponseOk));
44
-
45
- const returnedBookedSizeReplaceableProductVariants = await view({ checkoutItemId });
46
-
47
- expect(returnedBookedSizeReplaceableProductVariants).toStrictEqual(
48
- toBookedSizeReplaceableProductVariants(bookedSizeReplaceableProductVariantsResponse.result),
49
- );
50
- });
51
-
52
- it("returns undefined for a 404 response", async () => {
53
- httpPostMock.mockReturnValue(Promise.resolve(bookedSizeReplaceableProductVariantsResponseNotFound));
54
-
55
- const returnedBookedSizeReplaceableProductVariants = await view({ checkoutItemId });
56
-
57
- expect(returnedBookedSizeReplaceableProductVariants).toBeUndefined();
58
- });
59
-
60
- it("throws for an unsuccessfull response", async () => {
61
- httpPostMock.mockReturnValue(Promise.resolve(bookedSizeReplaceableProductVariantsResponseError));
62
-
63
- await expect(view({ checkoutItemId })).rejects.toThrow();
64
- });
65
- });
@@ -1,102 +0,0 @@
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
- };
@@ -1,99 +0,0 @@
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
- });
@@ -1,128 +0,0 @@
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 };
@@ -1,32 +0,0 @@
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
- });
@@ -1,27 +0,0 @@
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 };
@@ -1,51 +0,0 @@
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
- });
@@ -1,25 +0,0 @@
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 };
@@ -1,41 +0,0 @@
1
- import { CommandStatus } from "@lookiero/messaging-react";
2
- import { renderHook } from "@testing-library/react-hooks";
3
- import { UiSettingProjection } from "../../../projection/uiSetting/viewUiSettingByKey";
4
- import { useViewCheckoutIntroShown as sut } from "./useViewCheckoutIntroShown";
5
- import { useViewUiSettingByKey } from "./useViewUiSettingByKey";
6
-
7
- jest.mock("./useViewUiSettingByKey");
8
-
9
- const uiSettingProjection: UiSettingProjection = {
10
- id: "this-should-be-a-uuid",
11
- key: "ui_setting_key",
12
- value: "ui_setting_value",
13
- };
14
-
15
- describe("useViewCheckoutIntroShown integration hook", () => {
16
- it("returns uiSetting after rendering the hook (existing ui setting key)", async () => {
17
- (useViewUiSettingByKey as jest.Mock).mockReturnValue([uiSettingProjection, CommandStatus.SUCCESS]);
18
-
19
- const { result, waitFor } = renderHook(() => sut());
20
-
21
- await waitFor(() => {
22
- const [projection, status] = result.current;
23
-
24
- expect(projection).toStrictEqual(uiSettingProjection);
25
- expect(status).toBe(CommandStatus.SUCCESS);
26
- });
27
- });
28
-
29
- it("returns undefined after rendering the hook (non-existing ui setting key)", async () => {
30
- (useViewUiSettingByKey as jest.Mock).mockReturnValue([undefined, CommandStatus.ERROR]);
31
-
32
- const { result, waitFor } = renderHook(() => sut());
33
-
34
- await waitFor(() => {
35
- const [projection, status] = result.current;
36
-
37
- expect(projection).toBeUndefined();
38
- expect(status).toBe(CommandStatus.ERROR);
39
- });
40
- });
41
- });
@@ -1,9 +0,0 @@
1
- import { UISettings } from "../../ui/settings/UISettings";
2
- import { useViewUiSettingByKey } from "./useViewUiSettingByKey";
3
-
4
- const useViewCheckoutIntroShown = () =>
5
- useViewUiSettingByKey({
6
- key: UISettings.CHECKOUT_INTRO_SHOWN,
7
- });
8
-
9
- export { useViewCheckoutIntroShown };