Skip to content
This repository was archived by the owner on Mar 12, 2023. It is now read-only.

Commit 5f4214b

Browse files
authored
Merge pull request #131 from otoyo/refactor-tests
Refactor tests and fix interfaces
2 parents cc0a8a6 + 097d969 commit 5f4214b

30 files changed

+1160
-2497
lines changed

README.ja.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ yarn lint
120120
yarn test
121121
```
122122

123-
HTML を変更した場合はスナップショットを更新してください。
124-
125-
```
126-
yarn jest --updateSnapshot
127-
```
128-
129-
- [Jest CLI オプション --updateSnapshot](https://jestjs.io/ja/docs/cli#--updatesnapshot)
130-
131123
## オプション設定
132124

133125
- favicon

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ yarn lint
113113
yarn test
114114
```
115115

116-
Update the snapshot if you change HTML.
117-
118-
```
119-
yarn jest --updateSnapshot
120-
```
121-
122-
- [Jest CLI Options --updateSnapshot](https://jestjs.io/docs/cli#--updatesnapshot)
123-
124116
## Optional settings
125117

126118
- favicon

__mocks__/@notionhq/client.js

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,56 +35,26 @@ client.Client = class {
3535
blocks: {
3636
children: {
3737
list: ({ block_id }) => {
38-
const tableBlockId = '30f2f940-3bd8-46de-b76c-00e4c0eb9521'
39-
const nestedBulletedListBlockId =
40-
'd3a36836-2e43-4d4d-a186-9b18bc86e6ff'
41-
const nestedNumberedListBlockId =
42-
'4e28c935-0b09-48c3-b72c-169b7fc5dbdb'
43-
44-
if (block_id === tableBlockId) {
45-
return JSON.parse(
46-
fs
47-
.readFileSync(
48-
path.resolve(
49-
'./__tests__/fixtures/notion-api-response-table-row-blocks.json'
50-
)
51-
)
52-
.toString()
53-
)
54-
} else if (block_id === nestedBulletedListBlockId) {
55-
return JSON.parse(
56-
fs
57-
.readFileSync(
58-
path.resolve(
59-
'./__tests__/fixtures/notion-api-response-bulleted-list-item-blocks.json'
60-
)
61-
)
62-
.toString()
63-
)
64-
} else if (block_id === nestedNumberedListBlockId) {
65-
return JSON.parse(
66-
fs
67-
.readFileSync(
68-
path.resolve(
69-
//'./__tests__/fixtures/notion-api-response-bulleted-list-item-blocks.json'
70-
'./__tests__/fixtures/notion-api-response-numbered-list-item-blocks.json'
71-
)
72-
)
73-
.toString()
74-
)
38+
const blockIdToFilename = {
39+
'30f2f940-3bd8-46de-b76c-00e4c0eb9521': './__tests__/fixtures/notion-api-response-table-row-blocks.json',
40+
'fd07e26e-c0be-43df-be77-da87a5dcc986': './__tests__/fixtures/notion-api-response-columns.json',
41+
'8d87c82c-056f-425e-9dd6-a3998bbda4bb': './__tests__/fixtures/notion-api-response-column-blocks.json',
42+
'd3a36836-2e43-4d4d-a186-9b18bc86e6ff': './__tests__/fixtures/notion-api-response-bulleted-list-item-blocks.json',
43+
'4e28c935-0b09-48c3-b72c-169b7fc5dbdb': './__tests__/fixtures/notion-api-response-numbered-list-item-blocks.json',
44+
'04543c2a-b9f1-4fcc-8ff9-70196353c63a': './__tests__/fixtures/notion-api-response-to-do-blocks.json',
45+
'359244aa-d0bf-43a0-aa32-87a3afba908d': './__tests__/fixtures/notion-api-response-synced-block-children.json',
46+
'b25cc629-df95-4ffb-adbe-a83aa0e13165': './__tests__/fixtures/notion-api-response-toggle-blocks.json',
7547
}
76-
77-
return JSON.parse(
78-
fs
79-
.readFileSync(
80-
path.resolve(
81-
'./__tests__/fixtures/notion-api-response-page-blocks.json'
82-
)
83-
)
84-
.toString()
85-
)
48+
const filename = blockIdToFilename[block_id] || './__tests__/fixtures/notion-api-response-page-blocks.json'
49+
return JSON.parse(fs.readFileSync(path.resolve(filename)).toString())
8650
},
8751
},
52+
retrieve: ({ block_id }) => {
53+
if (block_id === '359244aa-d0bf-43a0-aa32-87a3afba908d') {
54+
return JSON.parse(fs.readFileSync(path.resolve('./__tests__/fixtures/notion-api-response-original-synced-block.json')).toString())
55+
}
56+
return {}
57+
},
8858
},
8959
}
9060
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"object": "list",
3+
"results": [
4+
{
5+
"object": "block",
6+
"id": "e4e135a3-afb9-4665-8c37-d10a00e57f57",
7+
"created_time": "2022-02-23T09:54:00.000Z",
8+
"last_edited_time": "2022-02-23T09:54:00.000Z",
9+
"created_by": {
10+
"object": "user",
11+
"id": "c6c84f05-e202-41a2-8653-dd26ca8757f8"
12+
},
13+
"last_edited_by": {
14+
"object": "user",
15+
"id": "c6c84f05-e202-41a2-8653-dd26ca8757f8"
16+
},
17+
"has_children": false,
18+
"archived": false,
19+
"type": "paragraph",
20+
"paragraph": {
21+
"rich_text": [
22+
{
23+
"type": "text",
24+
"text": {
25+
"content": "Column List",
26+
"link": null
27+
},
28+
"annotations": {
29+
"bold": false,
30+
"italic": false,
31+
"strikethrough": false,
32+
"underline": false,
33+
"code": false,
34+
"color": "default"
35+
},
36+
"plain_text": "Column List",
37+
"href": null
38+
}
39+
],
40+
"color": "default"
41+
}
42+
}
43+
],
44+
"next_cursor": null,
45+
"has_more": false
46+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"object": "list",
3+
"results": [
4+
{
5+
"object": "block",
6+
"id": "8d87c82c-056f-425e-9dd6-a3998bbda4bb",
7+
"created_time": "2022-02-23T09:54:00.000Z",
8+
"last_edited_time": "2022-02-23T09:54:00.000Z",
9+
"created_by": {
10+
"object": "user",
11+
"id": "c6c84f05-e202-41a2-8653-dd26ca8757f8"
12+
},
13+
"last_edited_by": {
14+
"object": "user",
15+
"id": "c6c84f05-e202-41a2-8653-dd26ca8757f8"
16+
},
17+
"has_children": true,
18+
"archived": false,
19+
"type": "column",
20+
"column": {}
21+
}
22+
],
23+
"next_cursor": null,
24+
"has_more": false
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"object": "block",
3+
"id": "359244aa-d0bf-43a0-aa32-87a3afba908d",
4+
"created_time": "2022-02-23T09:54:00.000Z",
5+
"last_edited_time": "2022-02-23T09:54:00.000Z",
6+
"created_by": {
7+
"object": "user",
8+
"id": "c6c84f05-e202-41a2-8653-dd26ca8757f8"
9+
},
10+
"last_edited_by": {
11+
"object": "user",
12+
"id": "c6c84f05-e202-41a2-8653-dd26ca8757f8"
13+
},
14+
"has_children": true,
15+
"archived": false,
16+
"type": "synced_block",
17+
"synced_block": {
18+
"synced_from": null
19+
}
20+
}

0 commit comments

Comments
 (0)