import mongoose from 'mongoose'; import { DakaoUserError, DakaoUserService } from '../dakao-user.service'; import { AccountRegisterHandler } from './account-register.handler'; const objectId = (hex: string) => new mongoose.Types.ObjectId(hex); function makeHandler(dakaoUserService?: Partial) { return new AccountRegisterHandler({ registerRiotAccount: jest.fn(), ...dakaoUserService, } as unknown as DakaoUserService); } const baseParams = { communityId: objectId('111111111111111111111111'), senderUserId: 'kakao-user-1', senderNickname: '프리리', gameName: '프리리', tagLine: 'KR1', }; describe('AccountRegisterHandler', () => { it('registers a Riot account through DakaoUserService', async () => { const registerRiotAccount = jest.fn().mockResolvedValue({ user: { _id: objectId('222222222222222222222222') }, riotAccount: { gameName: '프리리', tagLine: 'KR1' }, }); const handler = makeHandler({ registerRiotAccount, }); const segments = await handler.handle(baseParams); expect(registerRiotAccount).toHaveBeenCalledWith({ communityId: baseParams.communityId, kakaoTalkId: 'kakao-user-1', kakaoTalkNickname: '프리리', gameName: '프리리', tagLine: 'KR1', }); expect(segments).toEqual([ expect.objectContaining({ kind: 'mention', userId: 'kakao-user-1' }), expect.objectContaining({ kind: 'text', text: expect.stringContaining('등록 계정: 프리리#KR1'), }), ]); }); it('translates Riot account conflict errors', async () => { const handler = makeHandler({ registerRiotAccount: jest .fn() .mockRejectedValue( new DakaoUserError('riot_account_conflict', '기존소환사#KR1'), ), }); const segments = await handler.handle(baseParams); expect(segments).toEqual([ expect.objectContaining({ kind: 'mention', userId: 'kakao-user-1' }), expect.objectContaining({ kind: 'text', text: expect.stringContaining('이미 다른 사용자가 등록한 라이엇 계정'), }), ]); expect(segments[1]).toMatchObject({ kind: 'text', text: expect.stringContaining('기존소환사#KR1'), }); }); });