-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* perf: version list type * perf: add node default value * perf: snapshot status * fix: version detail auth * fix: export defalt
- Loading branch information
Showing
24 changed files
with
750 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import '@/pages/api/__mocks__/base'; | ||
import { root } from '@/pages/api/__mocks__/db/init'; | ||
import { getTestRequest } from '@/test/utils'; | ||
import { AppErrEnum } from '@fastgpt/global/common/error/code/app'; | ||
import handler from './demo'; | ||
|
||
// Import the schema | ||
import { MongoOutLink } from '@fastgpt/service/support/outLink/schema'; | ||
|
||
beforeAll(async () => { | ||
// await MongoOutLink.create({ | ||
// shareId: 'aaa', | ||
// appId: root.appId, | ||
// tmbId: root.tmbId, | ||
// teamId: root.teamId, | ||
// type: 'share', | ||
// name: 'aaa' | ||
// }) | ||
}); | ||
|
||
test('Should return a list of outLink', async () => { | ||
// Mock request | ||
const res = (await handler( | ||
...getTestRequest({ | ||
query: { | ||
appId: root.appId, | ||
type: 'share' | ||
}, | ||
user: root | ||
}) | ||
)) as any; | ||
|
||
expect(res.code).toBe(200); | ||
expect(res.data.length).toBe(2); | ||
}); | ||
|
||
test('appId is required', async () => { | ||
const res = (await handler( | ||
...getTestRequest({ | ||
query: { | ||
type: 'share' | ||
}, | ||
user: root | ||
}) | ||
)) as any; | ||
expect(res.code).toBe(500); | ||
expect(res.error).toBe(AppErrEnum.unExist); | ||
}); | ||
|
||
test('if type is not provided, return nothing', async () => { | ||
const res = (await handler( | ||
...getTestRequest({ | ||
query: { | ||
appId: root.appId | ||
}, | ||
user: root | ||
}) | ||
)) as any; | ||
expect(res.code).toBe(200); | ||
expect(res.data.length).toBe(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next'; | ||
import { NextAPI } from '@/service/middleware/entry'; | ||
|
||
export type demoQuery = {}; | ||
|
||
export type demoBody = {}; | ||
|
||
export type demoResponse = {}; | ||
|
||
async function handler( | ||
req: ApiRequestProps<demoBody, demoQuery>, | ||
res: ApiResponseType<any> | ||
): Promise<demoResponse> { | ||
return {}; | ||
} | ||
|
||
export default NextAPI(handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import '@/pages/api/__mocks__/base'; | ||
import { root } from '@/pages/api/__mocks__/db/init'; | ||
import { getTestRequest } from '@/test/utils'; | ||
import handler, { versionListBody, versionListResponse } from './list'; | ||
|
||
// Import the schema | ||
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema'; | ||
|
||
const total = 22; | ||
|
||
beforeAll(async () => { | ||
const arr = new Array(total).fill(0); | ||
await MongoAppVersion.insertMany( | ||
arr.map((_, index) => ({ | ||
appId: root.appId, | ||
nodes: [], | ||
edges: [], | ||
chatConfig: {}, | ||
isPublish: index % 2 === 0, | ||
versionName: `v` + index, | ||
tmbId: root.tmbId, | ||
time: new Date(index * 1000) | ||
})) | ||
); | ||
}); | ||
|
||
test('Get version list and check', async () => { | ||
const offset = 0; | ||
const pageSize = 10; | ||
|
||
const _res = (await handler( | ||
...getTestRequest<{}, versionListBody>({ | ||
body: { | ||
offset, | ||
pageSize, | ||
appId: root.appId | ||
}, | ||
user: root | ||
}) | ||
)) as any; | ||
const res = _res.data as versionListResponse; | ||
|
||
expect(res.total).toBe(total); | ||
expect(res.list.length).toBe(pageSize); | ||
expect(res.list[0].versionName).toBe('v21'); | ||
expect(res.list[9].versionName).toBe('v12'); | ||
}); | ||
|
||
test('Get version list with offset 20', async () => { | ||
const offset = 20; | ||
const pageSize = 10; | ||
|
||
const _res = (await handler( | ||
...getTestRequest<{}, versionListBody>({ | ||
body: { | ||
offset, | ||
pageSize, | ||
appId: root.appId | ||
}, | ||
user: root | ||
}) | ||
)) as any; | ||
const res = _res.data as versionListResponse; | ||
|
||
expect(res.total).toBe(total); | ||
expect(res.list.length).toBe(2); | ||
expect(res.list[0].versionName).toBe('v1'); | ||
expect(res.list[1].versionName).toBe('v0'); | ||
}); |
25 changes: 12 additions & 13 deletions
25
...p/src/pages/api/core/app/version/list.tsx → ...pp/src/pages/api/core/app/version/list.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.