Files
lolympus-tournament-support/apps/api/src/modules/dakao/parsers/command.parser.spec.ts
T
2026-04-25 11:49:21 -07:00

77 lines
2.4 KiB
TypeScript

import { CommandParseError, parseCommand } from './command.parser';
describe('parseCommand', () => {
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',
matchId: '69b63bc96da18dfdb218ee8c',
gameName: '프리리',
tagLine: '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',
gameName: 'hello world',
tagLine: 'KR1',
});
});
it('normalizes hidden unicode differences in riot id', () => {
const decomposedGameName = '프리리'.normalize('NFD');
const result = parseCommand(
`!내전 신청 69b63bc96da18dfdb218ee8c ${decomposedGameName}\u200B#KR1\uFEFF 미드,탑`,
);
expect(result).toMatchObject({
kind: 'match-join',
gameName: '프리리',
tagLine: 'KR1',
});
});
it('throws not_a_command for non-prefix messages', () => {
expect(() => parseCommand('안녕하세요')).toThrow(/not_a_command/);
});
it('throws unknown_command for unrecognized subcommands', () => {
expect(() => parseCommand('!내전 폭파')).toThrow(/unknown_command/);
});
it('throws invalid_match_id for non-objectid match', () => {
expect(() =>
parseCommand('!내전 신청 not-an-id 프리리#KR1 미드,탑'),
).toThrow(/invalid_match_id/);
});
it('throws invalid_riot_id when # missing', () => {
expect(() =>
parseCommand('!내전 신청 69b63bc96da18dfdb218ee8c 프리리 미드,탑'),
).toThrow(/invalid_riot_id/);
});
it('throws invalid_position for too few positions', () => {
expect(() => {
parseCommand('!내전 신청 69b63bc96da18dfdb218ee8c 프리리#KR1 미드');
}).toThrow(CommandParseError);
});
});