Files
FastGPT/projects/app/src/test/utils.ts
Archer f89452acdd Group role (#2993)
* feat: app/dataset support group (#2898)

* pref: member-group (#2862)

* feat: group list ordered by updateTime

* fix: transfer ownership of group when deleting member

* fix: i18n fix

* feat: can not set member as admin/owner when user is not active

* fix: GroupInfoModal hover input do not change color

* fix(fe): searchinput do not scroll

* feat: app collaborator with group, remove default permission

* feat: dataset collaborator with group, remove default permission

* chore(test): pref mock

* chore: remove useless code

* chore: adjust

* fix: add self as collaborator when creating folder

* fix(fe): folder manage menu do not show when user has write permission
only

* fix: dataset folder create

* feat: Add code comment

* Pref: app move (#2952)

* perf: app schema

* doc

---------

Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
2024-10-25 19:39:11 +08:00

95 lines
1.8 KiB
TypeScript

import { ERROR_ENUM } from '@fastgpt/global/common/error/errorCode';
export type TestTokenType = {
userId: string;
teamId: string;
tmbId: string;
isRoot: boolean;
};
export type TestRequest = {
headers: {
cookie?: {
token?: TestTokenType;
};
authorization?: string; // testkey
rootkey?: string; // rootkey
};
query: {
[key: string]: string;
};
body: {
[key: string]: string;
};
};
export function getTestRequest<Q = any, B = any>({
query = {},
body = {},
authToken = true,
// authRoot = false,
// authApiKey = false,
user
}: {
query?: Partial<Q>;
body?: Partial<B>;
authToken?: boolean;
authRoot?: boolean;
authApiKey?: boolean;
user?: {
uid: string;
tmbId: string;
teamId: string;
isRoot: boolean;
};
}): [any, any] {
const headers: TestRequest['headers'] = {};
if (authToken) {
headers.cookie = {
token: {
userId: String(user?.uid || ''),
teamId: String(user?.teamId || ''),
tmbId: String(user?.tmbId || ''),
isRoot: user?.isRoot || false
}
};
}
return [
{
headers,
query,
body
},
{}
];
}
export const parseHeaderCertMock = async ({
req,
authToken = true,
authRoot = false,
authApiKey = false
}: {
req: TestRequest;
authToken?: boolean;
authRoot?: boolean;
authApiKey?: boolean;
}): Promise<TestTokenType> => {
if (authToken) {
const token = req.headers?.cookie?.token;
if (!token) {
return Promise.reject(ERROR_ENUM.unAuthorization);
}
return token;
}
// if (authRoot) {
// // TODO: unfinished
// return req.headers.rootkey;
// }
// if (authApiKey) {
// // TODO: unfinished
// return req.headers.authorization;
// }
return {} as any;
};