4.8.11 test (#2843)
* feat: app version test * update doc * fix: paging num error * fix: doc api domain * rename variable * perf: memment node min size
This commit is contained in:
55
projects/app/src/pages/api/core/app/version/latest.test.ts
Normal file
55
projects/app/src/pages/api/core/app/version/latest.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import '@/pages/api/__mocks__/base';
|
||||
import { root } from '@/pages/api/__mocks__/db/init';
|
||||
import { getTestRequest } from '@/test/utils';
|
||||
import handler, { getLatestVersionQuery, getLatestVersionResponse } from './latest';
|
||||
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema';
|
||||
|
||||
beforeAll(async () => {
|
||||
// 创建3个测试数据,其中2个是已发布的
|
||||
await MongoAppVersion.create([
|
||||
{
|
||||
appId: root.appId,
|
||||
nodes: [1],
|
||||
edges: [],
|
||||
chatConfig: {},
|
||||
isPublish: false,
|
||||
versionName: 'v1',
|
||||
tmbId: root.tmbId,
|
||||
time: new Date('2023-01-01')
|
||||
},
|
||||
{
|
||||
appId: root.appId,
|
||||
nodes: [2],
|
||||
edges: [],
|
||||
chatConfig: {},
|
||||
isPublish: true,
|
||||
versionName: 'v2',
|
||||
tmbId: root.tmbId,
|
||||
time: new Date('2023-01-02')
|
||||
},
|
||||
{
|
||||
appId: root.appId,
|
||||
nodes: [3],
|
||||
edges: [],
|
||||
chatConfig: {},
|
||||
isPublish: false,
|
||||
versionName: 'v3',
|
||||
tmbId: root.tmbId,
|
||||
time: new Date('2023-01-03')
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
test('获取最新版本并检查', async () => {
|
||||
const _res = (await handler(
|
||||
...getTestRequest<{}, getLatestVersionQuery>({
|
||||
query: {
|
||||
appId: root.appId
|
||||
},
|
||||
user: root
|
||||
})
|
||||
)) as any;
|
||||
const res = _res.data as getLatestVersionResponse;
|
||||
|
||||
expect(res.nodes[0]).toEqual(2);
|
||||
});
|
||||
37
projects/app/src/pages/api/core/app/version/publish.test.ts
Normal file
37
projects/app/src/pages/api/core/app/version/publish.test.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import '@/pages/api/__mocks__/base';
|
||||
import { root } from '@/pages/api/__mocks__/db/init';
|
||||
import { getTestRequest } from '@/test/utils';
|
||||
import handler from './publish';
|
||||
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema';
|
||||
import { PostPublishAppProps } from '@/global/core/app/api';
|
||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||
|
||||
describe('发布应用版本测试', () => {
|
||||
test('发布一个未发布的版本', async () => {
|
||||
const publishData: PostPublishAppProps = {
|
||||
nodes: [],
|
||||
edges: [],
|
||||
chatConfig: {},
|
||||
type: AppTypeEnum.simple,
|
||||
isPublish: false,
|
||||
versionName: '1'
|
||||
};
|
||||
|
||||
await handler(
|
||||
...getTestRequest<{ appId: string }, PostPublishAppProps>({
|
||||
body: publishData,
|
||||
query: { appId: root.appId },
|
||||
user: root
|
||||
})
|
||||
);
|
||||
|
||||
// 检查数据库是否插入成功
|
||||
const insertedVersion = await MongoAppVersion.countDocuments();
|
||||
|
||||
console.log(insertedVersion, '==-');
|
||||
|
||||
// expect(insertedVersion).toBeTruthy();
|
||||
// expect(insertedVersion?.isPublish).toBe(false);
|
||||
// expect(insertedVersion?.versionName).toBe('1');
|
||||
});
|
||||
});
|
||||
@@ -8,7 +8,6 @@ import { beforeUpdateAppFormat } from '@fastgpt/service/core/app/controller';
|
||||
import { getNextTimeByCronStringAndTimezone } from '@fastgpt/global/common/string/time';
|
||||
import { PostPublishAppProps } from '@/global/core/app/api';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse<any>): Promise<{}> {
|
||||
const { appId } = req.query as { appId: string };
|
||||
|
||||
Reference in New Issue
Block a user