mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-07 01:02:55 +08:00
289da0f7b0
* sandbox-sync-agent * refactor: host pro as submodule * chore: checkpoint host pro restructure * refactor workspace test layout and startup init * chore: update next turbopack setup * chore: snapshot current work before actions fix * chore: update pro submodule * chore: point pro submodule url to upstream https * fix: Dockerfile * chore: update pro submodule * ci: support private pro submodule token and skip fork jobs * fix(ci): build sdk workspace deps before code-sandbox bundle * fix(app): exclude vitest configs from production typecheck * fix(app-image): build sdk packages before next build * fix(ci): align dockerfiles with workspace sdk build flow * chore(docker): upgrade node20 docker images to node24 * fix(ci): read admin coverage output path in pro test workflow * fix(app-image): include next-i18next config and locale assets * chore: update pro submodule * chore: do not specify branch for submodule * chore: remove most ts-nocheck sign * chore: update pro submodule * chore: remove sandbox-agent-sync package * chore: do not modify "pushData" file logic * fix: health check * chore: restore dev axios proxy state * fix: test-fastgpt report workflow * fix: use valid vitest coverage action inputs
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { ModelPermission } from '@fastgpt/global/support/permission/model/controller';
|
|
import {
|
|
NullRoleVal,
|
|
ReadRoleVal,
|
|
WriteRoleVal,
|
|
ManageRoleVal
|
|
} from '@fastgpt/global/support/permission/constant';
|
|
|
|
describe('permission/model/controller', () => {
|
|
describe('ModelPermission', () => {
|
|
it('should create ModelPermission with default role', () => {
|
|
const perm = new ModelPermission();
|
|
|
|
expect(perm.role).toBe(NullRoleVal);
|
|
expect(perm.isOwner).toBe(false);
|
|
});
|
|
|
|
it('should create ModelPermission with read role', () => {
|
|
const perm = new ModelPermission({ role: ReadRoleVal });
|
|
|
|
expect(perm.role).toBe(ReadRoleVal);
|
|
expect(perm.hasReadPer).toBe(true);
|
|
expect(perm.hasReadRole).toBe(true);
|
|
});
|
|
|
|
it('should create ModelPermission with write role', () => {
|
|
const perm = new ModelPermission({ role: WriteRoleVal });
|
|
|
|
expect(perm.role).toBe(WriteRoleVal);
|
|
expect(perm.hasWritePer).toBe(true);
|
|
expect(perm.hasWriteRole).toBe(true);
|
|
expect(perm.hasReadPer).toBe(true);
|
|
});
|
|
|
|
it('should create ModelPermission with manage role', () => {
|
|
const perm = new ModelPermission({ role: ManageRoleVal });
|
|
|
|
expect(perm.role).toBe(ManageRoleVal);
|
|
expect(perm.hasManagePer).toBe(true);
|
|
expect(perm.hasManageRole).toBe(true);
|
|
expect(perm.hasWritePer).toBe(true);
|
|
expect(perm.hasReadPer).toBe(true);
|
|
});
|
|
|
|
it('should create ModelPermission as owner', () => {
|
|
const perm = new ModelPermission({ isOwner: true });
|
|
|
|
expect(perm.isOwner).toBe(true);
|
|
expect(perm.hasManagePer).toBe(true);
|
|
expect(perm.hasWritePer).toBe(true);
|
|
expect(perm.hasReadPer).toBe(true);
|
|
});
|
|
|
|
it('should support addRole method', () => {
|
|
const perm = new ModelPermission({ role: ReadRoleVal });
|
|
|
|
expect(perm.hasWriteRole).toBe(false);
|
|
|
|
perm.addRole(WriteRoleVal);
|
|
|
|
expect(perm.hasWriteRole).toBe(true);
|
|
expect(perm.hasReadRole).toBe(true);
|
|
});
|
|
|
|
it('should support removeRole method', () => {
|
|
const perm = new ModelPermission({ role: ReadRoleVal | WriteRoleVal });
|
|
|
|
expect(perm.hasWriteRole).toBe(true);
|
|
|
|
perm.removeRole(WriteRoleVal);
|
|
|
|
expect(perm.hasWriteRole).toBe(false);
|
|
expect(perm.hasReadRole).toBe(true);
|
|
});
|
|
});
|
|
});
|