Skip to content

Commit

Permalink
add test for board creation
Browse files Browse the repository at this point in the history
  • Loading branch information
uidp committed Dec 16, 2024
1 parent 43728dd commit ad830cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/modules/data/room/RoomDetails.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const useRoomDetailsStore = defineStore("roomDetailsStore", () => {
const roomBoards = ref<RoomBoardItem[]>([]);

const roomApi = RoomApiFactory(undefined, "/v3", $axios);
const boardApi = BoardApiFactory(undefined, "/v3", $axios);

const fetchRoom = async (id: string) => {
try {
Expand All @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions src/modules/data/room/RoomDetails.store.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { initializeAxios, mapAxiosErrorToResponseError } from "@/utils/api";
import {
apiResponseErrorFactory,
axiosErrorFactory,
mockApiResponse,
} from "@@/tests/test-utils";

jest.mock("@/utils/api");
Expand Down Expand Up @@ -35,12 +36,14 @@ const setupErrorResponse = (message = "NOT_FOUND", code = 404) => {

describe("useRoomDetailsStore", () => {
let roomApiMock: DeepMocked<serverApi.RoomApiInterface>;
let boardApiMock: DeepMocked<serverApi.BoardApiInterface>;
let axiosMock: DeepMocked<AxiosInstance>;
let mockedCreateApplicationErrorCalls: ReturnType<typeof useApplicationError>;

beforeEach(() => {
setActivePinia(createPinia());
roomApiMock = createMock<serverApi.RoomApiInterface>();
boardApiMock = createMock<serverApi.BoardApiInterface>();
axiosMock = createMock<AxiosInstance>();
mockedCreateApplicationErrorCalls =
createMock<ReturnType<typeof useApplicationError>>();
Expand All @@ -49,6 +52,7 @@ describe("useRoomDetailsStore", () => {
);

jest.spyOn(serverApi, "RoomApiFactory").mockReturnValue(roomApiMock);
jest.spyOn(serverApi, "BoardApiFactory").mockReturnValue(boardApiMock);
initializeAxios(axiosMock);
});

Expand Down Expand Up @@ -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,
});
});
});
});

0 comments on commit ad830cd

Please sign in to comment.