mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-08-25 20:46:31 +00:00
test(api-tokens): cover the token-name length cap
Export tokenNameSchema and pin the 100-character boundary (100 accepted, 101 rejected) plus its trim/default behavior. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
f5f7974826
commit
a87ac2db18
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { tokenNameSchema } from './settings-api-tokens';
|
||||
|
||||
describe('tokenNameSchema', () => {
|
||||
it('accepts a name at the 100-character boundary', () => {
|
||||
expect(tokenNameSchema.safeParse('a'.repeat(100)).success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects a name one character over the 100-character cap', () => {
|
||||
expect(tokenNameSchema.safeParse('a'.repeat(101)).success).toBe(false);
|
||||
});
|
||||
|
||||
it('trims surrounding whitespace before length-checking', () => {
|
||||
expect(tokenNameSchema.safeParse(` ${'a'.repeat(100)} `)).toMatchObject({
|
||||
data: 'a'.repeat(100),
|
||||
success: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults an omitted name to an empty string', () => {
|
||||
expect(tokenNameSchema.safeParse(undefined)).toMatchObject({ data: '', success: true });
|
||||
});
|
||||
});
|
||||
@@ -63,7 +63,7 @@ import { baseUrl } from '@/models/api';
|
||||
type APIToken = ApiTokenFragmentFragment;
|
||||
|
||||
// 100 mirrors the backend cap (server/models/api_tokens.go + the createAPIToken/updateAPIToken resolvers).
|
||||
const tokenNameSchema = z.string().trim().max(100, 'Token name must be 100 characters or less').default('');
|
||||
export const tokenNameSchema = z.string().trim().max(100, 'Token name must be 100 characters or less').default('');
|
||||
|
||||
const createTokenFormSchema = z.object({
|
||||
// Nullable in form input (the date picker starts empty); the refine gates
|
||||
|
||||
Reference in New Issue
Block a user