@lookiero/checkout 12.1.2 → 12.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 (54) hide show
  1. package/dist/src/infrastructure/delivery/baseBootstrap.d.ts +2 -11
  2. package/dist/src/infrastructure/delivery/baseBootstrap.js +3 -8
  3. package/dist/src/infrastructure/delivery/bootstrap.js +0 -7
  4. package/dist/src/infrastructure/delivery/bootstrap.mock.js +0 -7
  5. package/dist/src/version.d.ts +1 -1
  6. package/dist/src/version.js +1 -1
  7. package/package.json +1 -1
  8. package/src/infrastructure/delivery/baseBootstrap.ts +3 -28
  9. package/src/infrastructure/delivery/bootstrap.mock.ts +0 -7
  10. package/src/infrastructure/delivery/bootstrap.ts +0 -7
  11. package/dist/src/domain/uiSetting/command/updateUiSetting.d.ts +0 -15
  12. package/dist/src/domain/uiSetting/command/updateUiSetting.js +0 -10
  13. package/dist/src/domain/uiSetting/model/uiSetting.d.ts +0 -9
  14. package/dist/src/domain/uiSetting/model/uiSetting.js +0 -11
  15. package/dist/src/domain/uiSetting/model/uiSettingUpdated.d.ts +0 -15
  16. package/dist/src/domain/uiSetting/model/uiSettingUpdated.js +0 -8
  17. package/dist/src/domain/uiSetting/model/uiSettings.d.ts +0 -7
  18. package/dist/src/domain/uiSetting/model/uiSettings.js +0 -1
  19. package/dist/src/infrastructure/domain/uiSetting/model/storageUiSettings.d.ts +0 -17
  20. package/dist/src/infrastructure/domain/uiSetting/model/storageUiSettings.js +0 -20
  21. package/dist/src/infrastructure/domain/uiSetting/react/useUpdateUiSetting.d.ts +0 -18
  22. package/dist/src/infrastructure/domain/uiSetting/react/useUpdateUiSetting.js +0 -22
  23. package/dist/src/infrastructure/persistence/asyncStorageStorage.d.ts +0 -5
  24. package/dist/src/infrastructure/persistence/asyncStorageStorage.js +0 -7
  25. package/dist/src/infrastructure/persistence/uiSettingData.d.ts +0 -6
  26. package/dist/src/infrastructure/persistence/uiSettingData.js +0 -1
  27. package/dist/src/infrastructure/projection/uiSetting/react/useViewUiSettingByKey.d.ts +0 -10
  28. package/dist/src/infrastructure/projection/uiSetting/react/useViewUiSettingByKey.js +0 -11
  29. package/dist/src/infrastructure/projection/uiSetting/storageUiSettingByKeyView.d.ts +0 -13
  30. package/dist/src/infrastructure/projection/uiSetting/storageUiSettingByKeyView.js +0 -15
  31. package/dist/src/infrastructure/ui/settings/UISettings.d.ts +0 -3
  32. package/dist/src/infrastructure/ui/settings/UISettings.js +0 -4
  33. package/dist/src/projection/uiSetting/viewUiSettingByKey.d.ts +0 -29
  34. package/dist/src/projection/uiSetting/viewUiSettingByKey.js +0 -8
  35. package/src/domain/uiSetting/command/updateUiSetting.test.ts +0 -18
  36. package/src/domain/uiSetting/command/updateUiSetting.ts +0 -26
  37. package/src/domain/uiSetting/model/uiSetting.test.ts +0 -25
  38. package/src/domain/uiSetting/model/uiSetting.ts +0 -24
  39. package/src/domain/uiSetting/model/uiSettingUpdated.test.ts +0 -16
  40. package/src/domain/uiSetting/model/uiSettingUpdated.ts +0 -25
  41. package/src/domain/uiSetting/model/uiSettings.ts +0 -15
  42. package/src/infrastructure/domain/uiSetting/model/storageUiSettings.test.ts +0 -50
  43. package/src/infrastructure/domain/uiSetting/model/storageUiSettings.ts +0 -49
  44. package/src/infrastructure/domain/uiSetting/react/useUpdateUiSetting.test.ts +0 -62
  45. package/src/infrastructure/domain/uiSetting/react/useUpdateUiSetting.ts +0 -50
  46. package/src/infrastructure/persistence/asyncStorageStorage.ts +0 -13
  47. package/src/infrastructure/persistence/uiSettingData.ts +0 -7
  48. package/src/infrastructure/projection/uiSetting/react/useViewUiSettingByKey.test.ts +0 -33
  49. package/src/infrastructure/projection/uiSetting/react/useViewUiSettingByKey.ts +0 -22
  50. package/src/infrastructure/projection/uiSetting/storageUiSettingByKeyView.test.ts +0 -36
  51. package/src/infrastructure/projection/uiSetting/storageUiSettingByKeyView.ts +0 -37
  52. package/src/infrastructure/ui/settings/UISettings.ts +0 -3
  53. package/src/projection/uiSetting/viewUiSettingByKey.test.ts +0 -23
  54. package/src/projection/uiSetting/viewUiSettingByKey.ts +0 -50
