-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.ts
111 lines (85 loc) · 3 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import 'dotenv/config';
import { describe, it } from 'web-utility';
import {
BiDataTable,
BiTable,
BiTableView,
LarkApp,
SpreadSheetModel,
TableCellValue
} from '../src';
const {
APP_ID,
APP_SECRET,
SPREADSHEET_ID,
SHEET_ID,
BITABLE_ID,
BITABLE_TABLE_ID,
MEDIA_ID
} = process.env;
const app = new LarkApp({ id: APP_ID!, secret: APP_SECRET! });
describe('MobX Lark SDK', async () => {
await it('should get an Access Token', async expect => {
const token = await app.getAccessToken();
expect(/^t-\S+/.test(token));
});
const spreadSheet =
await it('should get a Sheet Meta of a Spread Sheet document', async expect => {
type Example = Record<'k1' | 'k2' | 'k3', any>;
class ExampleSheetModel extends SpreadSheetModel<Example> {
client = app.client;
offset: [number, number] = [1, 7];
columnKeys: (keyof Example)[] = ['k1', 'k2', 'k3'];
}
const spreadSheet = new ExampleSheetModel(
SPREADSHEET_ID!,
SHEET_ID!
);
await spreadSheet.getMeta();
const { meta } = spreadSheet;
expect(meta?.sheetId === SHEET_ID);
return spreadSheet;
});
await it('should get a page of rows in a sheet', async expect => {
const data = await spreadSheet.getList();
expect(
JSON.stringify(Object.keys(data[0])) ===
JSON.stringify(spreadSheet.columnKeys)
);
console.log(JSON.stringify(data, null, 4));
});
await it('should get a page of tables in a BITable document', async expect => {
class ExampleTableModel extends BiTable() {
client = app.client;
}
const biTable = new ExampleTableModel(BITABLE_ID!);
const [table] = await biTable.getList();
expect(typeof table.table_id === 'string');
return table!;
});
await it('should get a page of views in a BITable table', async expect => {
class ExampleTableViewModel extends BiTableView() {
client = app.client;
}
const tableView = new ExampleTableViewModel(
BITABLE_ID!,
BITABLE_TABLE_ID!
);
const [view] = await tableView.getList();
expect(['grid', 'form'].includes(view.view_type));
});
await it('should get a page of records in a BITable table', async expect => {
class ExampleDataTableModel extends BiDataTable<
Record<'id' | 'name' | 'type', TableCellValue>
>() {
client = app.client;
}
const table = new ExampleDataTableModel(BITABLE_ID!, BITABLE_TABLE_ID!);
const [record] = await table.getList();
expect(typeof record.id === 'string');
});
await it('should download a file', async expect => {
const file = await app.downloadFile(MEDIA_ID!);
expect(file.byteLength > 0);
});
}).finally(() => process.exit());