Files
game_voice_recorder/site/server/test/unknown-users.test.ts
EJClaw a4511a8eaf 사이트: 모르는 유저 다시 받기가 한 번 실패하면 영영 안 받던 문제
받는 중 중복만 막고, 실패하면 다음 이벤트에서 다시 받는다 (성공한 아이디만 기억).
lib/unknown-users.ts 로 빼고 테스트 추가, 목 서버에 /mock/users-fail · latejoin?again=1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 22:56:45 +09:00

52 lines
1.7 KiB
TypeScript

// 사이트 화면: 처음 보는 유저 아이디가 오면 유저 목록을 다시 받는 규칙 (site/web/src/lib/unknown-users.ts)
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { makeUnknownUserCheck } from '../../web/src/lib/unknown-users.ts';
const tick = () => new Promise((r) => setTimeout(r, 0));
test('모르는 유저: 받는 중에는 또 부르지 않고, 실패하면 다음 이벤트에서 다시 받는다', async () => {
const known = new Set(['a']);
let calls = 0;
let fail = true;
let release!: () => void;
const check = makeUnknownUserCheck(() => {
calls++;
return new Promise<void>((ok, no) => {
release = () => (fail ? no(new Error('500')) : (known.add('late'), ok()));
});
});
const has = (id: string) => known.has(id);
check(['a'], has);
assert.equal(calls, 0, '아는 사람은 부르지 않음');
check(['late'], has);
check(['late'], has);
assert.equal(calls, 1, '받는 중에는 한 번만');
release(); // 500
await tick();
check(['late'], has);
assert.equal(calls, 2, '실패 뒤 다음 발화에서 다시 받음');
fail = false;
release();
await tick();
assert.ok(known.has('late'));
check(['late'], has);
assert.equal(calls, 2, '받은 뒤에는 부르지 않음');
});
test('모르는 유저: 받았는데도 목록에 없는 아이디는 발화마다 다시 부르지 않는다', async () => {
let calls = 0;
const check = makeUnknownUserCheck(async () => {
calls++;
});
const has = () => false;
check(['ghost'], has);
await tick();
check(['ghost'], has);
check(['ghost', ''], has);
assert.equal(calls, 1);
check(['other'], has);
assert.equal(calls, 2, '다른 새 아이디는 다시 받음');
});