|
| 1 | +import { ReleaseCreated } from '../../../src/reactions/github/release-created'; |
| 2 | +import { TwitchChatMock } from '../../__mocks__/TwitchChat'; |
| 3 | +import { StreamLabsMock } from '../../__mocks__/StreamLabs'; |
| 4 | +import { ReleaseCreatedPayload } from '../../../src/schemas/github/release-created-payload'; |
| 5 | +import { ReleaseCreatedPayloadBuilder } from '../../builders/release-created-payload-builder'; |
| 6 | + |
| 7 | +describe('ReleaseCreated', () => { |
| 8 | + let twitchChat: TwitchChatMock; |
| 9 | + let streamLabs: StreamLabsMock; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + twitchChat = new TwitchChatMock(); |
| 13 | + streamLabs = new StreamLabsMock(); |
| 14 | + }); |
| 15 | + |
| 16 | + describe('#canHandle', () => { |
| 17 | + it('returns false when the event is not release', () => { |
| 18 | + const subject = new ReleaseCreated(twitchChat, streamLabs); |
| 19 | + const event = 'star'; |
| 20 | + |
| 21 | + const payload: ReleaseCreatedPayload = {} as ReleaseCreatedPayload; |
| 22 | + |
| 23 | + expect(subject.canHandle({ payload, event })).toEqual(false); |
| 24 | + }); |
| 25 | + it('returns false when the release is not published', () => { |
| 26 | + const subject = new ReleaseCreated(twitchChat, streamLabs); |
| 27 | + const event = 'release'; |
| 28 | + |
| 29 | + const payload = new ReleaseCreatedPayloadBuilder().with({ action: 'created' }).getInstance(); |
| 30 | + |
| 31 | + expect(subject.canHandle({ payload, event })).toEqual(false); |
| 32 | + }); |
| 33 | + it('returns true when the release is published', () => { |
| 34 | + const subject = new ReleaseCreated(twitchChat, streamLabs); |
| 35 | + const event = 'release'; |
| 36 | + |
| 37 | + const payload = new ReleaseCreatedPayloadBuilder() |
| 38 | + .with({ action: 'published' }) |
| 39 | + .getInstance(); |
| 40 | + |
| 41 | + expect(subject.canHandle({ payload, event })).toEqual(true); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('#getTwitchChatMessage', () => { |
| 46 | + it('returns the expected message', () => { |
| 47 | + const subject = new ReleaseCreated(twitchChat, streamLabs); |
| 48 | + const payload = new ReleaseCreatedPayloadBuilder() |
| 49 | + .with({ action: 'published' }) |
| 50 | + .getInstance(); |
| 51 | + |
| 52 | + expect(subject.getTwitchChatMessage({ payload })).toEqual( |
| 53 | + `streamdevs/webhook version 1.0.0 has just been released 🚀! Check it out http://github.com/streamdevs/webhook/releases/1.0.0`, |
| 54 | + ); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe('#getStreamLabsMessage', () => { |
| 59 | + it('returns the expected message', () => { |
| 60 | + const subject = new ReleaseCreated(twitchChat, streamLabs); |
| 61 | + const payload = new ReleaseCreatedPayloadBuilder() |
| 62 | + .with({ action: 'published' }) |
| 63 | + .getInstance(); |
| 64 | + |
| 65 | + expect(subject.getStreamLabsMessage({ payload })).toEqual( |
| 66 | + `*streamdevs/webhook* version *1.0.0* has just been released 🚀!`, |
| 67 | + ); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments