190 lines
5.9 KiB
TypeScript
190 lines
5.9 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-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);
|
|
});
|
|
});
|