@lookiero/checkout 0.1.1 → 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 (165) hide show
  1. package/dist/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.d.ts +4 -4
  2. package/dist/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.js +3 -2
  3. package/dist/domain/checkoutBooking/model/checkoutBooking.d.ts +3 -2
  4. package/dist/domain/checkoutBooking/model/checkoutBooking.js +2 -1
  5. package/dist/domain/checkoutBooking/model/checkoutBookingBooked.d.ts +4 -4
  6. package/dist/domain/checkoutBooking/model/checkoutBookingBooked.js +3 -2
  7. package/dist/domain/checkoutBooking/model/checkoutBookings.d.ts +3 -2
  8. package/dist/domain/uiSetting/command/updateUiSetting.d.ts +4 -4
  9. package/dist/domain/uiSetting/command/updateUiSetting.js +3 -2
  10. package/dist/domain/uiSetting/model/uiSetting.d.ts +3 -2
  11. package/dist/domain/uiSetting/model/uiSetting.js +2 -1
  12. package/dist/domain/uiSetting/model/uiSettingUpdated.d.ts +4 -4
  13. package/dist/domain/uiSetting/model/uiSettingUpdated.js +3 -2
  14. package/dist/domain/uiSetting/model/uiSettings.d.ts +3 -2
  15. package/dist/infrastructure/delivery/_mock/bootstrap.mock.js +2 -1
  16. package/dist/infrastructure/delivery/bootstrap.d.ts +2 -1
  17. package/dist/infrastructure/delivery/bootstrap.js +3 -2
  18. package/dist/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.d.ts +2 -2
  19. package/dist/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.js +2 -1
  20. package/dist/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.d.ts +2 -2
  21. package/dist/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.js +2 -1
  22. package/dist/infrastructure/domain/react/useSetCheckoutIntroShown.d.ts +13 -0
  23. package/dist/infrastructure/domain/react/useSetCheckoutIntroShown.js +9 -0
  24. package/dist/infrastructure/domain/react/useUpdateUiSetting.d.ts +2 -2
  25. package/dist/infrastructure/domain/react/useUpdateUiSetting.js +2 -1
  26. package/dist/infrastructure/domain/uiSetting/model/storageUiSettings.d.ts +3 -3
  27. package/dist/infrastructure/domain/uiSetting/model/storageUiSettings.js +3 -2
  28. package/dist/infrastructure/persistence/asyncStorageStorage.d.ts +3 -2
  29. package/dist/infrastructure/persistence/asyncStorageStorage.js +3 -2
  30. package/dist/infrastructure/persistence/storage.d.ts +3 -2
  31. package/dist/infrastructure/persistence/uiSettingData.d.ts +2 -1
  32. package/dist/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.js +2 -1
  33. package/dist/infrastructure/projection/react/useViewCheckoutIntroShown.d.ts +2 -0
  34. package/dist/infrastructure/projection/react/useViewCheckoutIntroShown.js +6 -0
  35. package/dist/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.js +2 -1
  36. package/dist/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.js +2 -1
  37. package/dist/infrastructure/projection/react/useViewUiSettingByKey.d.ts +3 -3
  38. package/dist/infrastructure/projection/react/useViewUiSettingByKey.js +9 -5
  39. package/dist/infrastructure/projection/storageUiSettingByKeyView.d.ts +2 -2
  40. package/dist/infrastructure/projection/storageUiSettingByKeyView.js +2 -1
  41. package/dist/infrastructure/ui/Root.js +8 -10
  42. package/dist/infrastructure/ui/components/atoms/spinner/Spinner.js +9 -0
  43. package/dist/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.js +4 -4
  44. package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +13 -10
  45. package/dist/infrastructure/ui/routing/Routing.js +11 -14
  46. package/dist/infrastructure/ui/settings/UISettings.d.ts +4 -0
  47. package/dist/infrastructure/ui/settings/UISettings.js +5 -0
  48. package/dist/infrastructure/ui/views/intro/Intro.js +5 -7
  49. package/dist/infrastructure/ui/views/item/Item.js +6 -8
  50. package/dist/infrastructure/ui/views/summary/Summary.js +5 -7
  51. package/dist/projection/uiSetting/viewUiSettingByKey.d.ts +6 -6
  52. package/dist/projection/uiSetting/viewUiSettingByKey.js +4 -3
  53. package/package.json +6 -3
  54. package/.eslintignore +0 -7
  55. package/.eslintrc +0 -72
  56. package/.expo-shared/assets.json +0 -4
  57. package/.github/CODEOWNERS +0 -1
  58. package/.github/actions/version/action.yaml +0 -32
  59. package/.github/dependabot.yaml +0 -10
  60. package/.github/workflows/build.yaml +0 -71
  61. package/.github/workflows/publish.yaml +0 -52
  62. package/.husky/pre-commit +0 -4
  63. package/.husky/prepare-commit-msg +0 -26
  64. package/.husky/prepush +0 -12
  65. package/.lintstagedrc.json +0 -4
  66. package/.nvmrc +0 -1
  67. package/.prettierignore +0 -2
  68. package/.prettierrc.json +0 -6
  69. package/@types/aurora-next.d.ts +0 -1
  70. package/app.config.js +0 -4
  71. package/app.json +0 -31
  72. package/assets/adaptive-icon.png +0 -0
  73. package/assets/favicon.png +0 -0
  74. package/assets/icon.png +0 -0
  75. package/assets/splash.png +0 -0
  76. package/babel.config.js +0 -6
  77. package/dist/infrastructure/projection/react/useViewIsCheckoutIntroVisible.d.ts +0 -3
  78. package/dist/infrastructure/projection/react/useViewIsCheckoutIntroVisible.js +0 -3
  79. package/dist/infrastructure/ui/components/atoms/spiner/Spinner.js +0 -11
  80. package/dist/infrastructure/ui/test/render.d.ts +0 -19
  81. package/dist/infrastructure/ui/test/render.js +0 -14
  82. package/jest.config.js +0 -9
  83. package/jest.setup.js +0 -3
  84. package/src/Expo.tsx +0 -59
  85. package/src/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.test.ts +0 -26
  86. package/src/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.ts +0 -27
  87. package/src/domain/checkoutBooking/model/checkoutBooking.test.ts +0 -30
  88. package/src/domain/checkoutBooking/model/checkoutBooking.ts +0 -31
  89. package/src/domain/checkoutBooking/model/checkoutBookingBooked.test.ts +0 -23
  90. package/src/domain/checkoutBooking/model/checkoutBookingBooked.ts +0 -23
  91. package/src/domain/checkoutBooking/model/checkoutBookings.ts +0 -6
  92. package/src/domain/uiSetting/command/updateUiSetting.test.ts +0 -19
  93. package/src/domain/uiSetting/command/updateUiSetting.ts +0 -23
  94. package/src/domain/uiSetting/model/uiSetting.test.ts +0 -26
  95. package/src/domain/uiSetting/model/uiSetting.ts +0 -22
  96. package/src/domain/uiSetting/model/uiSettingUpdated.test.ts +0 -17
  97. package/src/domain/uiSetting/model/uiSettingUpdated.ts +0 -19
  98. package/src/domain/uiSetting/model/uiSettings.ts +0 -6
  99. package/src/index.ts +0 -44
  100. package/src/infrastructure/delivery/_mock/bootstrap.mock.ts +0 -38
  101. package/src/infrastructure/delivery/_mock/checkout.mock.ts +0 -81
  102. package/src/infrastructure/delivery/bootstrap.ts +0 -42
  103. package/src/infrastructure/delivery/http/fetchHttpClient.test.ts +0 -51
  104. package/src/infrastructure/delivery/http/fetchHttpClient.ts +0 -41
  105. package/src/infrastructure/delivery/http/httpClient.ts +0 -18
  106. package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.test.ts +0 -45
  107. package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.ts +0 -32
  108. package/src/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.test.ts +0 -38
  109. package/src/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.ts +0 -44
  110. package/src/infrastructure/domain/react/useUpdateUiSetting.test.ts +0 -31
  111. package/src/infrastructure/domain/react/useUpdateUiSetting.ts +0 -43
  112. package/src/infrastructure/domain/uiSetting/model/storageUiSettings.test.ts +0 -50
  113. package/src/infrastructure/domain/uiSetting/model/storageUiSettings.ts +0 -50
  114. package/src/infrastructure/persistence/asyncStorageStorage.ts +0 -12
  115. package/src/infrastructure/persistence/storage.ts +0 -7
  116. package/src/infrastructure/persistence/uiSettingData.ts +0 -5
  117. package/src/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.test.ts +0 -65
  118. package/src/infrastructure/projection/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.ts +0 -102
  119. package/src/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.test.ts +0 -99
  120. package/src/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.ts +0 -128
  121. package/src/infrastructure/projection/httpIsCheckoutEnabledByCustomerIdView.test.ts +0 -32
  122. package/src/infrastructure/projection/httpIsCheckoutEnabledByCustomerIdView.ts +0 -27
  123. package/src/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.test.ts +0 -51
  124. package/src/infrastructure/projection/react/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.ts +0 -25
  125. package/src/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.test.ts +0 -28
  126. package/src/infrastructure/projection/react/useViewFirstAvailableCheckoutByCustomerId.ts +0 -22
  127. package/src/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.test.ts +0 -44
  128. package/src/infrastructure/projection/react/useViewIsCheckoutAccessibleByCustomerId.ts +0 -24
  129. package/src/infrastructure/projection/react/useViewIsCheckoutIntroVisible.ts +0 -5
  130. package/src/infrastructure/projection/react/useViewUiSettingByKey.test.ts +0 -30
  131. package/src/infrastructure/projection/react/useViewUiSettingByKey.ts +0 -18
  132. package/src/infrastructure/projection/storageUiSettingByKeyView.test.ts +0 -32
  133. package/src/infrastructure/projection/storageUiSettingByKeyView.ts +0 -35
  134. package/src/infrastructure/ui/Root.tsx +0 -53
  135. package/src/infrastructure/ui/components/atoms/spiner/Spinner.style.ts +0 -12
  136. package/src/infrastructure/ui/components/atoms/spiner/Spinner.tsx +0 -35
  137. package/src/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.test.tsx +0 -70
  138. package/src/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.tsx +0 -31
  139. package/src/infrastructure/ui/routing/CheckoutMiddleware.test.tsx +0 -100
  140. package/src/infrastructure/ui/routing/CheckoutMiddleware.tsx +0 -52
  141. package/src/infrastructure/ui/routing/Routing.tsx +0 -64
  142. package/src/infrastructure/ui/routing/router/Router.native.ts +0 -1
  143. package/src/infrastructure/ui/routing/router/Router.ts +0 -1
  144. package/src/infrastructure/ui/routing/routes.ts +0 -6
  145. package/src/infrastructure/ui/test/render.tsx +0 -47
  146. package/src/infrastructure/ui/views/intro/Intro.test.tsx +0 -15
  147. package/src/infrastructure/ui/views/intro/Intro.tsx +0 -27
  148. package/src/infrastructure/ui/views/item/Item.tsx +0 -31
  149. package/src/infrastructure/ui/views/summary/Summary.tsx +0 -27
  150. package/src/projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem.test.ts +0 -40
  151. package/src/projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem.ts +0 -85
  152. package/src/projection/checkout/viewFirstAvailableCheckoutByCustomerId.test.ts +0 -22
  153. package/src/projection/checkout/viewFirstAvailableCheckoutByCustomerId.ts +0 -149
  154. package/src/projection/checkout/viewIsCheckoutAccessibleByCustomerId.test.ts +0 -54
  155. package/src/projection/checkout/viewIsCheckoutAccessibleByCustomerId.ts +0 -46
  156. package/src/projection/checkout/viewIsCheckoutEnabledByCustomerId.test.ts +0 -20
  157. package/src/projection/checkout/viewIsCheckoutEnabledByCustomerId.ts +0 -51
  158. package/src/projection/uiSetting/viewUiSettingByKey.test.ts +0 -22
  159. package/src/projection/uiSetting/viewUiSettingByKey.ts +0 -47
  160. package/tsconfig.build.json +0 -16
  161. package/tsconfig.json +0 -19
  162. package/webpack.config.js +0 -17
  163. /package/dist/infrastructure/ui/components/atoms/{spiner → spinner}/Spinner.d.ts +0 -0
  164. /package/dist/infrastructure/ui/components/atoms/{spiner → spinner}/Spinner.style.d.ts +0 -0
  165. /package/dist/infrastructure/ui/components/atoms/{spiner → spinner}/Spinner.style.js +0 -0
