Files
Genarrative/scripts/repair-auth-public-user-codes.test.ts
kdletters 387a1c26e3 完成全量检查整改
清理已跟踪原始日志与个人本地配置
修复前后端有效门禁、测试和构建问题
补齐生产 Jenkins、SpacetimeDB 本地命令与文档约束
收紧图片编辑器状态、附件与媒体引用测试
排除已下线旧创作入口测试并清理 warning
2026-07-17 16:56:46 +08:00

114 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { repairAuthPublicUserCodesInMigration } from './repair-auth-public-user-codes.mjs';
function table(name: string, rows: unknown[]) {
return { name, rows };
}
describe('repairAuthPublicUserCodesInMigration', () => {
it('keeps the first public code and reassigns duplicate codes and usernames', () => {
const migration = {
schema_version: 7,
exported_at_micros: 1,
tables: [
table('user_account', [
{
user_id: 'user_a',
public_user_code: 'SY-00000007',
username: 'phone_00000008',
login_method: 'phone',
},
{
user_id: 'user_b',
public_user_code: 'SY-00000007',
username: 'phone_00000008',
login_method: 'phone',
},
{
user_id: 'user_c',
public_user_code: 'SY00000009',
username: 'phone_00000010',
login_method: 'phone',
},
]),
table('auth_identity', [{ identity_id: 'authi_phone_1' }]),
],
};
const result = repairAuthPublicUserCodesInMigration(migration);
expect(result.migration.tables).toHaveLength(1);
expect(result.migration.tables[0].name).toBe('user_account');
expect(result.migration.tables[0].rows).toMatchObject([
{
user_id: 'user_a',
public_user_code: 'SY-00000007',
username: 'phone_00000008',
},
{
user_id: 'user_b',
public_user_code: 'SY-00000010',
username: 'phone_00000011',
},
{
user_id: 'user_c',
public_user_code: 'SY-00000009',
username: 'phone_00000010',
},
]);
expect(result.repairedRows).toEqual([
{
userId: 'user_b',
field: 'public_user_code',
from: 'SY-00000007',
to: 'SY-00000010',
},
{
userId: 'user_b',
field: 'username',
from: 'phone_00000008',
to: 'phone_00000011',
},
]);
});
it('assigns missing public codes without colliding with existing codes', () => {
const migration = {
schema_version: 7,
exported_at_micros: 1,
tables: [
table('user_account', [
{
user_id: 'user_a',
public_user_code: '',
username: '',
login_method: 'password',
},
{
user_id: 'user_b',
public_user_code: 'SY-00000002',
username: 'phone_00000003',
login_method: 'phone',
},
]),
],
};
const result = repairAuthPublicUserCodesInMigration(migration);
expect(result.migration.tables[0].rows).toMatchObject([
{
user_id: 'user_a',
public_user_code: 'SY-00000003',
username: 'phone_00000004',
},
{
user_id: 'user_b',
public_user_code: 'SY-00000002',
username: 'phone_00000003',
},
]);
});
});