@@ -1,29 +0,0 @@
1
- import { Query, QueryHandlerFunction, QueryHandlerFunctionArgs } from "@lookiero/messaging";
2
- interface UiSettingProjection {
3
- readonly id: string;
4
- readonly key: string;
5
- readonly value: unknown;
6
- }
7
- declare const VIEW_UI_SETTING_BY_KEY = "view_ui_setting_by_key";
8
- interface ViewUiSettingByKeyPayload {
9
- readonly key: string;
10
- }
11
- interface ViewUiSettingByKey extends Query<typeof VIEW_UI_SETTING_BY_KEY>, ViewUiSettingByKeyPayload {
12
- }
13
- interface ViewUiSettingByKeyFunction {
14
- (payload: ViewUiSettingByKeyPayload): ViewUiSettingByKey;
15
- }
16
- declare const viewUiSettingByKey: ViewUiSettingByKeyFunction;
17
- type ViewUiSettingByKeyResult = UiSettingProjection | null;
18
- interface UiSettingByKeyViewArgs {
19
- readonly key: string;
20
- }
21
- interface UiSettingByKeyView {
22
- (args: UiSettingByKeyViewArgs): Promise<ViewUiSettingByKeyResult>;
23
- }
24
- interface ViewUiSettingByKeyHandlerFunctionArgs extends QueryHandlerFunctionArgs {
25
- readonly view: UiSettingByKeyView;
26
- }
27
- declare const viewUiSettingByKeyHandler: QueryHandlerFunction<ViewUiSettingByKey, ViewUiSettingByKeyResult, ViewUiSettingByKeyHandlerFunctionArgs>;
28
- export type { UiSettingProjection, UiSettingByKeyView };
29
- export { VIEW_UI_SETTING_BY_KEY, viewUiSettingByKey, viewUiSettingByKeyHandler };
@@ -1,8 +0,0 @@
1
- import { query } from "@lookiero/messaging";
2
- const VIEW_UI_SETTING_BY_KEY = "view_ui_setting_by_key";
3
- const viewUiSettingByKey = (payload) => ({
4
- ...query({ name: VIEW_UI_SETTING_BY_KEY }),
5
- ...payload,
6
- });
7
- const viewUiSettingByKeyHandler = ({ view }) => async ({ key }) => view({ key });
8
- export { VIEW_UI_SETTING_BY_KEY, viewUiSettingByKey, viewUiSettingByKeyHandler };
@@ -1,18 +0,0 @@
1
- import { updateUiSetting as sut, UPDATE_UI_SETTING } from "./updateUiSetting";
2
-
3
- describe("updateUiSetting", () => {
4
- it("returns an UpdateUiSetting command", () => {
5
- const aggregateId = "eefb8e7c-cd89-47e0-8be2-f504aeec7f83";
6
- const key = "ui_setting_key";
7
- const value = "ui_setting_value";
8
-
9
- const command = sut({ aggregateId, key, value });
10
-
11
- expect(command.aggregateId).toBe(aggregateId);
12
- expect(command.key).toBe(key);
13
- expect(command.value).toBe(value);
14
- expect(command.name).toBe(UPDATE_UI_SETTING);
15
- expect(typeof command.messageId).toBe("string");
16
- expect(typeof command.occurredOn).toBe("number");
17
- });
18
- });
@@ -1,26 +0,0 @@
1
- import { command, Command } from "@lookiero/messaging";
2
-
3
- const UPDATE_UI_SETTING = "update_ui_setting";
4
-
5
- interface UpdateUiSettingPayload {
6
- readonly aggregateId: string;
7
- readonly key: string;
8
- readonly value: unknown;
9
- }
10
-
11
- interface UpdateUiSetting extends Command<typeof UPDATE_UI_SETTING>, UpdateUiSettingPayload {}
12
-
13
- interface UpdateUiSettingFunction {
14
- (payload: UpdateUiSettingPayload): UpdateUiSetting;
15
- }
16
-
17
- const updateUiSetting: UpdateUiSettingFunction = ({ aggregateId, ...payload }) => ({
18
- ...command({
19
- aggregateId,
20
- name: UPDATE_UI_SETTING,
21
- }),
22
- ...payload,
23
- });
24
-
25
- export type { UpdateUiSetting };
26
- export { UPDATE_UI_SETTING, updateUiSetting };
@@ -1,25 +0,0 @@
1
- import { mock } from "jest-mock-extended";
2
- import { QueryBus } from "@lookiero/messaging";
3
- import { updateUiSetting } from "../command/updateUiSetting";
4
- import { updateUiSettingHandler as sut } from "./uiSetting";
5
- import { UI_SETTING_UPDATED } from "./uiSettingUpdated";
6
-
7
- describe("uiSetting", () => {
8
- const queryBus = mock<QueryBus>();
9
-
10
- it("updateUiSetting publishing UiSettingUpdated", async () => {
11
- const aggregateId = "91445dca-d7b7-47aa-981b-d5323b493baf";
12
- const key = "ui_setting_key";
13
- const value = "ui_setting_value";
14
- const state = { aggregateId, key, value, domainEvents: [] };
15
-
16
- const command = updateUiSetting({ aggregateId, key, value });
17
-
18
- const aggregateRoot = await sut({ queryBus })({ aggregateRoot: state, command });
19
-
20
- expect(aggregateRoot.aggregateId).toBe(aggregateId);
21
- expect(aggregateRoot.key).toBe(key);
22
- expect(aggregateRoot.value).toBe(value);
23
- expect(aggregateRoot.domainEvents[0].name).toBe(UI_SETTING_UPDATED);
24
- });
25
- });
@@ -1,24 +0,0 @@
1
- import { AggregateRoot, CommandHandlerFunction } from "@lookiero/messaging";
2
- import { UpdateUiSetting } from "../command/updateUiSetting";
3
- import { uiSettingUpdated } from "./uiSettingUpdated";
4
-
5
- interface UiSetting extends AggregateRoot {
6
- readonly key: string;
7
- readonly value: unknown;
8
- }
9
-
10
- const updateUiSettingHandler: CommandHandlerFunction<UpdateUiSetting, UiSetting> =
11
- () =>
12
- async ({ aggregateRoot, command }) => {
13
- const { aggregateId, key, value } = command;
14
-
15
- return {
16
- ...aggregateRoot,
17
- key,
18
- value,
19
- domainEvents: [uiSettingUpdated({ aggregateId, key })],
20
- };
21
- };
22
-
23
- export type { UiSetting };
24
- export { updateUiSettingHandler };
@@ -1,16 +0,0 @@
1
- import { uiSettingUpdated as sut, UI_SETTING_UPDATED } from "./uiSettingUpdated";
2
-
3
- describe("uiSettingUpdated", () => {
4
- it("returns an UiSettingUpdated domain event", () => {
5
- const aggregateId = "6a38eb43-473e-4db5-b306-b56bab9d48a3";
6
- const key = "ui_setting_key";
7
-
8
- const domainEvent = sut({ aggregateId, key });
9
-
10
- expect(domainEvent.aggregateId).toBe(aggregateId);
11
- expect(domainEvent.key).toBe(key);
12
- expect(domainEvent.name).toBe(UI_SETTING_UPDATED);
13
- expect(typeof domainEvent.messageId).toBe("string");
14
- expect(typeof domainEvent.occurredOn).toBe("number");
15
- });
16
- });
@@ -1,25 +0,0 @@
1
- import { domainEvent, DomainEvent, MessageName } from "@lookiero/messaging";
2
-
3
- const UI_SETTING_UPDATED = "ui_setting_updated";
4
-
5
- interface UiSettingUpdatedPayload {
6
- readonly aggregateId: string;
7
- readonly key: string;
8
- }
9
-
10
- interface UiSettingUpdated extends DomainEvent<typeof UI_SETTING_UPDATED>, UiSettingUpdatedPayload {}
11
-
12
- interface UiSettingUpdatedFunction {
13
- (payload: UiSettingUpdatedPayload): UiSettingUpdated;
14
- }
15
-
16
- const uiSettingUpdated: UiSettingUpdatedFunction = ({ aggregateId, key }) => ({
17
- ...domainEvent({ aggregateId, name: UI_SETTING_UPDATED }),
18
- key,
19
- });
20
-
21
- const isUiSettingUpdated = (event: DomainEvent<MessageName>): event is UiSettingUpdated =>
22
- event.name === UI_SETTING_UPDATED;
23
-
24
- export type { UiSettingUpdated };
25
- export { UI_SETTING_UPDATED, uiSettingUpdated, isUiSettingUpdated };
@@ -1,15 +0,0 @@
1
- import {
2
- RepositoryGetFunction,
3
- RepositoryGetFunctionArgs,
4
- RepositorySaveFunction,
5
- RepositorySaveFunctionArgs,
6
- } from "@lookiero/messaging";
7
- import { UiSetting } from "./uiSetting";
8
-
9
- interface UiSettingGetFunction<UiSettingGetFunctionArgs extends RepositoryGetFunctionArgs>
10
- extends RepositoryGetFunction<UiSetting, UiSettingGetFunctionArgs> {}
11
-
12
- interface UiSettingSaveFunction<UiSettingSaveFunctionArgs extends RepositorySaveFunctionArgs>
13
- extends RepositorySaveFunction<UiSetting, UiSettingSaveFunctionArgs> {}
14
-
15
- export type { UiSettingGetFunction, UiSettingSaveFunction };
@@ -1,50 +0,0 @@
1
- import { getUiSetting as getSut, saveUiSetting as saveSut } from "./storageUiSettings";
2
-
3
- const readMock = jest.fn();
4
- const writeMock = jest.fn();
5
- const queryBusMock = jest.fn(() => Promise.resolve());
6
-
7
- describe("storageUiSettings", () => {
8
- it("gets uiSetting based on the given ui setting key", async () => {
9
- const aggregateId = "5be88e6f-fa15-41de-a36f-f8001f343dde";
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, queryBus: queryBusMock })(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(null);
28
-
29
- await expect(getSut({ read: readMock, queryBus: queryBusMock })(uiSettingKey)).rejects.toThrow();
30
- });
31
-
32
- it("saves the given uiSetting", async () => {
33
- const aggregateId = "fc8b7212-e700-47f9-ab83-42b0db22592a";
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,49 +0,0 @@
1
- import { RepositoryGetFunctionArgs, RepositorySaveFunctionArgs } from "@lookiero/messaging";
2
- import { UiSetting } from "../../../../domain/uiSetting/model/uiSetting";
3
- import { UiSettingGetFunction, UiSettingSaveFunction } from "../../../../domain/uiSetting/model/uiSettings";
4
- import { ReadFunction, WriteFunction } from "../../../persistence/storage";
5
- import { UiSettingDto } from "../../../persistence/uiSettingData";
6
-
7
- const toDomain = (uiSettingDto: UiSettingDto): UiSetting => ({
8
- aggregateId: uiSettingDto.id,
9
- key: uiSettingDto.key,
10
- value: uiSettingDto.value,
11
- domainEvents: [],
12
- });
13
-
14
- const fromDomain = (uiSetting: UiSetting): UiSettingDto => ({
15
- id: uiSetting.aggregateId,
16
- key: uiSetting.key,
17
- value: uiSetting.value,
18
- });
19
-
20
- interface StorageUiSettingsGetFunctionArgs extends RepositoryGetFunctionArgs {
21
- readonly read: ReadFunction<UiSettingDto>;
22
- }
23
-
24
- interface StorageUiSettingsGetFunction extends UiSettingGetFunction<StorageUiSettingsGetFunctionArgs> {}
25
-
26
- const getUiSetting: StorageUiSettingsGetFunction =
27
- ({ read }) =>
28
- async (uiSettingKey) => {
29
- const uiSettingDto = await read(uiSettingKey);
30
-
31
- if (!uiSettingDto) {
32
- throw new Error(`UiSetting not found: ${uiSettingKey}`);
33
- }
34
-
35
- return toDomain(uiSettingDto);
36
- };
37
-
38
- interface StorageUiSettingsSaveFunctionArgs extends RepositorySaveFunctionArgs {
39
- readonly write: WriteFunction<UiSettingDto>;
40
- }
41
-
42
- interface StorageUiSettingsSaveFunction extends UiSettingSaveFunction<StorageUiSettingsSaveFunctionArgs> {}
43
-
44
- const saveUiSetting: StorageUiSettingsSaveFunction =
45
- ({ write }) =>
46
- async (aggregateRoot) =>
47
- await write(aggregateRoot.key, fromDomain(aggregateRoot));
48
-
49
- export { getUiSetting, saveUiSetting };
@@ -1,62 +0,0 @@
1
- import { act, renderHook, waitFor } from "@testing-library/react-native";
2
- import { mock } from "jest-mock-extended";
3
- import { bootstrap, CommandStatus } from "@lookiero/messaging-react";
4
- import { Logger } from "@lookiero/sty-psp-logging";
5
- import { UPDATE_UI_SETTING } from "../../../../domain/uiSetting/command/updateUiSetting";
6
- import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
7
- import { useUpdateUiSetting as sut } from "./useUpdateUiSetting";
8
-
9
- const uiSettingKey = "ui_setting_key";
10
- const uiSettingValue = "ui_setting_value";
11
-
12
- const logger = mock<Logger>();
13
-
14
- const saveMock = jest.fn();
15
- const save = jest.fn(() => saveMock);
16
- const mockUpdateUiSettingHandler = jest.fn();
17
- const { Component: Messaging } = bootstrap({ id: MESSAGING_CONTEXT_ID })
18
- .command(
19
- UPDATE_UI_SETTING,
20
- mockUpdateUiSettingHandler,
21
- {},
22
- )(() => jest.fn(), save)
23
- .build();
24
-
25
- describe("useUpdateUiSetting integration hook", () => {
26
- it("returns success as the status when 'update' succeeds", async () => {
27
- mockUpdateUiSettingHandler.mockImplementation(() => () => ({ domainEvents: [] }));
28
- const { result } = renderHook(() => sut({ logger }), { wrapper: Messaging });
29
-
30
- await act(() => {
31
- const [update] = result.current;
32
- update({ key: uiSettingKey, value: uiSettingValue });
33
- });
34
-
35
- await waitFor(() => {
36
- const [, status] = result.current;
37
- expect(status).toBe(CommandStatus.SUCCESS);
38
- });
39
- }, 10000);
40
-
41
- it("calls logger.captureException when 'update' fails", async () => {
42
- const error = new Error("Some error");
43
- mockUpdateUiSettingHandler.mockImplementation(() => () => {
44
- throw error;
45
- });
46
- const { result } = renderHook(() => sut({ logger }), {
47
- wrapper: Messaging,
48
- });
49
-
50
- await act(() => {
51
- const [update] = result.current;
52
- update({ key: uiSettingKey, value: uiSettingValue });
53
- });
54
-
55
- await waitFor(() => {
56
- const [, status] = result.current;
57
-
58
- expect(status).toBe(CommandStatus.ERROR);
59
- expect(logger.captureException).toHaveBeenCalledWith(error);
60
- });
61
- });
62
- });
@@ -1,50 +0,0 @@
1
- import { useCallback } from "react";
2
- import { v4 as uuid } from "uuid";
3
- import { CommandStatus, useCommand } from "@lookiero/messaging-react";
4
- import { Logger } from "@lookiero/sty-psp-logging";
5
- import { updateUiSetting } from "../../../../domain/uiSetting/command/updateUiSetting";
6
- import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
7
-
8
- interface UpdateFunctionArgs {
9
- readonly key: string;
10
- readonly value: unknown;
11
- }
12
-
13
- interface UpdateFunction {
14
- (args: UpdateFunctionArgs): Promise<void>;
15
- }
16
-
17
- type UseUpdateUiSetting = [update: UpdateFunction, status: CommandStatus];
18
-
19
- interface UseUpdateUiSettingArgs {
20
- readonly logger: Logger;
21
- }
22
-
23
- interface UseUpdateUiSettingFunction {
24
- (args: UseUpdateUiSettingArgs): UseUpdateUiSetting;
25
- }
26
-
27
- const useUpdateUiSetting: UseUpdateUiSettingFunction = ({ logger }) => {
28
- const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
29
-
30
- const update: UpdateFunction = useCallback(
31
- async ({ key, value }) => {
32
- try {
33
- await commandBus(
34
- updateUiSetting({
35
- aggregateId: uuid(),
36
- key,
37
- value,
38
- }),
39
- );
40
- } catch (error) {
41
- logger.captureException(error as Error);
42
- }
43
- },
44
- [commandBus, logger],
45
- );
46
-
47
- return [update, status];
48
- };
49
-
50
- export { useUpdateUiSetting };
@@ -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) : null;
9
- };
10
-
11
- const write: WriteFunction<UiSettingDto> = async (key, value) => AsyncStorage.setItem(key, JSON.stringify(value));
12
-
13
- export { read, write };
@@ -1,7 +0,0 @@
1
- interface UiSettingDto {
2
- readonly id: string;
3
- readonly key: string;
4
- readonly value: unknown;
5
- }
6
-
7
- export type { UiSettingDto };
@@ -1,33 +0,0 @@
1
- import { renderHook, waitFor } from "@testing-library/react-native";
2
- import { bootstrap, QueryStatus } from "@lookiero/messaging-react";
3
- import {
4
- UiSettingProjection,
5
- viewUiSettingByKeyHandler,
6
- VIEW_UI_SETTING_BY_KEY,
7
- } from "../../../../projection/uiSetting/viewUiSettingByKey";
8
- import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
9
- import { useViewUiSettingByKey as sut } from "./useViewUiSettingByKey";
10
-
11
- const uiSettingKey = "ui_setting_key";
12
- const uiSettingProjection: UiSettingProjection = {
13
- id: "3a1a95f5-724c-4924-a9e4-fb474dd74d80",
14
- key: uiSettingKey,
15
- value: "ui_setting_value",
16
- };
17
- const view = jest.fn().mockReturnValue(uiSettingProjection);
18
- const { Component: Messaging } = bootstrap({ id: MESSAGING_CONTEXT_ID })
19
- .query(VIEW_UI_SETTING_BY_KEY, viewUiSettingByKeyHandler, { view })
20
- .build();
21
-
22
- describe("useViewUiSettingByKey integration hook", () => {
23
- it("returns success as the query status and the result itself after rendering the hook", async () => {
24
- const { result } = renderHook(() => sut({ key: uiSettingKey }), { wrapper: Messaging });
25
-
26
- await waitFor(() => {
27
- const [projection, status] = result.current;
28
-
29
- expect(projection).toStrictEqual(uiSettingProjection);
30
- expect(status).toBe(QueryStatus.SUCCESS);
31
- });
32
- });
33
- });
@@ -1,22 +0,0 @@
1
- import { useQuery, UseQueryFunctionResult } from "@lookiero/messaging-react";
2
- import { isUiSettingUpdated } from "../../../../domain/uiSetting/model/uiSettingUpdated";
3
- import { UiSettingProjection, viewUiSettingByKey } from "../../../../projection/uiSetting/viewUiSettingByKey";
4
- import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
-
6
- interface UseViewUiSettingByKeyFunctionArgs {
7
- readonly key: string;
8
- }
9
-
10
- interface UseViewUiSettingByKeyFunction {
11
- (args: UseViewUiSettingByKeyFunctionArgs): UseQueryFunctionResult<UiSettingProjection>;
12
- }
13
-
14
- const useViewUiSettingByKey: UseViewUiSettingByKeyFunction = ({ key }) =>
15
- useQuery({
16
- query: viewUiSettingByKey({ key }),
17
- contextId: MESSAGING_CONTEXT_ID,
18
- invalidation: isUiSettingUpdated,
19
- options: { refetchOnMount: "always", staleTime: Infinity, retry: false, refetchOnWindowFocus: false },
20
- });
21
-
22
- export { useViewUiSettingByKey };
@@ -1,36 +0,0 @@
1
- import { UiSettingDto } from "../../persistence/uiSettingData";
2
- import { storageUiSettingByKeyView as sut } from "./storageUiSettingByKeyView";
3
-
4
- const uiSettingKey = "ui_setting_key";
5
- const uiSetting: UiSettingDto = {
6
- id: "ba1fecef-0154-42ea-bbf9-b9c65c621a58",
7
- key: uiSettingKey,
8
- value: "ui_setting_value",
9
- };
10
-
11
- const readMock = jest.fn();
12
- const view = sut({ read: readMock });
13
-
14
- describe("storageUiSettingByKeyView", () => {
15
- it("returns a UiSetting projection", async () => {
16
- readMock.mockReturnValue(Promise.resolve(uiSetting));
17
-
18
- const returnedUiSetting = await view({ key: uiSettingKey });
19
-
20
- expect(returnedUiSetting).toStrictEqual(uiSetting);
21
- });
22
-
23
- it("returns null when ui setting key does not exist", async () => {
24
- readMock.mockReturnValue(Promise.resolve(null));
25
-
26
- const returnedUiSetting = await view({ key: uiSettingKey });
27
-
28
- expect(returnedUiSetting).toBeNull();
29
- });
30
-
31
- it("throws for an unsuccessfull response", async () => {
32
- readMock.mockRejectedValue("error");
33
-
34
- await expect(view({ key: uiSettingKey })).rejects.toThrow();
35
- });
36
- });
@@ -1,37 +0,0 @@
1
- import { UiSettingByKeyView, UiSettingProjection } from "../../../projection/uiSetting/viewUiSettingByKey";
2
- import { ReadFunction } from "../../persistence/storage";
3
- import { UiSettingDto } from "../../persistence/uiSettingData";
4
-
5
- interface ToUiSettingProjectionFunction {
6
- (uiSettingDto: UiSettingDto): UiSettingProjection;
7
- }
8
-
9
- const toUiSettingProjection: ToUiSettingProjectionFunction = (uiSettingDto) => ({
10
- id: uiSettingDto.id,
11
- key: uiSettingDto.key,
12
- value: uiSettingDto.value,
13
- });
14
-
15
- interface StorageUiSettingByKeyView extends UiSettingByKeyView {}
16
-
17
- interface StorageUiSettingByKeyViewFunctionArgs {
18
- readonly read: ReadFunction<UiSettingDto>;
19
- }
20
-
21
- interface StorageUiSettingByKeyViewFunction {
22
- (args: StorageUiSettingByKeyViewFunctionArgs): StorageUiSettingByKeyView;
23
- }
24
-
25
- const storageUiSettingByKeyView: StorageUiSettingByKeyViewFunction =
26
- ({ read }) =>
27
- async ({ key }) => {
28
- try {
29
- const uiSettingDto = await read(key);
30
-
31
- return uiSettingDto ? toUiSettingProjection(uiSettingDto) : null;
32
- } catch (ignored) {
33
- throw new Error("Could not fetch the uiSetting");
34
- }
35
- };
36
-
37
- export { storageUiSettingByKeyView };
@@ -1,3 +0,0 @@
1
- enum UISettings {}
2
-
3
- export { UISettings };
@@ -1,23 +0,0 @@
1
- import { mock } from "jest-mock-extended";
2
- import { QueryBus } from "@lookiero/messaging";
3
- import { viewUiSettingByKey, viewUiSettingByKeyHandler as sut, UiSettingProjection } from "./viewUiSettingByKey";
4
-
5
- const uiSettingKey = "ui_setting_key";
6
- const uiSettingProjection: UiSettingProjection = {
7
- id: "3e12edfe-67a7-41ac-a9c4-60d7de7c1556",
8
- key: uiSettingKey,
9
- value: "ui_setting_value",
10
- };
11
- const queryBus = mock<QueryBus>();
12
- const signal = mock<AbortSignal>();
13
-
14
- describe("viewUiSettingByKey", () => {
15
- it("returns ui setting by key", async () => {
16
- const query = viewUiSettingByKey({ key: uiSettingKey });
17
- const view = jest.fn(() => Promise.resolve(uiSettingProjection));
18
-
19
- const uiSettingProjectionResult = await sut({ view, queryBus, signal })(query);
20
-
21
- expect(uiSettingProjectionResult).toBe(uiSettingProjection);
22
- });
23
- });
@@ -1,50 +0,0 @@
1
- import { query, Query, QueryHandlerFunction, QueryHandlerFunctionArgs } from "@lookiero/messaging";
2
-
3
- interface UiSettingProjection {
4
- readonly id: string;
5
- readonly key: string;
6
- readonly value: unknown;
7
- }
8
-
9
- const VIEW_UI_SETTING_BY_KEY = "view_ui_setting_by_key";
10
-
11
- interface ViewUiSettingByKeyPayload {
12
- readonly key: string;
13
- }
14
-
15
- interface ViewUiSettingByKey extends Query<typeof VIEW_UI_SETTING_BY_KEY>, ViewUiSettingByKeyPayload {}
16
-
17
- interface ViewUiSettingByKeyFunction {
18
- (payload: ViewUiSettingByKeyPayload): ViewUiSettingByKey;
19
- }
20
-
21
- const viewUiSettingByKey: ViewUiSettingByKeyFunction = (payload) => ({
22
- ...query({ name: VIEW_UI_SETTING_BY_KEY }),
23
- ...payload,
24
- });
25
-
26
- type ViewUiSettingByKeyResult = UiSettingProjection | null;
27
-
28
- interface UiSettingByKeyViewArgs {
29
- readonly key: string;
30
- }
31
-
32
- interface UiSettingByKeyView {
33
- (args: UiSettingByKeyViewArgs): Promise<ViewUiSettingByKeyResult>;
34
- }
35
-
36
- interface ViewUiSettingByKeyHandlerFunctionArgs extends QueryHandlerFunctionArgs {
37
- readonly view: UiSettingByKeyView;
38
- }
39
-
40
- const viewUiSettingByKeyHandler: QueryHandlerFunction<
41
- ViewUiSettingByKey,
42
- ViewUiSettingByKeyResult,
43
- ViewUiSettingByKeyHandlerFunctionArgs
44
- > =
45
- ({ view }) =>
46
- async ({ key }) =>
47
- view({ key });
48
-
49
- export type { UiSettingProjection, UiSettingByKeyView };
50
- export { VIEW_UI_SETTING_BY_KEY, viewUiSettingByKey, viewUiSettingByKeyHandler };