183e08ec80
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 48s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m10s
Decouple the displayed opponent name from the small pool of durable robot accounts: the disguised auto-match robot now gets a freshly composed name each game, stamped on a new game_players.display_name seat snapshot. The snapshot also captures humans' names, freezing what an opponent sees for the life of a game (a later rename no longer rewrites past games); readers fall back to the account's current name for pre-migration rows. Names come from a wide composed corpus (internal/robot/namevariety.go): Western locales (EN/DE/ES/IT/FR/PT), native Japanese/Chinese names, a gender-agreed Russian pool, and human-style handles. Routing keeps Pick's spirit -- a Russian game draws Cyrillic + <=20% Latin and never a CJK script; an English game the full corpus -- via robot.PickNamed. Loosen account.ValidateDisplayName (and the UI mirror) to admit a trailing run of up to five digits, so "Player2007"-style handles are valid for humans too and the disguised robot stays indistinguishable. Migration 00007 adds game_players.display_name (additive, NOT NULL DEFAULT ''); jet regenerated. Docs (ARCHITECTURE 7, FUNCTIONAL + _ru, PLAN, README) updated.
64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { awayDurationOk, browserOffset, isOffsetZone, validDisplayName, validEmail } from './profileValidation';
|
|
|
|
describe('validDisplayName', () => {
|
|
it.each([
|
|
['Kaya', true],
|
|
['Кая', true],
|
|
['Name_P. Last', true],
|
|
['Mr.Smith', true],
|
|
['Mr. Smith', true],
|
|
[' Kaya ', true],
|
|
['Name P._Last', false],
|
|
['Name Last', false],
|
|
['_Name', false],
|
|
['Anna B.', true],
|
|
['Name.', true],
|
|
['Name..', false],
|
|
['Name_', false],
|
|
['Name2', true], // a trailing digit is allowed
|
|
['Аня2007', true], // a trailing year
|
|
['Player12345', true], // 5 trailing digits — the max
|
|
['Player123456', false], // 6 trailing digits — over the limit
|
|
['Dark2Wolf', false], // a digit in the middle
|
|
['12345', false], // must start with a letter
|
|
['Name2.', false], // digits and a trailing dot cannot combine
|
|
['Anna B.2', false], // a trailing dot and digits cannot combine
|
|
['Night.Fox2007', true], // one "." special; digits do not count
|
|
['a.a.a.a.a.a2007', true], // 5 dots + a digit run still passes
|
|
['', false],
|
|
['a'.repeat(33), false],
|
|
['a.a.a.a.a.a', true], // 5 dots — at the special-char limit
|
|
['a.a.a.a.a.a.a', false], // 6 dots — over the limit
|
|
['J. R. R. Tolkien', true], // 3 dots; spaces are not special
|
|
])('%s -> %s', (name, ok) => {
|
|
expect(validDisplayName(name)).toBe(ok);
|
|
});
|
|
});
|
|
|
|
describe('validEmail', () => {
|
|
it('accepts a normal address', () => expect(validEmail('you@example.com')).toBe(true));
|
|
it('rejects a missing domain', () => expect(validEmail('you@')).toBe(false));
|
|
it('rejects spaces', () => expect(validEmail('a b@x.com')).toBe(false));
|
|
});
|
|
|
|
describe('awayDurationOk', () => {
|
|
it.each([
|
|
['22:00', '06:00', true],
|
|
['00:00', '12:00', true],
|
|
['08:00', '21:00', false],
|
|
['07:00', '07:00', true],
|
|
['20:00', '09:00', false],
|
|
])('%s-%s -> %s', (s, e, ok) => expect(awayDurationOk(s, e)).toBe(ok));
|
|
});
|
|
|
|
describe('timezone helpers', () => {
|
|
it('detects offset zones', () => {
|
|
expect(isOffsetZone('+03:00')).toBe(true);
|
|
expect(isOffsetZone('Europe/Moscow')).toBe(false);
|
|
});
|
|
it('formats the browser offset as ±HH:MM', () => {
|
|
expect(browserOffset()).toMatch(/^[+-]\d{2}:\d{2}$/);
|
|
});
|
|
});
|