chore: test

This commit is contained in:
Chareice 2024-01-24 20:07:55 +08:00
parent 476d0b869c
commit 5d070fea64
No known key found for this signature in database
2 changed files with 31 additions and 2 deletions

View File

@ -5,7 +5,7 @@
"dependencies": {}, "dependencies": {},
"displayName": "Database source manager ", "displayName": "Database source manager ",
"displayName.zh-CN": "外部数据源管理", "displayName.zh-CN": "外部数据源管理",
"description": "Connect external data source to Nocobase", "description": "Connect external data source to NocoBase",
"description.zh-CN": "将外部数据源接入Nocobase", "description.zh-CN": "将外部数据源接入Nocobase",
"peerDependencies": { "peerDependencies": {
"@nocobase/client": "0.x", "@nocobase/client": "0.x",

View File

@ -1,4 +1,5 @@
import { createMockServer, MockServer } from '@nocobase/test'; import { createMockServer, MockServer } from '@nocobase/test';
import { DataSource } from '@nocobase/data-source-manager';
describe('data source', async () => { describe('data source', async () => {
let app: MockServer; let app: MockServer;
@ -13,5 +14,33 @@ describe('data source', async () => {
await app.destroy(); await app.destroy();
}); });
it('should create data source', async () => {}); it('should create data source', async () => {
const loadFn = vi.fn();
class MockDataSource extends DataSource {
async load(): Promise<void> {
loadFn();
}
createCollectionManager(options?: any): any {
return undefined;
}
}
app.dataSourceManager.factory.register('mock', MockDataSource);
await app.db.getRepository('dataSources').create({
values: {
key: 'mockInstance1',
type: 'mock',
displayName: 'Mock',
options: {},
},
});
expect(loadFn).toBeCalledTimes(1);
const mockDataSource = app.dataSourceManager.dataSources.get('mockInstance1');
expect(mockDataSource).toBeInstanceOf(MockDataSource);
});
}); });