Skip to content

Commit 6062ca8

Browse files
committed
test: 테스트 코드 추가 및 수정
1 parent e1d7f87 commit 6062ca8

File tree

2 files changed

+103
-14
lines changed

2 files changed

+103
-14
lines changed

packages/notion-to-utils/src/client/getFileUrl.spec.ts

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const getFileUrlValidMock = {
2323
files: [
2424
{
2525
file: {
26-
url: 'https://~~',
27-
expiry_time: 'string',
26+
url: 'https://example.com/file.pdf',
27+
expiry_time: '2023-05-05T12:00:00.000Z',
2828
},
29-
name: 'test',
29+
name: 'test.pdf',
3030
type: 'file',
3131
},
3232
],
@@ -46,9 +46,27 @@ const getFileUrlInValidMock = {
4646
},
4747
};
4848

49+
const getFileUrlExternalMock = {
50+
object: 'page',
51+
properties: {
52+
[KEY]: {
53+
type: 'files',
54+
files: [
55+
{
56+
name: 'External File',
57+
type: 'external',
58+
external: {
59+
url: 'https://example.com/external-file.pdf',
60+
},
61+
},
62+
],
63+
id: '1',
64+
},
65+
},
66+
};
67+
4968
describe('getFileUrl', () => {
50-
it('should return fileUrl when valid pageId, valid propertyKey are provided', async () => {
51-
// Mock the notionClient.pages.retrieve method
69+
it('유효한 pageId와 유효한 propertyKey가 제공될 때 fileUrl을 반환한다', async () => {
5270
notionClient.pages.retrieve = vi
5371
.fn()
5472
.mockResolvedValue(getFileUrlValidMock);
@@ -57,23 +75,57 @@ describe('getFileUrl', () => {
5775
expect(fileUrl).toEqual(
5876
getFileUrlValidMock.properties[KEY].files[0]?.file.url
5977
);
78+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
79+
page_id: TEST_ID,
80+
});
6081
});
6182

62-
it('should return undefined when invalid pageId, valid propertyKey are provided', async () => {
83+
it('유효하지 않은 pageId와 유효한 propertyKey가 제공될 때 undefined를 반환한다', async () => {
6384
notionClient.pages.retrieve = vi
6485
.fn()
6586
.mockResolvedValue(getFileUrlInValidMock);
6687

6788
const fileUrl = await notionClient.getFileUrl(TEST_ID, KEY);
6889
expect(fileUrl).toBeUndefined();
90+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
91+
page_id: TEST_ID,
92+
});
6993
});
7094

71-
it('should return undefined when valid pageId, invalid propertyKey are provided', async () => {
95+
it('유효한 pageId와 유효하지 않은 propertyKey가 제공될 때 undefined를 반환한다', async () => {
7296
notionClient.pages.retrieve = vi
7397
.fn()
7498
.mockResolvedValue(getFileUrlValidMock);
7599

76-
const fileUrl = await notionClient.getFileUrl(TEST_ID, 'temp');
100+
const fileUrl = await notionClient.getFileUrl(TEST_ID, 'invalidKey');
77101
expect(fileUrl).toBeUndefined();
102+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
103+
page_id: TEST_ID,
104+
});
105+
});
106+
107+
it('외부 파일 타입에 대해 undefined를 반환한다', async () => {
108+
notionClient.pages.retrieve = vi
109+
.fn()
110+
.mockResolvedValue(getFileUrlExternalMock);
111+
112+
const fileUrl = await notionClient.getFileUrl(TEST_ID, KEY);
113+
expect(fileUrl).toBeUndefined();
114+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
115+
page_id: TEST_ID,
116+
});
117+
});
118+
119+
it('API 오류를 적절히 처리한다', async () => {
120+
notionClient.pages.retrieve = vi
121+
.fn()
122+
.mockRejectedValue(new Error('API Error'));
123+
124+
await expect(notionClient.getFileUrl(TEST_ID, KEY)).rejects.toThrow(
125+
'API Error'
126+
);
127+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
128+
page_id: TEST_ID,
129+
});
78130
});
79131
});

packages/notion-to-utils/src/client/getPageProperties.spec.ts

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,80 @@ const getPagePropertiesMock = {
2020
properties: {
2121
Category: { id: '1', type: 'text', text: { content: 'Category A' } },
2222
Slug: { id: '2', type: 'text', text: { content: 'slug-value' } },
23+
Date: { id: '3', type: 'date', date: { start: '2023-05-01' } },
2324
},
2425
};
2526

2627
describe('getPageProperties', () => {
27-
it('should return properties when valid pageId is provided', async () => {
28-
// Mock the notionClient.pages.retrieve method
28+
it('유효한 pageId가 제공되고 keys가 없을 때 모든 속성을 반환한다', async () => {
2929
notionClient.pages.retrieve = vi
3030
.fn()
3131
.mockResolvedValue(getPagePropertiesMock);
3232

33-
// Test when no keys are provided (should return all properties)
3433
const properties = await notionClient.getPageProperties(TEST_ID);
3534
expect(properties).toEqual(getPagePropertiesMock.properties);
35+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
36+
page_id: TEST_ID,
37+
});
3638
});
3739

38-
it('should return properties when valid pageId, keys are provided', async () => {
39-
// Mock the notionClient.pages.retrieve method
40+
it('유효한 pageId와 keys가 제공될 때 지정된 속성만 반환한다', async () => {
4041
notionClient.pages.retrieve = vi
4142
.fn()
4243
.mockResolvedValue(getPagePropertiesMock);
4344

4445
const filteredProperties = await notionClient.getPageProperties(TEST_ID, [
4546
'Category',
47+
'Date',
4648
]);
4749

4850
expect(filteredProperties).toEqual({
4951
Category: getPagePropertiesMock.properties.Category,
52+
Date: getPagePropertiesMock.properties.Date,
53+
});
54+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
55+
page_id: TEST_ID,
5056
});
5157
});
5258

53-
it('should return undefined when invalid pageId is provided', async () => {
59+
it('유효하지 않은 pageId가 제공될 때 undefined를 반환한다', async () => {
5460
notionClient.pages.retrieve = vi.fn().mockResolvedValue(null);
5561

5662
const filteredProperties = await notionClient.getPageProperties(TEST_ID, [
5763
'Category',
5864
]);
5965

6066
expect(filteredProperties).toBeUndefined();
67+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
68+
page_id: TEST_ID,
69+
});
70+
});
71+
72+
it('유효한 pageId가 제공되지만 일치하는 keys가 없을 때 빈 객체를 반환한다', async () => {
73+
notionClient.pages.retrieve = vi
74+
.fn()
75+
.mockResolvedValue(getPagePropertiesMock);
76+
77+
const filteredProperties = await notionClient.getPageProperties(TEST_ID, [
78+
'NonExistentKey',
79+
]);
80+
81+
expect(filteredProperties).toEqual({});
82+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
83+
page_id: TEST_ID,
84+
});
85+
});
86+
87+
it('API 오류를 적절히 처리한다', async () => {
88+
notionClient.pages.retrieve = vi
89+
.fn()
90+
.mockRejectedValue(new Error('API Error'));
91+
92+
await expect(notionClient.getPageProperties(TEST_ID)).rejects.toThrow(
93+
'API Error'
94+
);
95+
expect(notionClient.pages.retrieve).toHaveBeenCalledWith({
96+
page_id: TEST_ID,
97+
});
6198
});
6299
});

0 commit comments

Comments
 (0)