@@ -6,6 +6,7 @@ import { UpdatePageDto } from './dtos/updatePage.dto';
66import { PageResponseMessage } from './page.controller' ;
77import { PageNotFoundException } from '../exception/page.exception' ;
88import { Page } from './page.entity' ;
9+ import { WorkspaceNotFoundException } from '../exception/workspace.exception' ;
910
1011describe ( '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} ) ;
0 commit comments