feat(api): add Riot webhook
This commit is contained in:
1 parent
d6f52a8b15
commit
9f6974c577
2 files changed
+109
No files matched your search
@@ -0,0 +1,60 @@
|
||||
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 },
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user