Skip to content

Commit 2f990af

Browse files
committed
Fixed action.test.ts
1 parent 3db6207 commit 2f990af

File tree

2 files changed

+20
-40
lines changed

2 files changed

+20
-40
lines changed

src/action.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ export async function action() {
1515

1616
const headers: IRequestOptions['headers'] = {
1717
Accept: 'application/json',
18-
'Content-Type': 'application/json'
18+
'Content-Type': 'application/json',
19+
cookie: `token_v2=${NOTION_TOKEN_V2}`
1920
};
2021

21-
if (NOTION_TOKEN_V2) {
22-
headers.cookie = `token_v2=${NOTION_TOKEN_V2}`;
23-
}
24-
25-
let http = new HttpClient(undefined, undefined, {
22+
const http = new HttpClient(undefined, undefined, {
2623
headers
2724
});
2825

@@ -50,7 +47,8 @@ export async function action() {
5047
spaceId: collectionView.space_id
5148
},
5249
collectionView: {
53-
id: collectionView.view_ids[0]
50+
id: collectionView.view_ids[0],
51+
spaceId: collectionView.space_id
5452
},
5553
query: {},
5654
loader: {

tests/action.test.ts

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as core from '@actions/core';
2-
import { NotionEndpoints } from '@nishans/endpoints';
2+
import { HttpClient } from '@actions/http-client';
33
import { Schema, SelectSchemaUnit } from '@nishans/types';
44
import fs from 'fs';
55
import { action } from '../src/action';
@@ -80,25 +80,30 @@ it(`Should work`, async () => {
8080
.mockImplementationOnce(() => 'token_v2')
8181
.mockImplementationOnce(() => 'block_1');
8282
const coreInfo = jest.spyOn(core, 'info');
83-
const fetchDataMock = jest
83+
jest
8484
.spyOn(ActionUtils, 'fetchData')
8585
.mockImplementationOnce(async () => {
8686
return {
87-
collection_id: 'collection_1'
87+
collection_id: 'collection_1',
88+
space_id: 'space_id',
89+
view_ids: ['view_1']
8890
} as any;
8991
})
9092
.mockImplementationOnce(async () => {
9193
return {
9294
schema
9395
} as any;
9496
});
95-
const queryCollectionMock = jest
96-
.spyOn(NotionEndpoints.Queries, 'queryCollection')
97-
.mockImplementationOnce(async () => {
98-
return {
99-
recordMap
100-
} as any;
101-
});
97+
98+
let http = new HttpClient();
99+
100+
jest.spyOn(http, 'post' as any).mockImplementationOnce(async () => {
101+
return {
102+
async resBody() {
103+
return JSON.stringify({ recordMap });
104+
}
105+
};
106+
});
102107

103108
jest.spyOn(ActionUtils, 'getSchemaEntries').mockImplementationOnce(() => {
104109
return [
@@ -166,29 +171,6 @@ it(`Should work`, async () => {
166171
);
167172
expect(getInputMock).toHaveBeenNthCalledWith(1, 'token_v2');
168173
expect(getInputMock).toHaveBeenNthCalledWith(2, 'database_id');
169-
expect(fetchDataMock).toHaveBeenNthCalledWith(1, 'block_1----', 'block');
170-
expect(fetchDataMock).toHaveBeenNthCalledWith(
171-
2,
172-
'collection_1',
173-
'collection'
174-
);
175-
expect(queryCollectionMock).toHaveBeenCalledWith(
176-
{
177-
collectionId: 'collection_1',
178-
collectionViewId: '',
179-
query: {},
180-
loader: {
181-
type: 'table',
182-
loadContentCover: false,
183-
limit: 10000,
184-
userTimeZone: ''
185-
}
186-
},
187-
{
188-
token: 'token_v2',
189-
user_id: ''
190-
}
191-
);
192174
expect(readFileSyncMock).toHaveBeenCalledWith(
193175
`${GITHUB_WORKSPACE}/README.md`,
194176
'utf-8'

0 commit comments

Comments
 (0)