@@ -1,51 +0,0 @@
1
- import { fetchHttpGet as sutGet, fetchHttpPost as sutPost } from "./fetchHttpClient";
2
-
3
- const fetchMock = jest.fn();
4
- global.fetch = fetchMock;
5
-
6
- const apiUrl = "/api";
7
- const authToken = "token";
8
- const post = sutPost({ apiUrl, getAuthToken: () => authToken });
9
- const get = sutGet({ apiUrl, getAuthToken: () => authToken });
10
-
11
- afterEach(() => {
12
- fetchMock.mockClear();
13
- });
14
-
15
- describe("fetchHttpClient", () => {
16
- it("does a POST http request with the expected parameters", async () => {
17
- const endpoint = "/dummy-endpoint";
18
- const body = { foo: "bar" };
19
- const expectedEndpoint = `${apiUrl}${endpoint}`;
20
- const expectedPayload = {
21
- method: "POST",
22
- headers: {
23
- ["Content-Type"]: "application/json",
24
- authorization: `Bearer ${authToken}`,
25
- },
26
- body: JSON.stringify(body),
27
- };
28
-
29
- await post({ endpoint, body });
30
-
31
- expect(fetchMock).toHaveBeenCalledWith(expectedEndpoint, expectedPayload);
32
- });
33
-
34
- it("does a GET http request with the expected parameters", async () => {
35
- const endpoint = "/dummy-endpoint";
36
- const expectedEndpoint = `${apiUrl}${endpoint}`;
37
- const expectedPayload = {
38
- method: "GET",
39
- credentials: "include",
40
- mode: "no-cors",
41
- headers: {
42
- authorization: `Bearer ${authToken}`,
43
- },
44
- referrer: "",
45
- };
46
-
47
- await get({ endpoint });
48
-
49
- expect(fetchMock).toHaveBeenCalledWith(expectedEndpoint, expectedPayload);
50
- });
51
- });
@@ -1,41 +0,0 @@
1
- import { HttpGetFunction, HttpPostFunction } from "./httpClient";
2
-
3
- interface FetchHttpFunctionArgs {
4
- readonly apiUrl: string;
5
- readonly getAuthToken: () => string;
6
- }
7
-
8
- interface FetchHttpPostFunction {
9
- (args: FetchHttpFunctionArgs): HttpPostFunction;
10
- }
11
-
12
- interface FetchHttpGetFunction {
13
- (args: FetchHttpFunctionArgs): HttpGetFunction;
14
- }
15
-
16
- const fetchHttpPost: FetchHttpPostFunction =
17
- ({ apiUrl, getAuthToken }) =>
18
- async ({ endpoint, body }) =>
19
- fetch(`${apiUrl}${endpoint}`, {
20
- method: "POST",
21
- headers: {
22
- ["Content-Type"]: "application/json",
23
- authorization: `Bearer ${getAuthToken()}`,
24
- },
25
- body: JSON.stringify(body),
26
- });
27
-
28
- const fetchHttpGet: FetchHttpGetFunction =
29
- ({ apiUrl, getAuthToken }) =>
30
- async ({ endpoint }) =>
31
- fetch(`${apiUrl}${endpoint}`, {
32
- method: "GET",
33
- credentials: "include",
34
- mode: "no-cors",
35
- headers: {
36
- authorization: `Bearer ${getAuthToken()}`,
37
- },
38
- referrer: "",
39
- });
40
-
41
- export { fetchHttpGet, fetchHttpPost };
@@ -1,18 +0,0 @@
1
- interface HttpGetFunctionArgs {
2
- readonly endpoint: string;
3
- }
4
-
5
- interface HttpGetFunction {
6
- (args: HttpGetFunctionArgs): Promise<Response>;
7
- }
8
-
9
- interface HttpPostFunctionArgs {
10
- readonly endpoint: string;
11
- readonly body: Record<string, unknown>;
12
- }
13
-
14
- interface HttpPostFunction {
15
- (args: HttpPostFunctionArgs): Promise<Response>;
16
- }
17
-
18
- export { HttpGetFunction, HttpPostFunction };
@@ -1,45 +0,0 @@
1
- import { v4 as uuid } from "uuid";
2
- import { saveCheckoutBooking as sut } from "./httpCheckoutBookings";
3
-
4
- const saveCheckoutBookingResponseOk: Response = {
5
- ok: true,
6
- } as Response;
7
- const saveCheckoutBookingResponseError: Response = {
8
- ok: false,
9
- } as Response;
10
-
11
- const httpPostMock = jest.fn();
12
-
13
- const checkoutBooking = {
14
- checkoutId: "this-should-be-a-uuid",
15
- checkoutItemId: "this-should-be-a-uuid",
16
- checkoutBookingId: "this-should-be-a-uuid",
17
- };
18
-
19
- describe("httpCheckoutBookings", () => {
20
- it("saveCheckoutBooking: calls '/book-size-replaceable-product-variants-for-checkout-item' endpoint", async () => {
21
- const expectedEndpoint = "/book-size-replaceable-product-variants-for-checkout-item";
22
- httpPostMock.mockReturnValue(Promise.resolve(saveCheckoutBookingResponseOk));
23
-
24
- const checkoutBookingsSave = { aggregateId: uuid(), ...checkoutBooking, domainEvents: [] };
25
-
26
- await sut({ httpPost: httpPostMock })(checkoutBookingsSave);
27
-
28
- expect(httpPostMock).toBeCalledWith({
29
- endpoint: expectedEndpoint,
30
- body: {
31
- checkout_id: checkoutBooking.checkoutId,
32
- checkout_item_id: checkoutBooking.checkoutItemId,
33
- checkout_booking_id: checkoutBooking.checkoutBookingId,
34
- },
35
- });
36
- });
37
-
38
- it("saveCheckoutBooking: throws for an unsuccessfull response", async () => {
39
- httpPostMock.mockReturnValue(Promise.resolve(saveCheckoutBookingResponseError));
40
-
41
- const checkoutBookingsSave = { aggregateId: uuid(), ...checkoutBooking, domainEvents: [] };
42
-
43
- await expect(sut({ httpPost: httpPostMock })(checkoutBookingsSave)).rejects.toThrow();
44
- });
45
- });
@@ -1,32 +0,0 @@
1
- import { CheckoutBookingsSaveFunction } from "../../../../domain/checkoutBooking/model/checkoutBookings";
2
- import { HttpPostFunction } from "../../../delivery/http/httpClient";
3
-
4
- interface HttpCheckoutBookingsSaveFunctionArgs {
5
- readonly httpPost: HttpPostFunction;
6
- }
7
-
8
- interface HttpCheckoutBookingsSaveFunction {
9
- (args: HttpCheckoutBookingsSaveFunctionArgs): CheckoutBookingsSaveFunction;
10
- }
11
-
12
- export const saveCheckoutBooking: HttpCheckoutBookingsSaveFunction =
13
- ({ httpPost }) =>
14
- async ({ checkoutId, checkoutItemId, checkoutBookingId }) => {
15
- try {
16
- const response = await httpPost({
17
- endpoint: "/book-size-replaceable-product-variants-for-checkout-item",
18
- body: {
19
- checkout_id: checkoutId,
20
- checkout_item_id: checkoutItemId,
21
- checkout_booking_id: checkoutBookingId,
22
- },
23
- });
24
-
25
- if (!response.ok) {
26
- throw new Error("Book size replaceable product variants for checkout item");
27
- }
28
- return;
29
- } catch (ignored) {
30
- throw new Error("Could not fetch BookSizeReplaceableProductVariantsForCheckoutItem");
31
- }
32
- };
@@ -1,38 +0,0 @@
1
- import { bootstrap, CommandStatus } from "@lookiero/messaging-react";
2
- import { act, renderHook } from "@testing-library/react-hooks";
3
- import { BOOK_SIZE_REPLACEABLE_PRODUCT_VARIANTS_FOR_CHECKOUT_ITEM } from "../../../domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem";
4
- import { bookSizeReplaceableProductVariantsForCheckoutItemHandler } from "../../../domain/checkoutBooking/model/checkoutBooking";
5
- import { useBookSizeReplaceableProductVariantsForCheckoutItem as sut } from "./useBookSizeReplaceableProductVariantsForCheckoutItem";
6
-
7
- const checkoutBooking = {
8
- checkoutId: "this-should-be-a-uuid",
9
- checkoutItemId: "this-should-be-a-uuid",
10
- checkoutBookingId: "this-should-be-a-uuid",
11
- };
12
-
13
- const saveMock = jest.fn();
14
- const { Component: Messaging } = bootstrap()
15
- .command(
16
- BOOK_SIZE_REPLACEABLE_PRODUCT_VARIANTS_FOR_CHECKOUT_ITEM,
17
- bookSizeReplaceableProductVariantsForCheckoutItemHandler,
18
- {
19
- get: jest.fn(),
20
- save: saveMock,
21
- },
22
- )
23
- .build();
24
-
25
- describe("useBookSizeReplaceableProductVariantsForCheckoutItem integration hook", () => {
26
- it("returns success as the status right after calling 'book'", async () => {
27
- saveMock.mockResolvedValue("success");
28
- const { result, waitFor } = renderHook(() => sut({ ...checkoutBooking }), { wrapper: Messaging });
29
-
30
- expect(result.current.status).toBe(CommandStatus.IDLE);
31
-
32
- await act(() => result.current.book());
33
-
34
- await waitFor(() => {
35
- expect(result.current.status).toBe(CommandStatus.SUCCESS);
36
- });
37
- });
38
- });
@@ -1,44 +0,0 @@
1
- import { CommandStatus, useCommand } from "@lookiero/messaging-react";
2
- import { useCallback } from "react";
3
- import { v4 as uuid } from "uuid";
4
- import { bookSizeReplaceableProductVariantsForCheckoutItem } from "../../../domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem";
5
-
6
- interface UseBookSizeReplaceableProductVariantsForCheckoutItem {
7
- readonly book: () => Promise<void>;
8
- readonly status: CommandStatus;
9
- }
10
-
11
- interface UseBookSizeReplaceableProductVariantsForCheckoutItemFunctionArgs {
12
- readonly checkoutId: string;
13
- readonly checkoutItemId: string;
14
- readonly checkoutBookingId: string;
15
- }
16
-
17
- interface UseBookSizeReplaceableProductVariantsForCheckoutItemFunction {
18
- (
19
- args: UseBookSizeReplaceableProductVariantsForCheckoutItemFunctionArgs,
20
- ): UseBookSizeReplaceableProductVariantsForCheckoutItem;
21
- }
22
-
23
- export const useBookSizeReplaceableProductVariantsForCheckoutItem: UseBookSizeReplaceableProductVariantsForCheckoutItemFunction =
24
- ({ checkoutId, checkoutItemId, checkoutBookingId }) => {
25
- const [commandBus, status] = useCommand();
26
-
27
- const book = useCallback(
28
- async () =>
29
- await commandBus(
30
- bookSizeReplaceableProductVariantsForCheckoutItem({
31
- aggregateId: uuid(),
32
- checkoutId,
33
- checkoutItemId,
34
- checkoutBookingId,
35
- }),
36
- ),
37
- [checkoutBookingId, checkoutId, checkoutItemId, commandBus],
38
- );
39
-
40
- return {
41
- book,
42
- status,
43
- };
44
- };
@@ -1,31 +0,0 @@
1
- import { bootstrap, CommandStatus } from "@lookiero/messaging-react";
2
- import { act, renderHook } from "@testing-library/react-hooks";
3
- import { UPDATE_UI_SETTING } from "../../../domain/uiSetting/command/updateUiSetting";
4
- import { updateUiSettingHandler } from "../../../domain/uiSetting/model/uiSetting";
5
- import { useUpdateUiSetting as sut } from "./useUpdateUiSetting";
6
-
7
- const uiSettingKey = "ui_setting_key";
8
- const uiSettingValue = "ui_setting_value";
9
-
10
- const saveMock = jest.fn();
11
- const { Component: Messaging } = bootstrap()
12
- .command(UPDATE_UI_SETTING, updateUiSettingHandler, {
13
- get: jest.fn(),
14
- save: saveMock,
15
- })
16
- .build();
17
-
18
- describe("useUpdateUiSetting integration hook", () => {
19
- it("returns success as the status right after calling 'update'", async () => {
20
- saveMock.mockResolvedValue("success");
21
- const { result, waitFor } = renderHook(() => sut(), { wrapper: Messaging });
22
-
23
- expect(result.current.status).toBe(CommandStatus.IDLE);
24
-
25
- await act(() => result.current.update({ key: uiSettingKey, value: uiSettingValue }));
26
-
27
- await waitFor(() => {
28
- expect(result.current.status).toBe(CommandStatus.SUCCESS);
29
- });
30
- });
31
- });
@@ -1,43 +0,0 @@
1
- import { CommandStatus, useCommand } from "@lookiero/messaging-react";
2
- import { useCallback } from "react";
3
- import { v4 as uuid } from "uuid";
4
- import { updateUiSetting } from "../../../domain/uiSetting/command/updateUiSetting";
5
-
6
- interface UpdateFunctionArgs {
7
- readonly key: string;
8
- readonly value: unknown;
9
- }
10
-
11
- interface UpdateFunction {
12
- (args: UpdateFunctionArgs): Promise<void>;
13
- }
14
-
15
- interface UseUpdateUiSetting {
16
- readonly update: UpdateFunction;
17
- readonly status: CommandStatus;
18
- }
19
-
20
- interface UseUpdateUiSettingFunction {
21
- (): UseUpdateUiSetting;
22
- }
23
-
24
- export const useUpdateUiSetting: UseUpdateUiSettingFunction = () => {
25
- const [commandBus, status] = useCommand();
26
-
27
- const update: UpdateFunction = useCallback(
28
- async ({ key, value }) =>
29
- await commandBus(
30
- updateUiSetting({
31
- aggregateId: uuid(),
32
- key,
33
- value,
34
- }),
35
- ),
36
- [commandBus],
37
- );
38
-
39
- return {
40
- update,
41
- status,
42
- };
43
- };
@@ -1,50 +0,0 @@
1
- import { v4 as uuid } from "uuid";
2
- import { getUiSetting as getSut, saveUiSetting as saveSut } from "./storageUiSettings";
3
-
4
- const readMock = jest.fn();
5
- const writeMock = jest.fn();
6
-
7
- describe("storageUiSettings", () => {
8
- it("gets uiSetting based on the given ui setting key", async () => {
9
- const aggregateId = uuid();
10
- const uiSettingKey = "ui_setting_key";
11
- const uiSettingValue = "ui_setting_value";
12
-
13
- readMock.mockReturnValue({
14
- id: aggregateId,
15
- key: uiSettingKey,
16
- value: uiSettingValue,
17
- });
18
-
19
- const getResponse = await getSut({ read: readMock })(uiSettingKey);
20
-
21
- expect(getResponse).toEqual({ aggregateId, key: uiSettingKey, value: uiSettingValue, domainEvents: [] });
22
- });
23
-
24
- it("throws an Error when uiSetting based on the given ui setting key does not exist", async () => {
25
- const uiSettingKey = "ui_setting_key";
26
-
27
- readMock.mockReturnValue(undefined);
28
-
29
- await expect(getSut({ read: readMock })(uiSettingKey)).rejects.toThrow();
30
- });
31
-
32
- it("saves the given uiSetting", async () => {
33
- const aggregateId = uuid();
34
- const uiSettingKey = "ui_setting_key";
35
- const uiSettingValue = "ui_setting_value";
36
-
37
- const uiSettingDto = { aggregateId, key: uiSettingKey, value: uiSettingValue };
38
- const uiSetting = { ...uiSettingDto, domainEvents: [] };
39
-
40
- writeMock.mockResolvedValue("success");
41
-
42
- await saveSut({ write: writeMock })(uiSetting);
43
-
44
- expect(writeMock).toHaveBeenCalledWith(uiSettingKey, {
45
- id: aggregateId,
46
- key: uiSettingKey,
47
- value: uiSettingValue,
48
- });
49
- });
50
- });
@@ -1,50 +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
- export 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
- export const saveUiSetting: StorageUiSettingsSaveFunction =
48
- ({ write }) =>
49
- async (aggregateRoot) =>
50
- await write(aggregateRoot.key, fromDomain(aggregateRoot));
@@ -1,12 +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
- export const read: ReadFunction<UiSettingDto> = async (key) => {
6
- const value = await AsyncStorage.getItem(key);
7
-
8
- return value ? JSON.parse(value) : undefined;
9
- };
10
-
11
- export const write: WriteFunction<UiSettingDto> = async (key, value) =>
12
- AsyncStorage.setItem(key, JSON.stringify(value));
@@ -1,7 +0,0 @@
1
- export interface ReadFunction<T> {
2
- (key: string): Promise<T | undefined>;
3
- }
4
-
5
- export interface WriteFunction<T> {
6
- (key: string, value: T): Promise<void>;
7
- }
@@ -1,5 +0,0 @@
1
- export interface UiSettingDto {
2
- readonly id: string;
3
- readonly key: string;
4
- readonly value: unknown;
5
- }
@@ -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
- };