Skip to content

Commit cf193ba

Browse files
feat: 페이지관련 코드 워크스페이스 관련 업데이트
1 parent 9d9e465 commit cf193ba

File tree

5 files changed

+233
-62
lines changed

5 files changed

+233
-62
lines changed

apps/backend/src/page/page.controller.spec.ts

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { UpdatePageDto } from './dtos/updatePage.dto';
66
import { PageResponseMessage } from './page.controller';
77
import { PageNotFoundException } from '../exception/page.exception';
88
import { Page } from './page.entity';
9+
import { WorkspaceNotFoundException } from '../exception/workspace.exception';
910

1011
describe('PageController', () => {
1112
let controller: PageController;
@@ -23,7 +24,7 @@ describe('PageController', () => {
2324
deletePage: jest.fn(),
2425
updatePage: jest.fn(),
2526
findPageById: jest.fn(),
26-
findPages: jest.fn(),
27+
findPagesByWorkspace: jest.fn(),
2728
},
2829
},
2930
],
@@ -38,17 +39,20 @@ describe('PageController', () => {
3839
});
3940

4041
describe('createPage', () => {
41-
it('페이지가 성공적으로 만들어진다', async () => {
42+
it('페이지가 성공적으로 만들어진다.', async () => {
4243
const dto: CreatePageDto = {
4344
title: 'New Page',
4445
content: {} as JSON,
46+
workspaceId: 'workspace-id',
4547
x: 1,
4648
y: 2,
4749
};
50+
4851
const expectedResponse = {
4952
message: PageResponseMessage.PAGE_CREATED,
5053
pageId: 1,
5154
};
55+
5256
const newDate = new Date();
5357
jest.spyOn(pageService, 'createPage').mockResolvedValue({
5458
id: 1,
@@ -61,11 +65,32 @@ describe('PageController', () => {
6165
emoji: null,
6266
workspace: null,
6367
});
68+
6469
const result = await controller.createPage(dto);
6570

6671
expect(pageService.createPage).toHaveBeenCalledWith(dto);
6772
expect(result).toEqual(expectedResponse);
6873
});
74+
75+
it('워크스페이스가 존재하지 않을 경우 WorkspaceNotFoundException을 throw한다.', async () => {
76+
const dto: CreatePageDto = {
77+
title: 'New Page',
78+
content: {} as JSON,
79+
workspaceId: 'invalid-workspace-id',
80+
x: 1,
81+
y: 2,
82+
};
83+
84+
jest
85+
.spyOn(pageService, 'createPage')
86+
.mockRejectedValue(new WorkspaceNotFoundException());
87+
88+
await expect(controller.createPage(dto)).rejects.toThrow(
89+
WorkspaceNotFoundException,
90+
);
91+
92+
expect(pageService.createPage).toHaveBeenCalledWith(dto);
93+
});
6994
});
7095

7196
describe('deletePage', () => {
@@ -117,22 +142,6 @@ describe('PageController', () => {
117142
});
118143
});
119144

120-
describe('findPages', () => {
121-
it('모든 페이지 목록을 content 없이 반환한다.', async () => {
122-
const expectedPages = [
123-
{ id: 1, title: 'Page1' },
124-
{ id: 2, title: 'Page2' },
125-
] as Page[];
126-
127-
jest.spyOn(pageService, 'findPages').mockResolvedValue(expectedPages);
128-
129-
await expect(controller.findPages()).resolves.toEqual({
130-
message: PageResponseMessage.PAGE_LIST_RETURNED,
131-
pages: expectedPages,
132-
});
133-
});
134-
});
135-
136145
describe('findPageById', () => {
137146
it('id에 해당하는 페이지의 상세 정보를 반환한다.', async () => {
138147
const expectedPage: Page = {
@@ -155,4 +164,44 @@ describe('PageController', () => {
155164
});
156165
});
157166
});
167+
168+
describe('findPagesByWorkspace', () => {
169+
it('특정 워크스페이스에 존재하는 페이지들을 반환한다.', async () => {
170+
const workspaceId = 'workspace-id';
171+
const expectedPages = [
172+
{ id: 1, title: 'Page 1', emoji: '📄' },
173+
{ id: 2, title: 'Page 2', emoji: '✏️' },
174+
] as Partial<Page>[];
175+
176+
jest
177+
.spyOn(pageService, 'findPagesByWorkspace')
178+
.mockResolvedValue(expectedPages);
179+
180+
const result = await controller.findPagesByWorkspace(workspaceId);
181+
182+
expect(pageService.findPagesByWorkspace).toHaveBeenCalledWith(
183+
workspaceId,
184+
);
185+
expect(result).toEqual({
186+
message: PageResponseMessage.PAGE_LIST_RETURNED,
187+
pages: expectedPages,
188+
});
189+
});
190+
191+
it('워크스페이스가 존재하지 않을 경우 WorkspaceNotFoundException을 throw한다.', async () => {
192+
const workspaceId = 'invalid-workspace-id';
193+
194+
jest
195+
.spyOn(pageService, 'findPagesByWorkspace')
196+
.mockRejectedValue(new WorkspaceNotFoundException());
197+
198+
await expect(
199+
controller.findPagesByWorkspace(workspaceId),
200+
).rejects.toThrow(WorkspaceNotFoundException);
201+
202+
expect(pageService.findPagesByWorkspace).toHaveBeenCalledWith(
203+
workspaceId,
204+
);
205+
});
206+
});
158207
});

apps/backend/src/page/page.controller.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ export class PageController {
8787
@ApiResponse({
8888
type: FindPagesResponseDto,
8989
})
90-
@ApiOperation({ summary: '모든 페이지를 가져옵니다.' })
91-
@Get()
90+
@ApiOperation({ summary: '특정 워크스페이스의 모든 페이지를 가져옵니다.' })
91+
@Get('/workspace/:workspaceId')
9292
@HttpCode(HttpStatus.OK)
93-
async findPages(): Promise<FindPagesResponseDto> {
93+
async findPagesByWorkspace(
94+
@Param('workspaceId') workspaceId: string, // Snowflake ID
95+
): Promise<FindPagesResponseDto> {
96+
const pages = await this.pageService.findPagesByWorkspace(workspaceId);
9497
return {
9598
message: PageResponseMessage.PAGE_LIST_RETURNED,
96-
pages: await this.pageService.findPages(),
99+
pages,
97100
};
98101
}
99102

apps/backend/src/page/page.repository.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ export class PageRepository extends Repository<Page> {
99
super(Page, dataSource.createEntityManager());
1010
}
1111

12-
async findPageList(): Promise<Page[]> {
13-
return await this.find({
12+
async findPagesByWorkspace(workspaceId: number): Promise<Partial<Page>[]> {
13+
return this.find({
14+
where: { workspace: { id: workspaceId } },
1415
select: {
1516
id: true,
1617
title: true,
1718
emoji: true,
1819
},
1920
});
2021
}
21-
22-
async findPagesByWorkspace(workspaceId: number): Promise<Page[]> {
23-
return this.find({ where: { workspace: { id: workspaceId } } });
24-
}
2522
}

0 commit comments

Comments
 (0)