mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
* feat: team permission refine (#4402) * chore: team permission extend * feat: manage team permission * chore: api auth * fix: i18n * feat: add initv493 * fix: test, org auth manager * test: app test for refined permission * update init sh * fix: add/remove manage permission (#4427) * fix: add/remove manage permission * fix: github action fastgpt-test * fix: mock create model * fix: team write permission * fix: ts * account permission --------- Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
This commit is contained in:
@@ -1,31 +1,22 @@
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import mongoose from '@fastgpt/service/common/mongo';
|
||||
import { connectMongo } from '@fastgpt/service/common/mongo/init';
|
||||
import {
|
||||
connectionMongo,
|
||||
connectionLogMongo,
|
||||
MONGO_URL,
|
||||
MONGO_LOG_URL
|
||||
} from '@fastgpt/service/common/mongo';
|
||||
import { initGlobalVariables } from '@/service/common/system';
|
||||
import { afterAll, beforeAll, vi } from 'vitest';
|
||||
import { setup, teardown } from 'vitest-mongodb';
|
||||
import setupModels from './setupModels';
|
||||
import './mocks';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import { connectMongo } from '@fastgpt/service/common/mongo/init';
|
||||
import { initGlobalVariables } from '@/service/common/system';
|
||||
import { afterAll, beforeAll, beforeEach, inject, vi } from 'vitest';
|
||||
import setupModels from './setupModels';
|
||||
import { clean } from './datas/users';
|
||||
import { connectionLogMongo, connectionMongo, Mongoose } from '@fastgpt/service/common/mongo';
|
||||
import { randomUUID } from 'crypto';
|
||||
|
||||
vi.stubEnv('NODE_ENV', 'test');
|
||||
vi.mock(import('@fastgpt/service/common/mongo'), async (importOriginal) => {
|
||||
|
||||
vi.mock(import('@fastgpt/service/common/mongo/init'), async (importOriginal: any) => {
|
||||
const mod = await importOriginal();
|
||||
return {
|
||||
...mod,
|
||||
connectionMongo: await (async () => {
|
||||
if (!global.mongodb) {
|
||||
global.mongodb = mongoose;
|
||||
await global.mongodb.connect((globalThis as any).__MONGO_URI__ as string);
|
||||
}
|
||||
|
||||
return global.mongodb;
|
||||
})()
|
||||
connectMongo: async (db: Mongoose, url: string) => {
|
||||
(await db.connect(url)).connection.useDb(randomUUID());
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -59,18 +50,12 @@ vi.mock(import('@/service/common/system'), async (importOriginal) => {
|
||||
});
|
||||
|
||||
beforeAll(async () => {
|
||||
await setup({
|
||||
type: 'replSet',
|
||||
serverOptions: {
|
||||
replSet: {
|
||||
count: 1
|
||||
}
|
||||
}
|
||||
});
|
||||
vi.stubEnv('MONGODB_URI', (globalThis as any).__MONGO_URI__);
|
||||
vi.stubEnv('MONGODB_URI', inject('MONGODB_URI'));
|
||||
await connectMongo(connectionMongo, inject('MONGODB_URI'));
|
||||
await connectMongo(connectionLogMongo, inject('MONGODB_URI'));
|
||||
|
||||
initGlobalVariables();
|
||||
await connectMongo(connectionMongo, MONGO_URL);
|
||||
await connectMongo(connectionLogMongo, MONGO_LOG_URL);
|
||||
global.systemEnv = {} as any;
|
||||
|
||||
// await getInitConfig();
|
||||
if (existsSync('projects/app/.env.local')) {
|
||||
@@ -83,13 +68,27 @@ beforeAll(async () => {
|
||||
systemEnv[key] = value;
|
||||
}
|
||||
}
|
||||
global.systemEnv = {} as any;
|
||||
global.systemEnv.oneapiUrl = systemEnv['OPENAI_BASE_URL'];
|
||||
global.systemEnv.chatApiKey = systemEnv['CHAT_API_KEY'];
|
||||
await setupModels();
|
||||
}
|
||||
global.feConfigs = {
|
||||
isPlus: false
|
||||
} as any;
|
||||
await setupModels();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await teardown();
|
||||
if (connectionMongo?.connection) connectionMongo?.connection.close();
|
||||
if (connectionLogMongo?.connection) connectionLogMongo?.connection.close();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await connectMongo(connectionMongo, inject('MONGODB_URI'));
|
||||
await connectMongo(connectionLogMongo, inject('MONGODB_URI'));
|
||||
|
||||
return async () => {
|
||||
clean();
|
||||
await connectionMongo?.connection.db?.dropDatabase();
|
||||
await connectionLogMongo?.connection.db?.dropDatabase();
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user