Skip to content

Commit c71ae64

Browse files
committed
feat: update launch configuration for Vitest and add county test cases
1 parent d1022ae commit c71ae64

4 files changed

Lines changed: 55 additions & 23 deletions

File tree

.vscode/launch.json

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
{
2-
// 使用 IntelliSense 以得知可用的屬性。
3-
// 暫留以檢視現有屬性的描述。
4-
// 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387
5-
"version": "0.2.0",
6-
"configurations": [
7-
8-
{
9-
"type": "pwa-node",
10-
"request": "launch",
11-
"name": "run test",
12-
"skipFiles": [
13-
"<node_internals>/**"
14-
],
15-
"program": "${workspaceFolder}\\test\\DataService.test.ts",
16-
"outFiles": [
17-
"${workspaceFolder}/**/*.js"
18-
]
19-
}
20-
]
21-
}
2+
// 使用 IntelliSense 以得知可用的屬性。
3+
// 暫留以檢視現有屬性的描述。
4+
// 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Vitest: Debug Current File",
11+
"program": "${workspaceFolder}/node_modules/vitest/vitest.mjs",
12+
"args": ["run", "${relativeFile}"],
13+
"smartStep": true,
14+
"console": "integratedTerminal"
15+
}
16+
]
17+
}

test/DataService.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ describe('DataService', () => {
1717
service = new DataService();
1818
});
1919

20-
it('get datas', async () => {
21-
const datas = await service.getData(token, baseId, 'contact');
20+
it('get data', async () => {
21+
const data = await service.getData(token, baseId, 'contact');
2222

23-
expect(datas.length).not.toEqual(0);
23+
expect(data.length).not.toEqual(0);
2424
});
2525

2626
it('add data', async () => {

test/county.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { config } from 'dotenv';
2+
import { describe, expect, it, beforeEach } from 'vitest';
3+
import { BaseModel } from '../src/dtos/BaseModel';
4+
import { DataService } from '../src';
5+
import { AirtableDeletion, AirtableResult } from '../src/dtos';
6+
7+
config();
8+
9+
const token = process.env.AIRTABLE_API ?? '';
10+
const baseId = 'appYytqUfVu81cjXn';
11+
12+
describe('DataService', () => {
13+
let service: DataService;
14+
let countyResult: BaseModel[] = [];
15+
16+
beforeEach(() => {
17+
service = new DataService();
18+
});
19+
20+
it('get county', async () => {
21+
countyResult = await service.getData(token, baseId, 'county');
22+
23+
expect(countyResult).not.toBeUndefined();
24+
expect(countyResult.length).toBeGreaterThan(0);
25+
});
26+
27+
it('get distinct with options', async () => {
28+
const distincts = await service.getData(token, baseId, 'distinct', {
29+
filterByFormula: `countyCode=${countyResult[0].countyCode}`,
30+
});
31+
32+
expect(distincts).not.toBeUndefined();
33+
expect(distincts.length).toBeGreaterThan(0);
34+
});
35+
});

vitest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default defineConfig({
44
test: {
55
globals: false,
66
environment: 'node',
7+
testTimeout: 200000,
78
coverage: {
89
reporter: ['text', 'lcov'],
910
exclude: [

0 commit comments

Comments
 (0)