Files
lolympus-tournament-support/apps/api/src/modules/dakao/parsers/command.parser.spec.ts
T
dahyeon 4b8ccf0077 fix: harden result polling and Redis 8.10 operations
Preserve tournament result jobs through lock contention and transient failures,
atomically schedule retries before acknowledgement, and publish initial polls
after releasing the preparation lock.

Fix Redis connection blocking, durability Hash cleanup, duplicate auction
request ordering, and scheduled-job promotion. Use native Redis 8.10 stream,
lock, counter, and field-expiring cache operations with invalidation fencing.

Repair 90 test type errors and add a repeatable API typecheck command.

Validation: 704 API tests, 129 web tests, 31 real Redis integration tests,
3 dependency checks, workspace type checks and builds, and changed-file lint.
2026-11-09 17:33:13 +09:00

203 lines
6.3 KiB
TypeScript

import { CommandParseError, parseCommand } from './command.parser';
describe('parseCommand', () => {
it('parses data transfer with the complete previous nickname', () => {
expect(parseCommand(' !내전 데이터이관 예전 닉.* ')).toEqual({
kind: 'data-transfer',
previousNickname: '예전 닉.*',
});
});
it('requires a previous nickname for data transfer', () => {
expect(() => parseCommand('!내전 데이터이관 ')).toThrow(
new CommandParseError('usage'),
);
});
it('parses match-list command (목록)', () => {
expect(parseCommand('!내전 목록')).toEqual({ kind: 'match-list' });
});
it('parses match-list command (리스트)', () => {
expect(parseCommand('!내전 리스트')).toEqual({ kind: 'match-list' });
});
it('parses match-list command (일정)', () => {
expect(parseCommand('!내전 일정')).toEqual({ kind: 'match-list' });
});
it('parses match-join command with simple riot id', () => {
const result = parseCommand(
'!내전 신청 69b63bc96da18dfdb218ee8c 프리리#KR1 미드,탑',
);
expect(result).toMatchObject({
kind: 'match-join',
matchAndRiotId: '69b63bc96da18dfdb218ee8c 프리리#KR1',
});
if (result.kind === 'match-join') {
expect(result.positions?.positions).toEqual(['MID', 'TOP']);
}
});
it('handles riot game name with spaces', () => {
const result = parseCommand(
'!내전 신청 69b63bc96da18dfdb218ee8c hello world#KR1 미드,서폿',
);
expect(result).toMatchObject({
kind: 'match-join',
matchAndRiotId: '69b63bc96da18dfdb218ee8c hello world#KR1',
});
});
it('parses hidden unicode differences in riot id input', () => {
const decomposedGameName = '프리리'.normalize('NFD');
const result = parseCommand(
`!내전 신청 69b63bc96da18dfdb218ee8c ${decomposedGameName}\u200B#KR1\uFEFF 미드,탑`,
);
expect(result).toMatchObject({
kind: 'match-join',
matchAndRiotId: `69b63bc96da18dfdb218ee8c ${decomposedGameName}\u200B#KR1`,
});
});
it('parses match-join command without explicit match id', () => {
const result = parseCommand('!내전 신청 프리리#KR1 미드,탑');
expect(result).toMatchObject({
kind: 'match-join',
matchAndRiotId: '프리리#KR1',
});
});
it('parses match-join command with title prefix', () => {
const result = parseCommand('!내전 신청 저녁 프리리#KR1 미드,탑');
expect(result).toMatchObject({
kind: 'match-join',
matchAndRiotId: '저녁 프리리#KR1',
});
});
it('parses abbreviated match-join command with only match code', () => {
expect(parseCommand('!내전 신청 cab1')).toEqual({
kind: 'match-join',
matchAndRiotId: 'cab1',
});
});
it('parses match-join command with registered account and explicit positions', () => {
const result = parseCommand('!내전 신청 cab1 미드,서포터');
expect(result).toMatchObject({
kind: 'match-join',
matchAndRiotId: 'cab1',
});
if (result.kind === 'match-join') {
expect(result.positions?.positions).toEqual(['MID', 'SUP']);
}
});
it('parses preferred position registration command', () => {
const result = parseCommand('!내전 선호포지션등록 미드,SPT');
expect(result).toMatchObject({
kind: 'preferred-position-register',
});
if (result.kind === 'preferred-position-register') {
expect(result.positions.positions).toEqual(['MID', 'SUP']);
}
});
it('parses match-cancel command (취소)', () => {
expect(parseCommand('!내전 취소 69b63bc96da18dfdb218ee8c')).toEqual({
kind: 'match-cancel',
matchId: '69b63bc96da18dfdb218ee8c',
});
});
it('parses match-cancel command (참가취소)', () => {
expect(parseCommand('!내전 참가취소 69b63bc96da18dfdb218ee8c')).toEqual({
kind: 'match-cancel',
matchId: '69b63bc96da18dfdb218ee8c',
});
});
it('parses match-cancel command with short code', () => {
expect(parseCommand('!내전 취소 AB12')).toEqual({
kind: 'match-cancel',
matchId: 'AB12',
});
});
it('parses account register command', () => {
expect(parseCommand('!내전 계정등록 hello world#KR1')).toEqual({
kind: 'account-register',
gameName: 'hello world',
tagLine: 'KR1',
});
});
it('parses primary account change command', () => {
expect(parseCommand('!내전 대표계정변경 프리리#KR1')).toEqual({
kind: 'primary-account-change',
gameName: '프리리',
tagLine: 'KR1',
});
});
it('normalizes primary account change riot id', () => {
const decomposedGameName = '프리리'.normalize('NFD');
expect(
parseCommand(`!내전 대표계정변경 ${decomposedGameName}\u200B#KR1\uFEFF`),
).toEqual({
kind: 'primary-account-change',
gameName: '프리리',
tagLine: 'KR1',
});
});
it('normalizes account register riot id', () => {
const decomposedGameName = '프리리'.normalize('NFD');
expect(
parseCommand(`!내전 계정등록 ${decomposedGameName}\u200B#KR1\uFEFF`),
).toEqual({
kind: 'account-register',
gameName: '프리리',
tagLine: 'KR1',
});
});
it('throws not_a_command for non-prefix messages', () => {
expect(() => parseCommand('안녕하세요')).toThrow(/not_a_command/);
});
it('throws usage for bare command prefix', () => {
expect(() => parseCommand('!내전')).toThrow(/usage/);
});
it('throws unknown_command for unrecognized subcommands', () => {
expect(() => parseCommand('!내전 폭파')).toThrow(/unknown_command/);
});
it('allows non-objectid join match reference for title matching', () => {
expect(
parseCommand('!내전 신청 not-an-id 프리리#KR1 미드,탑'),
).toMatchObject({
kind: 'match-join',
matchAndRiotId: 'not-an-id 프리리#KR1',
});
});
it('allows match-join without riot id for registered-account flow', () => {
expect(
parseCommand('!내전 신청 69b63bc96da18dfdb218ee8c 미드,탑'),
).toMatchObject({
kind: 'match-join',
matchAndRiotId: '69b63bc96da18dfdb218ee8c',
});
});
it('throws invalid_position for too few positions', () => {
expect(() => {
parseCommand('!내전 신청 69b63bc96da18dfdb218ee8c 프리리#KR1 미드');
}).toThrow(CommandParseError);
});
});