From edac6e0c4b9cf316be566b858f22db352f8c1362 Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Fri, 3 Apr 2026 15:12:57 +0800 Subject: [PATCH] update helpers --- frontend/src/test/helpers.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 frontend/src/test/helpers.ts diff --git a/frontend/src/test/helpers.ts b/frontend/src/test/helpers.ts new file mode 100644 index 0000000..90b403c --- /dev/null +++ b/frontend/src/test/helpers.ts @@ -0,0 +1,10 @@ +/** 构造一个 fake JWT,payload 中包含给定 role */ +export function fakeJwtWithRole(role: string): string { + const header = btoa(JSON.stringify({ alg: 'HS256', typ: 'JWT' })) + const payload = btoa(JSON.stringify({ uid: 1, role, s: 'random' })) + return `${header}.${payload}.fake-signature` +} + +/** 通用有效 JWT token(accessor 角色),用于不关心具体角色的测试场景 */ +export const VALID_TOKEN = fakeJwtWithRole('accessor') +export const VALID_REFRESH_TOKEN = 'valid-refresh-token'