@@ -24,28 +24,47 @@ const getPagePropertiesMock = {
24
24
} ,
25
25
} ;
26
26
27
+ const getPagePropertiesMockWithCover = {
28
+ object : 'page' ,
29
+ id : TEST_ID ,
30
+ properties : {
31
+ Category : { id : '1' , type : 'text' , text : { content : 'Category A' } } ,
32
+ Slug : { id : '2' , type : 'text' , text : { content : 'slug-value' } } ,
33
+ Date : { id : '3' , type : 'date' , date : { start : '2023-05-01' } } ,
34
+ } ,
35
+ cover : {
36
+ type : 'file' ,
37
+ file : {
38
+ url : 'https://notion-image.url/test.jpg' ,
39
+ } ,
40
+ } ,
41
+ } ;
42
+
27
43
describe ( 'getPageProperties' , ( ) => {
28
- it ( '유효한 pageId가 제공되고 keys가 없을 때 모든 속성을 반환한다' , async ( ) => {
44
+ it ( '유효한 pageId가 제공되고 keys가 없으며, extractValues가 false일 때 모든 속성을 반환한다' , async ( ) => {
29
45
notionClient . pages . retrieve = vi
30
46
. fn ( )
31
47
. mockResolvedValue ( getPagePropertiesMock ) ;
32
48
33
- const properties = await notionClient . getPageProperties ( TEST_ID ) ;
49
+ // extractValues를 false로 명시적으로 설정
50
+ const properties = await notionClient . getPageProperties ( TEST_ID , [ ] , false ) ;
34
51
expect ( properties ) . toEqual ( getPagePropertiesMock . properties ) ;
35
52
expect ( notionClient . pages . retrieve ) . toHaveBeenCalledWith ( {
36
53
page_id : TEST_ID ,
37
54
} ) ;
38
55
} ) ;
39
56
40
- it ( '유효한 pageId와 keys가 제공될 때 지정된 속성만 반환한다' , async ( ) => {
57
+ it ( '유효한 pageId와 keys가 제공될 때, extractValues가 false일 때 지정된 속성만 반환한다' , async ( ) => {
41
58
notionClient . pages . retrieve = vi
42
59
. fn ( )
43
60
. mockResolvedValue ( getPagePropertiesMock ) ;
44
61
45
- const filteredProperties = await notionClient . getPageProperties ( TEST_ID , [
46
- 'Category' ,
47
- 'Date' ,
48
- ] ) ;
62
+ // extractValues를 false로 명시적으로 설정
63
+ const filteredProperties = await notionClient . getPageProperties (
64
+ TEST_ID ,
65
+ [ 'Category' , 'Date' ] ,
66
+ false
67
+ ) ;
49
68
50
69
expect ( filteredProperties ) . toEqual ( {
51
70
Category : getPagePropertiesMock . properties . Category ,
@@ -59,9 +78,11 @@ describe('getPageProperties', () => {
59
78
it ( '유효하지 않은 pageId가 제공될 때 undefined를 반환한다' , async ( ) => {
60
79
notionClient . pages . retrieve = vi . fn ( ) . mockResolvedValue ( null ) ;
61
80
62
- const filteredProperties = await notionClient . getPageProperties ( TEST_ID , [
63
- 'Category' ,
64
- ] ) ;
81
+ const filteredProperties = await notionClient . getPageProperties (
82
+ TEST_ID ,
83
+ [ 'Category' ] ,
84
+ false
85
+ ) ;
65
86
66
87
expect ( filteredProperties ) . toBeUndefined ( ) ;
67
88
expect ( notionClient . pages . retrieve ) . toHaveBeenCalledWith ( {
@@ -74,9 +95,11 @@ describe('getPageProperties', () => {
74
95
. fn ( )
75
96
. mockResolvedValue ( getPagePropertiesMock ) ;
76
97
77
- const filteredProperties = await notionClient . getPageProperties ( TEST_ID , [
78
- 'NonExistentKey' ,
79
- ] ) ;
98
+ const filteredProperties = await notionClient . getPageProperties (
99
+ TEST_ID ,
100
+ [ 'NonExistentKey' ] ,
101
+ false
102
+ ) ;
80
103
81
104
expect ( filteredProperties ) . toEqual ( { } ) ;
82
105
expect ( notionClient . pages . retrieve ) . toHaveBeenCalledWith ( {
@@ -96,4 +119,100 @@ describe('getPageProperties', () => {
96
119
page_id : TEST_ID ,
97
120
} ) ;
98
121
} ) ;
122
+
123
+ // 커버 이미지 테스트 케이스 추가
124
+ it ( '파일 타입의 커버 이미지가 있을 때 coverUrl 속성을 추가한다' , async ( ) => {
125
+ notionClient . pages . retrieve = vi
126
+ . fn ( )
127
+ . mockResolvedValue ( getPagePropertiesMockWithCover ) ;
128
+
129
+ // 테스트 실행
130
+ const properties = await notionClient . getPageProperties ( TEST_ID , [ ] , false ) ;
131
+ console . log ( properties ) ;
132
+ // 결과 검증
133
+ expect ( properties ) . not . toBeUndefined ( ) ;
134
+ expect ( properties ) . toHaveProperty ( 'coverUrl' ) ;
135
+ expect ( ( properties as Record < string , any > ) . coverUrl ) . toEqual ( {
136
+ type : 'url' ,
137
+ url : 'https://www.notion.so/image/https%3A%2F%2Fnotion-image.url%2Ftest.jpg?table=block&id=TEMP&cache=v2' ,
138
+ id : `${ TEST_ID } -coverUrl` ,
139
+ } ) ;
140
+ } ) ;
141
+
142
+ it ( '외부 타입의 커버 이미지가 있을 때 coverUrl 속성을 추가한다' , async ( ) => {
143
+ const mockWithExternalCover = {
144
+ ...getPagePropertiesMock ,
145
+ cover : {
146
+ type : 'external' ,
147
+ external : {
148
+ url : 'https://external-image.url/test.jpg' ,
149
+ } ,
150
+ } ,
151
+ } ;
152
+
153
+ notionClient . pages . retrieve = vi
154
+ . fn ( )
155
+ . mockResolvedValue ( mockWithExternalCover ) ;
156
+
157
+ // 테스트 실행
158
+ const properties = await notionClient . getPageProperties ( TEST_ID , [ ] , false ) ;
159
+
160
+ // 결과 검증
161
+ expect ( properties ) . not . toBeUndefined ( ) ;
162
+ expect ( properties ) . toHaveProperty ( 'coverUrl' ) ;
163
+ expect ( ( properties as Record < string , any > ) . coverUrl ) . toEqual ( {
164
+ type : 'url' ,
165
+ url : mockWithExternalCover . cover . external . url ,
166
+ id : `${ TEST_ID } -coverUrl` ,
167
+ } ) ;
168
+ } ) ;
169
+
170
+ it ( '커버 이미지가 없을 때 coverUrl 속성을 추가하지 않는다' , async ( ) => {
171
+ const mockWithoutCover = {
172
+ object : 'page' ,
173
+ id : TEST_ID ,
174
+ properties : {
175
+ Category : { id : '1' , type : 'text' , text : { content : 'Category A' } } ,
176
+ Slug : { id : '2' , type : 'text' , text : { content : 'slug-value' } } ,
177
+ Date : { id : '3' , type : 'date' , date : { start : '2023-05-01' } } ,
178
+ } ,
179
+ // cover 속성 없음
180
+ } ;
181
+
182
+ notionClient . pages . retrieve = vi . fn ( ) . mockResolvedValue ( mockWithoutCover ) ;
183
+ // 테스트 실행
184
+ const properties = await notionClient . getPageProperties ( TEST_ID , [ ] , false ) ;
185
+
186
+ // 결과 검증
187
+ expect ( properties ) . not . toBeUndefined ( ) ;
188
+ expect ( properties as Record < string , any > ) . not . toHaveProperty ( 'coverUrl' ) ;
189
+ } ) ;
190
+
191
+ it ( 'extractValues가 true일 때 커버 이미지 URL을 추출한다' , async ( ) => {
192
+ // 커버 이미지가 있는 mock 데이터
193
+ const mockWithExternalCover = {
194
+ ...getPagePropertiesMock ,
195
+ cover : {
196
+ type : 'external' ,
197
+ external : {
198
+ url : 'https://external-image.url/test.jpg' ,
199
+ } ,
200
+ } ,
201
+ } ;
202
+
203
+ // pages.retrieve만 모킹
204
+ notionClient . pages . retrieve = vi
205
+ . fn ( )
206
+ . mockResolvedValue ( mockWithExternalCover ) ;
207
+
208
+ // 테스트 실행 - extractValues를 true로 설정
209
+ const properties = await notionClient . getPageProperties ( TEST_ID , [ ] , true ) ;
210
+
211
+ // 결과 검증
212
+ expect ( properties ) . not . toBeUndefined ( ) ;
213
+ expect ( properties ) . toHaveProperty ( 'coverUrl' ) ;
214
+ expect ( ( properties as Record < string , any > ) . coverUrl ) . toBe (
215
+ mockWithExternalCover . cover . external . url
216
+ ) ;
217
+ } ) ;
99
218
} ) ;
0 commit comments