@lookiero/checkout 0.1.1 → 0.1.2
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/dist/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.d.ts +4 -4
- package/dist/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.js +3 -2
- package/dist/domain/checkoutBooking/model/checkoutBooking.d.ts +3 -2
- package/dist/domain/checkoutBooking/model/checkoutBooking.js +2 -1
- package/dist/domain/checkoutBooking/model/checkoutBookingBooked.d.ts +4 -4
- package/dist/domain/checkoutBooking/model/checkoutBookingBooked.js +3 -2
- package/dist/domain/checkoutBooking/model/checkoutBookings.d.ts +3 -2
- package/dist/domain/uiSetting/command/updateUiSetting.d.ts +4 -4
- package/dist/domain/uiSetting/command/updateUiSetting.js +3 -2
- package/dist/domain/uiSetting/model/uiSetting.d.ts +3 -2
- package/dist/domain/uiSetting/model/uiSetting.js +2 -1
- package/dist/domain/uiSetting/model/uiSettingUpdated.d.ts +4 -4
- package/dist/domain/uiSetting/model/uiSettingUpdated.js +3 -2
- package/dist/domain/uiSetting/model/uiSettings.d.ts +3 -2
- package/dist/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.d.ts +2 -2
- package/dist/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.js +2 -1
- package/dist/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.d.ts +2 -2
- package/dist/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.js +2 -1
- package/dist/infrastructure/domain/react/useSetCheckoutIntroShown.d.ts +13 -0
- package/dist/infrastructure/domain/react/useSetCheckoutIntroShown.js +9 -0
- package/dist/infrastructure/domain/react/useUpdateUiSetting.d.ts +2 -2
- package/dist/infrastructure/domain/react/useUpdateUiSetting.js +2 -1
- package/dist/infrastructure/domain/uiSetting/model/storageUiSettings.d.ts +3 -3
- package/dist/infrastructure/domain/uiSetting/model/storageUiSettings.js +3 -2
- package/dist/infrastructure/persistence/asyncStorageStorage.d.ts +3 -2
- package/dist/infrastructure/persistence/asyncStorageStorage.js +3 -2
- package/dist/infrastructure/persistence/storage.d.ts +3 -2
- package/dist/infrastructure/persistence/uiSettingData.d.ts +2 -1
- package/dist/infrastructure/projection/react/useViewCheckoutIntroShown.d.ts +2 -0
- package/dist/infrastructure/projection/react/useViewCheckoutIntroShown.js +6 -0
- package/dist/infrastructure/projection/react/useViewUiSettingByKey.d.ts +3 -3
- package/dist/infrastructure/projection/react/useViewUiSettingByKey.js +6 -4
- package/dist/infrastructure/projection/storageUiSettingByKeyView.d.ts +2 -2
- package/dist/infrastructure/projection/storageUiSettingByKeyView.js +2 -1
- package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +4 -4
- package/dist/infrastructure/ui/settings/UISettings.d.ts +4 -0
- package/dist/infrastructure/ui/settings/UISettings.js +5 -0
- package/dist/projection/uiSetting/viewUiSettingByKey.d.ts +6 -6
- package/dist/projection/uiSetting/viewUiSettingByKey.js +4 -3
- package/package.json +1 -1
- package/src/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.ts +15 -7
- package/src/domain/checkoutBooking/model/checkoutBooking.ts +4 -2
- package/src/domain/checkoutBooking/model/checkoutBookingBooked.ts +5 -5
- package/src/domain/checkoutBooking/model/checkoutBookings.ts +4 -2
- package/src/domain/uiSetting/command/updateUiSetting.ts +5 -3
- package/src/domain/uiSetting/model/uiSetting.ts +4 -2
- package/src/domain/uiSetting/model/uiSettingUpdated.ts +5 -3
- package/src/domain/uiSetting/model/uiSettings.ts +4 -2
- package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.ts +3 -1
- package/src/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.ts +3 -1
- package/src/infrastructure/domain/react/useSetCheckoutIntroShown.test.ts +34 -0
- package/src/infrastructure/domain/react/useSetCheckoutIntroShown.ts +30 -0
- package/src/infrastructure/domain/react/useUpdateUiSetting.ts +3 -1
- package/src/infrastructure/domain/uiSetting/model/storageUiSettings.ts +4 -2
- package/src/infrastructure/persistence/asyncStorageStorage.ts +4 -3
- package/src/infrastructure/persistence/storage.ts +4 -2
- package/src/infrastructure/persistence/uiSettingData.ts +3 -1
- package/src/infrastructure/projection/react/useViewCheckoutIntroShown.test.ts +41 -0
- package/src/infrastructure/projection/react/useViewCheckoutIntroShown.ts +9 -0
- package/src/infrastructure/projection/react/useViewUiSettingByKey.test.ts +1 -1
- package/src/infrastructure/projection/react/useViewUiSettingByKey.ts +11 -5
- package/src/infrastructure/projection/storageUiSettingByKeyView.ts +3 -1
- package/src/infrastructure/ui/routing/CheckoutMiddleware.test.tsx +7 -7
- package/src/infrastructure/ui/routing/CheckoutMiddleware.tsx +4 -4
- package/src/infrastructure/ui/settings/UISettings.ts +5 -0
- package/src/projection/uiSetting/viewUiSettingByKey.ts +17 -9
- package/dist/infrastructure/projection/react/useViewIsCheckoutIntroVisible.d.ts +0 -3
- package/dist/infrastructure/projection/react/useViewIsCheckoutIntroVisible.js +0 -3
- package/src/infrastructure/projection/react/useViewIsCheckoutIntroVisible.ts +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { domainEvent, DomainEvent } from "@lookiero/messaging";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const CHECKOUT_BOOKING_BOOKED = "checkout_booking_booked";
|
|
4
4
|
|
|
5
5
|
interface CheckoutBookingBookedPayload {
|
|
6
6
|
readonly aggregateId: string;
|
|
@@ -9,15 +9,15 @@ interface CheckoutBookingBookedPayload {
|
|
|
9
9
|
readonly checkoutBookingId: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
extends DomainEvent<typeof CHECKOUT_BOOKING_BOOKED>,
|
|
14
|
-
CheckoutBookingBookedPayload {}
|
|
12
|
+
interface CheckoutBookingBooked extends DomainEvent<typeof CHECKOUT_BOOKING_BOOKED>, CheckoutBookingBookedPayload {}
|
|
15
13
|
|
|
16
14
|
interface CheckoutBookingBookedFunction {
|
|
17
15
|
(payload: CheckoutBookingBookedPayload): CheckoutBookingBooked;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
const checkoutBookingBooked: CheckoutBookingBookedFunction = ({ aggregateId, ...payload }) => ({
|
|
21
19
|
...domainEvent({ aggregateId, name: CHECKOUT_BOOKING_BOOKED }),
|
|
22
20
|
...payload,
|
|
23
21
|
});
|
|
22
|
+
|
|
23
|
+
export { CHECKOUT_BOOKING_BOOKED, CheckoutBookingBooked, checkoutBookingBooked };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { RepositoryGetFunction, RepositorySaveFunction } from "@lookiero/messaging";
|
|
2
2
|
import { CheckoutBooking } from "./checkoutBooking";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface CheckoutBookingsGetFunction extends RepositoryGetFunction<CheckoutBooking> {}
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface CheckoutBookingsSaveFunction extends RepositorySaveFunction<CheckoutBooking> {}
|
|
7
|
+
|
|
8
|
+
export { CheckoutBookingsGetFunction, CheckoutBookingsSaveFunction };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { command, Command } from "@lookiero/messaging";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const UPDATE_UI_SETTING = "update_ui_setting";
|
|
4
4
|
|
|
5
5
|
interface UpdateUiSettingPayload {
|
|
6
6
|
readonly aggregateId: string;
|
|
@@ -8,16 +8,18 @@ interface UpdateUiSettingPayload {
|
|
|
8
8
|
readonly value: unknown;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
interface UpdateUiSetting extends Command<typeof UPDATE_UI_SETTING>, UpdateUiSettingPayload {}
|
|
12
12
|
|
|
13
13
|
interface UpdateUiSettingFunction {
|
|
14
14
|
(payload: UpdateUiSettingPayload): UpdateUiSetting;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const updateUiSetting: UpdateUiSettingFunction = ({ aggregateId, ...payload }) => ({
|
|
18
18
|
...command({
|
|
19
19
|
aggregateId,
|
|
20
20
|
name: UPDATE_UI_SETTING,
|
|
21
21
|
}),
|
|
22
22
|
...payload,
|
|
23
23
|
});
|
|
24
|
+
|
|
25
|
+
export { UPDATE_UI_SETTING, UpdateUiSetting, updateUiSetting };
|
|
@@ -3,12 +3,12 @@ import { CommandHandlerFunction } from "@lookiero/messaging/domain/model";
|
|
|
3
3
|
import { UpdateUiSetting } from "../command/updateUiSetting";
|
|
4
4
|
import { uiSettingUpdated } from "./uiSettingUpdated";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface UiSetting extends AggregateRoot {
|
|
7
7
|
readonly key: string;
|
|
8
8
|
readonly value: unknown;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const updateUiSettingHandler: CommandHandlerFunction<UpdateUiSetting, UiSetting> =
|
|
12
12
|
() =>
|
|
13
13
|
async ({ aggregateRoot, command }) => {
|
|
14
14
|
const { aggregateId, key, value } = command;
|
|
@@ -20,3 +20,5 @@ export const updateUiSettingHandler: CommandHandlerFunction<UpdateUiSetting, UiS
|
|
|
20
20
|
domainEvents: uiSettingUpdated({ aggregateId, key }),
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
+
|
|
24
|
+
export { UiSetting, updateUiSettingHandler };
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { domainEvent, DomainEvent } from "@lookiero/messaging";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const UI_SETTING_UPDATED = "ui_setting_updated";
|
|
4
4
|
|
|
5
5
|
interface UiSettingUpdatedPayload {
|
|
6
6
|
readonly aggregateId: string;
|
|
7
7
|
readonly key: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface UiSettingUpdated extends DomainEvent<typeof UI_SETTING_UPDATED>, UiSettingUpdatedPayload {}
|
|
11
11
|
|
|
12
12
|
interface UiSettingUpdatedFunction {
|
|
13
13
|
(payload: UiSettingUpdatedPayload): UiSettingUpdated;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const uiSettingUpdated: UiSettingUpdatedFunction = ({ aggregateId, key }) => ({
|
|
17
17
|
...domainEvent({ aggregateId, name: UI_SETTING_UPDATED }),
|
|
18
18
|
key,
|
|
19
19
|
});
|
|
20
|
+
|
|
21
|
+
export { UI_SETTING_UPDATED, UiSettingUpdated, uiSettingUpdated };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { RepositoryGetFunction, RepositorySaveFunction } from "@lookiero/messaging";
|
|
2
2
|
import { UiSetting } from "./uiSetting";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface UiSettingGetFunction extends RepositoryGetFunction<UiSetting> {}
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface UiSettingSaveFunction extends RepositorySaveFunction<UiSetting> {}
|
|
7
|
+
|
|
8
|
+
export { UiSettingGetFunction, UiSettingSaveFunction };
|
|
@@ -9,7 +9,7 @@ interface HttpCheckoutBookingsSaveFunction {
|
|
|
9
9
|
(args: HttpCheckoutBookingsSaveFunctionArgs): CheckoutBookingsSaveFunction;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const saveCheckoutBooking: HttpCheckoutBookingsSaveFunction =
|
|
13
13
|
({ httpPost }) =>
|
|
14
14
|
async ({ checkoutId, checkoutItemId, checkoutBookingId }) => {
|
|
15
15
|
try {
|
|
@@ -30,3 +30,5 @@ export const saveCheckoutBooking: HttpCheckoutBookingsSaveFunction =
|
|
|
30
30
|
throw new Error("Could not fetch BookSizeReplaceableProductVariantsForCheckoutItem");
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
+
|
|
34
|
+
export { saveCheckoutBooking };
|
package/src/infrastructure/domain/react/useBookSizeReplaceableProductVariantsForCheckoutItem.ts
CHANGED
|
@@ -20,7 +20,7 @@ interface UseBookSizeReplaceableProductVariantsForCheckoutItemFunction {
|
|
|
20
20
|
): UseBookSizeReplaceableProductVariantsForCheckoutItem;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const useBookSizeReplaceableProductVariantsForCheckoutItem: UseBookSizeReplaceableProductVariantsForCheckoutItemFunction =
|
|
24
24
|
({ checkoutId, checkoutItemId, checkoutBookingId }) => {
|
|
25
25
|
const [commandBus, status] = useCommand();
|
|
26
26
|
|
|
@@ -42,3 +42,5 @@ export const useBookSizeReplaceableProductVariantsForCheckoutItem: UseBookSizeRe
|
|
|
42
42
|
status,
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
export { useBookSizeReplaceableProductVariantsForCheckoutItem };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CommandStatus } from "@lookiero/messaging-react";
|
|
2
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
3
|
+
import { useSetCheckoutIntroShown as sut } from "./useSetCheckoutIntroShown";
|
|
4
|
+
import { useUpdateUiSetting } from "./useUpdateUiSetting";
|
|
5
|
+
|
|
6
|
+
jest.mock("./useUpdateUiSetting");
|
|
7
|
+
|
|
8
|
+
describe("useSetCheckoutIntroShown integration hook", () => {
|
|
9
|
+
it("returns success after rendering the hook", async () => {
|
|
10
|
+
(useUpdateUiSetting as jest.Mock).mockReturnValue({
|
|
11
|
+
update: jest.fn(),
|
|
12
|
+
status: CommandStatus.SUCCESS,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const { result } = renderHook(() => sut());
|
|
16
|
+
|
|
17
|
+
result.current.setCheckoutIntroShown();
|
|
18
|
+
|
|
19
|
+
expect(result.current.status).toBe(CommandStatus.SUCCESS);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("returns error after rendering the hook", async () => {
|
|
23
|
+
(useUpdateUiSetting as jest.Mock).mockReturnValue({
|
|
24
|
+
update: jest.fn(),
|
|
25
|
+
status: CommandStatus.ERROR,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const { result } = renderHook(() => sut());
|
|
29
|
+
|
|
30
|
+
result.current.setCheckoutIntroShown();
|
|
31
|
+
|
|
32
|
+
expect(result.current.status).toBe(CommandStatus.ERROR);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CommandStatus } from "@lookiero/messaging-react";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { UISettings } from "../../ui/settings/UISettings";
|
|
4
|
+
import { useUpdateUiSetting } from "./useUpdateUiSetting";
|
|
5
|
+
|
|
6
|
+
interface SetCheckoutIntroShownFunction {
|
|
7
|
+
(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface UseSetCheckoutIntroShown {
|
|
11
|
+
readonly setCheckoutIntroShown: SetCheckoutIntroShownFunction;
|
|
12
|
+
readonly status: CommandStatus;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface UseSetCheckoutIntroShownFunction {
|
|
16
|
+
(): UseSetCheckoutIntroShown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const useSetCheckoutIntroShown: UseSetCheckoutIntroShownFunction = () => {
|
|
20
|
+
const { update, status } = useUpdateUiSetting();
|
|
21
|
+
|
|
22
|
+
const setCheckoutIntroShown = useCallback(
|
|
23
|
+
() => update({ key: UISettings.CHECKOUT_INTRO_SHOWN, value: true }),
|
|
24
|
+
[update],
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return { setCheckoutIntroShown, status };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { useSetCheckoutIntroShown };
|
|
@@ -21,7 +21,7 @@ interface UseUpdateUiSettingFunction {
|
|
|
21
21
|
(): UseUpdateUiSetting;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const useUpdateUiSetting: UseUpdateUiSettingFunction = () => {
|
|
25
25
|
const [commandBus, status] = useCommand();
|
|
26
26
|
|
|
27
27
|
const update: UpdateFunction = useCallback(
|
|
@@ -41,3 +41,5 @@ export const useUpdateUiSetting: UseUpdateUiSettingFunction = () => {
|
|
|
41
41
|
status,
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
+
|
|
45
|
+
export { useUpdateUiSetting };
|
|
@@ -24,7 +24,7 @@ interface StorageUiSettingsGetFunction {
|
|
|
24
24
|
(args: StorageUiSettingsGetFunctionArgs): UiSettingGetFunction;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const getUiSetting: StorageUiSettingsGetFunction =
|
|
28
28
|
({ read }) =>
|
|
29
29
|
async (uiSettingKey) => {
|
|
30
30
|
const uiSettingDto = await read(uiSettingKey);
|
|
@@ -44,7 +44,9 @@ interface StorageUiSettingsSaveFunction {
|
|
|
44
44
|
(args: StorageUiSettingsSaveFunctionArgs): UiSettingSaveFunction;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const saveUiSetting: StorageUiSettingsSaveFunction =
|
|
48
48
|
({ write }) =>
|
|
49
49
|
async (aggregateRoot) =>
|
|
50
50
|
await write(aggregateRoot.key, fromDomain(aggregateRoot));
|
|
51
|
+
|
|
52
|
+
export { getUiSetting, saveUiSetting };
|
|
@@ -2,11 +2,12 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
|
2
2
|
import { ReadFunction, WriteFunction } from "./storage";
|
|
3
3
|
import { UiSettingDto } from "./uiSettingData";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const read: ReadFunction<UiSettingDto> = async (key) => {
|
|
6
6
|
const value = await AsyncStorage.getItem(key);
|
|
7
7
|
|
|
8
8
|
return value ? JSON.parse(value) : undefined;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const write: WriteFunction<UiSettingDto> = async (key, value) => AsyncStorage.setItem(key, JSON.stringify(value));
|
|
12
|
+
|
|
13
|
+
export { read, write };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
interface ReadFunction<T> {
|
|
2
2
|
(key: string): Promise<T | undefined>;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface WriteFunction<T> {
|
|
6
6
|
(key: string, value: T): Promise<void>;
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
export { ReadFunction, WriteFunction };
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
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 };
|
|
@@ -18,7 +18,7 @@ const { Component: Messaging } = bootstrap().query(VIEW_UI_SETTING_BY_KEY, viewU
|
|
|
18
18
|
|
|
19
19
|
describe("useViewUiSettingByKey integration hook", () => {
|
|
20
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 });
|
|
21
|
+
const { result, waitFor } = renderHook(() => sut({ key: uiSettingKey }), { wrapper: Messaging });
|
|
22
22
|
|
|
23
23
|
await waitFor(() => {
|
|
24
24
|
const [projection, status] = result.current;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
+
import { DomainEvent, MessageName } from "@lookiero/messaging";
|
|
1
2
|
import { useQuery, UseQueryFunctionResult } from "@lookiero/messaging-react";
|
|
2
|
-
import {
|
|
3
|
+
import { UiSettingUpdated, UI_SETTING_UPDATED } from "../../../domain/uiSetting/model/uiSettingUpdated";
|
|
3
4
|
import { UiSettingProjection, viewUiSettingByKey } from "../../../projection/uiSetting/viewUiSettingByKey";
|
|
4
5
|
|
|
5
6
|
interface UseViewUiSettingByKeyFunctionArgs {
|
|
6
|
-
readonly
|
|
7
|
+
readonly key: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
interface UseViewUiSettingByKeyFunction {
|
|
10
11
|
(args: UseViewUiSettingByKeyFunctionArgs): UseQueryFunctionResult<UiSettingProjection>;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
const isUiSettingUpdated = (event: DomainEvent<MessageName>): event is UiSettingUpdated =>
|
|
15
|
+
event.name === UI_SETTING_UPDATED;
|
|
16
|
+
|
|
17
|
+
const useViewUiSettingByKey: UseViewUiSettingByKeyFunction = ({ key }) =>
|
|
14
18
|
useQuery({
|
|
15
|
-
query: viewUiSettingByKey({ key
|
|
16
|
-
invalidation:
|
|
19
|
+
query: viewUiSettingByKey({ key }),
|
|
20
|
+
invalidation: isUiSettingUpdated,
|
|
17
21
|
options: { staleTime: Infinity },
|
|
18
22
|
});
|
|
23
|
+
|
|
24
|
+
export { useViewUiSettingByKey };
|
|
@@ -22,7 +22,7 @@ interface StorageUiSettingByKeyViewFunction {
|
|
|
22
22
|
(args: StorageUiSettingByKeyViewFunctionArgs): StorageUiSettingByKeyView;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const storageUiSettingByKeyView: StorageUiSettingByKeyViewFunction =
|
|
26
26
|
({ read }) =>
|
|
27
27
|
async ({ key }) => {
|
|
28
28
|
try {
|
|
@@ -33,3 +33,5 @@ export const storageUiSettingByKeyView: StorageUiSettingByKeyViewFunction =
|
|
|
33
33
|
throw new Error("Could not fetch the uiSetting");
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
+
|
|
37
|
+
export { storageUiSettingByKeyView };
|
|
@@ -5,13 +5,13 @@ import { v4 as uuid } from "uuid";
|
|
|
5
5
|
import { CheckoutItemStatus } from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
6
6
|
import { startedCheckoutWithItems } from "../../delivery/_mock/checkout.mock";
|
|
7
7
|
import { useViewFirstAvailableCheckoutByCustomerId } from "../../projection/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
8
|
-
import {
|
|
8
|
+
import { useViewCheckoutIntroShown } from "../../projection/react/useViewCheckoutIntroShown";
|
|
9
9
|
import { CheckoutMiddleware } from "./CheckoutMiddleware";
|
|
10
10
|
|
|
11
11
|
import { Routes as CheckoutRoutes } from "./routes";
|
|
12
12
|
|
|
13
|
-
jest.mock("../../projection/react/
|
|
14
|
-
|
|
13
|
+
jest.mock("../../projection/react/useViewCheckoutIntroShown", () => ({
|
|
14
|
+
useViewCheckoutIntroShown: jest.fn(),
|
|
15
15
|
}));
|
|
16
16
|
jest.mock("../../projection/react/useViewFirstAvailableCheckoutByCustomerId", () => ({
|
|
17
17
|
useViewFirstAvailableCheckoutByCustomerId: jest.fn(),
|
|
@@ -56,7 +56,7 @@ const routes: string[] = [
|
|
|
56
56
|
|
|
57
57
|
describe("CheckoutMiddleware component", () => {
|
|
58
58
|
test.each(routes)("renders a loader while processing dependant use-cases in route: %s", async (route) => {
|
|
59
|
-
(
|
|
59
|
+
(useViewCheckoutIntroShown as jest.Mock).mockReturnValue([undefined, "loading"]);
|
|
60
60
|
(useViewFirstAvailableCheckoutByCustomerId as jest.Mock).mockReturnValue([undefined, "loading"]);
|
|
61
61
|
|
|
62
62
|
const { findByText } = renderCheckoutMiddleware({ route });
|
|
@@ -67,7 +67,7 @@ describe("CheckoutMiddleware component", () => {
|
|
|
67
67
|
|
|
68
68
|
test.each(routes)("renders the intro view if it should be visible with initial route: %s", async (route) => {
|
|
69
69
|
const checkoutMock = startedCheckoutWithItems({ status: [CheckoutItemStatus.INITIAL, CheckoutItemStatus.INITIAL] });
|
|
70
|
-
(
|
|
70
|
+
(useViewCheckoutIntroShown as jest.Mock).mockReturnValue([true, "success"]);
|
|
71
71
|
(useViewFirstAvailableCheckoutByCustomerId as jest.Mock).mockReturnValue([checkoutMock, "success"]);
|
|
72
72
|
|
|
73
73
|
const { findByText } = renderCheckoutMiddleware({ route });
|
|
@@ -78,7 +78,7 @@ describe("CheckoutMiddleware component", () => {
|
|
|
78
78
|
|
|
79
79
|
test.each(routes)("renders the item view if it should be visible with initial route: %s", async (route) => {
|
|
80
80
|
const checkoutMock = startedCheckoutWithItems({ status: [CheckoutItemStatus.KEPT, CheckoutItemStatus.INITIAL] });
|
|
81
|
-
(
|
|
81
|
+
(useViewCheckoutIntroShown as jest.Mock).mockReturnValue([false, "success"]);
|
|
82
82
|
(useViewFirstAvailableCheckoutByCustomerId as jest.Mock).mockReturnValue([checkoutMock, "success"]);
|
|
83
83
|
|
|
84
84
|
const { findByText } = renderCheckoutMiddleware({ route });
|
|
@@ -89,7 +89,7 @@ describe("CheckoutMiddleware component", () => {
|
|
|
89
89
|
|
|
90
90
|
test.each(routes)("renders the summary view if it should be visible with initial route: %s", async (route) => {
|
|
91
91
|
const checkoutMock = startedCheckoutWithItems({ status: [CheckoutItemStatus.KEPT, CheckoutItemStatus.RETURNED] });
|
|
92
|
-
(
|
|
92
|
+
(useViewCheckoutIntroShown as jest.Mock).mockReturnValue([false, "success"]);
|
|
93
93
|
(useViewFirstAvailableCheckoutByCustomerId as jest.Mock).mockReturnValue([checkoutMock, "success"]);
|
|
94
94
|
|
|
95
95
|
const { findByText } = renderCheckoutMiddleware({ route });
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
CheckoutItemStatus,
|
|
7
7
|
} from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
8
8
|
import { useViewFirstAvailableCheckoutByCustomerId } from "../../projection/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
9
|
-
import {
|
|
9
|
+
import { useViewCheckoutIntroShown } from "../../projection/react/useViewCheckoutIntroShown";
|
|
10
10
|
import { Spinner } from "../components/atoms/spiner/Spinner";
|
|
11
11
|
import { Routes } from "./routes";
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@ interface CheckoutMiddlewareProps {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const CheckoutMiddleware: FC<CheckoutMiddlewareProps> = ({ customerId, loader = <Spinner /> }) => {
|
|
19
|
-
const [
|
|
19
|
+
const [checkoutIntroShown, checkoutIntroShownStatus] = useViewCheckoutIntroShown();
|
|
20
20
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
21
21
|
const firstItemWithoutCustomerDecision: CheckoutItemProjection | undefined = checkout?.items.find((item) =>
|
|
22
22
|
[CheckoutItemStatus.EXPIRED, CheckoutItemStatus.INITIAL].includes(item.status),
|
|
@@ -26,13 +26,13 @@ const CheckoutMiddleware: FC<CheckoutMiddlewareProps> = ({ customerId, loader =
|
|
|
26
26
|
const isItemRoute = useMatch(Routes.ITEM);
|
|
27
27
|
const isSummaryRoute = useMatch(Routes.SUMMARY);
|
|
28
28
|
|
|
29
|
-
const dependenciesLoaded =
|
|
29
|
+
const dependenciesLoaded = checkoutIntroShownStatus === QueryStatus.SUCCESS && checkoutStatus === QueryStatus.SUCCESS;
|
|
30
30
|
|
|
31
31
|
if (!dependenciesLoaded) {
|
|
32
32
|
return loader;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
if (
|
|
35
|
+
if (checkoutIntroShown) {
|
|
36
36
|
if (!isIntroRoute) {
|
|
37
37
|
return <Navigate replace to={Routes.INTRO} />;
|
|
38
38
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { query, Query, QueryHandlerFunction, QueryHandlerFunctionArgs } from "@lookiero/messaging";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface UiSettingProjection {
|
|
4
4
|
readonly id: string;
|
|
5
5
|
readonly key: string;
|
|
6
6
|
readonly value: unknown;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const VIEW_UI_SETTING_BY_KEY = "view_ui_setting_by_key";
|
|
10
10
|
|
|
11
11
|
interface ViewUiSettingByKeyPayload {
|
|
12
12
|
readonly key: string;
|
|
@@ -18,13 +18,18 @@ interface ViewUiSettingByKeyFunction {
|
|
|
18
18
|
(payload: ViewUiSettingByKeyPayload): ViewUiSettingByKey;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
const viewUiSettingByKey: ViewUiSettingByKeyFunction = (payload) => ({
|
|
22
|
+
...query({ name: VIEW_UI_SETTING_BY_KEY }),
|
|
23
|
+
...payload,
|
|
24
|
+
});
|
|
25
|
+
|
|
21
26
|
type ViewUiSettingByKeyResult = UiSettingProjection | undefined;
|
|
22
27
|
|
|
23
28
|
interface UiSettingByKeyViewArgs {
|
|
24
29
|
readonly key: string;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
interface UiSettingByKeyView {
|
|
28
33
|
(args: UiSettingByKeyViewArgs): Promise<ViewUiSettingByKeyResult>;
|
|
29
34
|
}
|
|
30
35
|
|
|
@@ -32,12 +37,7 @@ interface ViewUiSettingByKeyHandlerFunctionArgs extends QueryHandlerFunctionArgs
|
|
|
32
37
|
readonly view: UiSettingByKeyView;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
...query({ name: VIEW_UI_SETTING_BY_KEY }),
|
|
37
|
-
...payload,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
export const viewUiSettingByKeyHandler: QueryHandlerFunction<
|
|
40
|
+
const viewUiSettingByKeyHandler: QueryHandlerFunction<
|
|
41
41
|
ViewUiSettingByKey,
|
|
42
42
|
ViewUiSettingByKeyResult,
|
|
43
43
|
ViewUiSettingByKeyHandlerFunctionArgs
|
|
@@ -45,3 +45,11 @@ export const viewUiSettingByKeyHandler: QueryHandlerFunction<
|
|
|
45
45
|
({ view }) =>
|
|
46
46
|
async ({ key }) =>
|
|
47
47
|
view({ key });
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
UiSettingProjection,
|
|
51
|
+
VIEW_UI_SETTING_BY_KEY,
|
|
52
|
+
UiSettingByKeyView,
|
|
53
|
+
viewUiSettingByKey,
|
|
54
|
+
viewUiSettingByKeyHandler,
|
|
55
|
+
};
|