|
| 1 | +import { getConfig } from '../../../src/config'; |
| 2 | +import { initServer } from '../../../src/server'; |
| 3 | +import { StreamLabs } from '../../../src/services/StreamLabs'; |
| 4 | +import { TwitchChat } from '../../../src/services/TwitchChat'; |
| 5 | +import { MergeRequestPayloadBuilder } from '../../builders/payload/gitlab/merge-request-payload-builder'; |
| 6 | + |
| 7 | +describe('POST /gitlab', () => { |
| 8 | + let streamLabsSpy: jest.SpyInstance<Promise<void>>; |
| 9 | + let twitchChatSpy: jest.SpyInstance<Promise<void>>; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + streamLabsSpy = jest.spyOn(StreamLabs.prototype, 'alert'); |
| 13 | + streamLabsSpy.mockImplementationOnce(jest.fn()); |
| 14 | + |
| 15 | + twitchChatSpy = jest.spyOn(TwitchChat.prototype, 'send'); |
| 16 | + twitchChatSpy.mockImplementationOnce(jest.fn()); |
| 17 | + }); |
| 18 | + |
| 19 | + describe('Merge Request Hook', () => { |
| 20 | + it('handles merge request merged event', async () => { |
| 21 | + const subject = await initServer(getConfig()); |
| 22 | + const payload = new MergeRequestPayloadBuilder() |
| 23 | + .with({ object_attributes: { state: 'merged' } }) |
| 24 | + .getInstance(); |
| 25 | + |
| 26 | + const { result } = await subject.inject({ |
| 27 | + method: 'POST', |
| 28 | + url: '/gitlab', |
| 29 | + payload, |
| 30 | + headers: { 'x-gitlab-event': 'Merge Request Hook' }, |
| 31 | + }); |
| 32 | + |
| 33 | + expect(result).toEqual( |
| 34 | + expect.objectContaining({ |
| 35 | + messages: [ |
| 36 | + expect.objectContaining({ |
| 37 | + twitchChat: expect.anything(), |
| 38 | + streamlabs: expect.anything(), |
| 39 | + }), |
| 40 | + ], |
| 41 | + }), |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + it('handles merge request opened event', async () => { |
| 46 | + const subject = await initServer(getConfig()); |
| 47 | + const payload = new MergeRequestPayloadBuilder() |
| 48 | + .with({ object_attributes: { state: 'opened' } }) |
| 49 | + .getInstance(); |
| 50 | + |
| 51 | + const { result } = await subject.inject({ |
| 52 | + method: 'POST', |
| 53 | + url: '/gitlab', |
| 54 | + payload, |
| 55 | + headers: { 'x-gitlab-event': 'Merge Request Hook' }, |
| 56 | + }); |
| 57 | + |
| 58 | + expect(result).toEqual( |
| 59 | + expect.objectContaining({ |
| 60 | + messages: [ |
| 61 | + expect.objectContaining({ |
| 62 | + twitchChat: expect.anything(), |
| 63 | + streamlabs: expect.anything(), |
| 64 | + }), |
| 65 | + ], |
| 66 | + }), |
| 67 | + ); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments