Files
lolympus-tournament-support/apps/api/src/modules/riot/riot-webhook.controller.spec.ts
T
2026-04-09 01:24:00 +09:00

61 lines
1.7 KiB
TypeScript

import type { Request } from 'express';
import { RiotWebhookController } from './riot-webhook.controller';
type RiotWebhookRequest = Request & {
rawBody?: Buffer;
};
describe('RiotWebhookController', () => {
let controller: RiotWebhookController;
beforeEach(() => {
controller = new RiotWebhookController();
});
afterEach(() => {
jest.restoreAllMocks();
});
it('logs the incoming webhook payload and returns an acknowledgement', () => {
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined);
const dirSpy = jest.spyOn(console, 'dir').mockImplementation(() => undefined);
const request = {
method: 'POST',
originalUrl: '/riot/webhooks/tournament',
protocol: 'https',
hostname: 'example.test',
ip: '127.0.0.1',
ips: ['127.0.0.1'],
headers: {
'content-type': 'application/json',
},
query: {
shard: 'kr',
},
params: {},
body: {
eventType: 'MATCH_FINISHED',
},
rawBody: Buffer.from('{"eventType":"MATCH_FINISHED"}', 'utf8'),
} as unknown as RiotWebhookRequest;
const response = controller.captureTournamentWebhook(request);
expect(response.ok).toBe(true);
expect(response.message).toBe('Riot webhook received.');
expect(response.receivedAt).toEqual(expect.any(String));
expect(logSpy).toHaveBeenCalledTimes(2);
expect(dirSpy).toHaveBeenCalledWith(
expect.objectContaining({
method: 'POST',
url: '/riot/webhooks/tournament',
body: {
eventType: 'MATCH_FINISHED',
},
rawBodyText: '{"eventType":"MATCH_FINISHED"}',
}),
{ depth: null },
);
});
});