From ad830cd43eeec6d54c9d13e03888f69f55a99545 Mon Sep 17 00:00:00 2001 From: Uwe Ilgenstein Date: Mon, 16 Dec 2024 07:47:46 +0100 Subject: [PATCH] add test for board creation --- src/modules/data/room/RoomDetails.store.ts | 3 +- .../data/room/RoomDetails.store.unit.ts | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/modules/data/room/RoomDetails.store.ts b/src/modules/data/room/RoomDetails.store.ts index 61fb81cfec..af82c1c601 100644 --- a/src/modules/data/room/RoomDetails.store.ts +++ b/src/modules/data/room/RoomDetails.store.ts @@ -23,6 +23,7 @@ export const useRoomDetailsStore = defineStore("roomDetailsStore", () => { const roomBoards = ref([]); const roomApi = RoomApiFactory(undefined, "/v3", $axios); + const boardApi = BoardApiFactory(undefined, "/v3", $axios); const fetchRoom = async (id: string) => { try { @@ -49,8 +50,6 @@ export const useRoomDetailsStore = defineStore("roomDetailsStore", () => { layout: BoardLayout, title: string ) => { - const boardApi = BoardApiFactory(undefined, "/v3", $axios); - const params: CreateBoardBodyParams = { title: title, parentId: roomId, diff --git a/src/modules/data/room/RoomDetails.store.unit.ts b/src/modules/data/room/RoomDetails.store.unit.ts index ae0bca7fa4..b14e8b6d23 100644 --- a/src/modules/data/room/RoomDetails.store.unit.ts +++ b/src/modules/data/room/RoomDetails.store.unit.ts @@ -8,6 +8,7 @@ import { initializeAxios, mapAxiosErrorToResponseError } from "@/utils/api"; import { apiResponseErrorFactory, axiosErrorFactory, + mockApiResponse, } from "@@/tests/test-utils"; jest.mock("@/utils/api"); @@ -35,12 +36,14 @@ const setupErrorResponse = (message = "NOT_FOUND", code = 404) => { describe("useRoomDetailsStore", () => { let roomApiMock: DeepMocked; + let boardApiMock: DeepMocked; let axiosMock: DeepMocked; let mockedCreateApplicationErrorCalls: ReturnType; beforeEach(() => { setActivePinia(createPinia()); roomApiMock = createMock(); + boardApiMock = createMock(); axiosMock = createMock(); mockedCreateApplicationErrorCalls = createMock>(); @@ -49,6 +52,7 @@ describe("useRoomDetailsStore", () => { ); jest.spyOn(serverApi, "RoomApiFactory").mockReturnValue(roomApiMock); + jest.spyOn(serverApi, "BoardApiFactory").mockReturnValue(boardApiMock); initializeAxios(axiosMock); }); @@ -135,4 +139,30 @@ describe("useRoomDetailsStore", () => { expect(store.room).toBeUndefined(); }); }); + + describe("createBoard", () => { + it("should call createBoard api", async () => { + const { store } = setup(); + const boardId = "board-id"; + const roomId = "room-id"; + const layout = serverApi.BoardLayout.Columns; + const title = "title"; + + boardApiMock.boardControllerCreateBoard.mockResolvedValue( + mockApiResponse({ + data: { id: boardId }, + }) + ); + + const result = await store.createBoard(roomId, layout, title); + + expect(result).toBe(boardId); + expect(boardApiMock.boardControllerCreateBoard).toHaveBeenCalledWith({ + title, + parentId: roomId, + parentType: serverApi.BoardParentType.Room, + layout, + }); + }); + }); });