mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 23:49:27 +08:00
test: sub app agent (#5963)
* test: sub agent * chore: test --------- Co-authored-by: Chareice <chareice@live.com>
This commit is contained in:
parent
c77a8a35ff
commit
a89269d25a
@ -111,9 +111,10 @@ export class MockServer extends Application {
|
|||||||
await AppSupervisor.getInstance().destroy();
|
await AppSupervisor.getInstance().destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
agent(): ExtendedAgent {
|
agent(callback?): ExtendedAgent {
|
||||||
const agent = supertest.agent(this.callback());
|
const agent = supertest.agent(callback || this.callback());
|
||||||
const prefix = this.resourcer.options.prefix;
|
const prefix = this.resourcer.options.prefix;
|
||||||
|
|
||||||
const proxy = new Proxy(agent, {
|
const proxy = new Proxy(agent, {
|
||||||
get(target, method: string, receiver) {
|
get(target, method: string, receiver) {
|
||||||
if (['login', 'loginUsingId'].includes(method)) {
|
if (['login', 'loginUsingId'].includes(method)) {
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* This file is part of the NocoBase (R) project.
|
||||||
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||||
|
* Authors: NocoBase Team.
|
||||||
|
*
|
||||||
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||||
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createMockServer, MockServer } from '@nocobase/test';
|
||||||
|
import { AppSupervisor } from '@nocobase/server';
|
||||||
|
|
||||||
|
describe('sub app', async () => {
|
||||||
|
let app: MockServer;
|
||||||
|
let agent: any;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
app = await createMockServer({
|
||||||
|
plugins: ['multi-app-manager', 'client', 'ui-schema-storage', 'system-settings'],
|
||||||
|
});
|
||||||
|
await app.db.getRepository('applications').create({
|
||||||
|
values: {
|
||||||
|
name: 'test_sub',
|
||||||
|
options: {
|
||||||
|
plugins: ['client', 'ui-schema-storage', 'system-settings'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
context: {
|
||||||
|
waitSubAppInstall: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
agent = app.agent();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await app.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sub agent', async () => {
|
||||||
|
const res = await agent.get('/app:getInfo');
|
||||||
|
expect(res.body.data.name).toBe('main');
|
||||||
|
|
||||||
|
const subApp = await AppSupervisor.getInstance().getApp('test_sub');
|
||||||
|
|
||||||
|
const res1 = await app.agent(subApp.callback()).get('/api/app:getInfo');
|
||||||
|
expect(res1.body.data.name).toBe('test_sub');
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user