-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { StreamLabs } from '../../services/StreamLabs'; | ||
import { TwitchChat } from '../../services/TwitchChat'; | ||
|
||
interface PingConfig { | ||
streamlabs: StreamLabs; | ||
twitchChat: TwitchChat; | ||
} | ||
|
||
interface HandleOptions { | ||
// FIXME: add Payload type | ||
payload: any; | ||
} | ||
|
||
export class Ping { | ||
private streamlabs: StreamLabs; | ||
private twitchChat: TwitchChat; | ||
|
||
public constructor({ streamlabs, twitchChat }: PingConfig) { | ||
this.streamlabs = streamlabs; | ||
this.twitchChat = twitchChat; | ||
} | ||
|
||
public async handle({ payload }: HandleOptions) { | ||
const streamlabsMessage = `🎉 Your repo *${payload.repository.full_name}* is configured correctly for *${payload.hook.events}* events 🎉`; | ||
await this.streamlabs.alert({ | ||
message: streamlabsMessage, | ||
}); | ||
|
||
const twitchMessage = `🎉 Your repo ${payload.repository.full_name} is configured correctly for ${payload.hook.events} events 🎉`; | ||
await this.twitchChat.send(twitchMessage); | ||
|
||
return { | ||
twitchChat: { | ||
message: twitchMessage, | ||
notified: true, | ||
}, | ||
streamlabs: { | ||
message: streamlabsMessage, | ||
notified: true, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Ping } from '../../../src/reactions/github/ping'; | ||
|
||
describe('Ping', () => { | ||
describe('#handle', () => { | ||
let streamlabs: any; | ||
let twitchChat: any; | ||
let payload: any; | ||
|
||
beforeEach(() => { | ||
streamlabs = { alert: jest.fn() }; | ||
twitchChat = { send: jest.fn() }; | ||
payload = { | ||
hook: { | ||
events: ['fork'], | ||
}, | ||
repository: { | ||
full_name: 'streamdevs/webhook', | ||
}, | ||
sender: { | ||
login: 'orestes', | ||
}, | ||
}; | ||
}); | ||
|
||
it('calls StreamLabs with the expected message', async () => { | ||
const subject = new Ping({ streamlabs, twitchChat }); | ||
|
||
await subject.handle({ payload }); | ||
|
||
expect(streamlabs.alert).toHaveBeenCalledWith({ | ||
message: `🎉 Your repo *${payload.repository.full_name}* is configured correctly for *fork* events 🎉`, | ||
}); | ||
}); | ||
|
||
it('calls TwitchChat with the expected message', async () => { | ||
const subject = new Ping({ streamlabs, twitchChat }); | ||
|
||
await subject.handle({ payload }); | ||
|
||
expect(twitchChat.send).toHaveBeenCalledWith( | ||
`🎉 Your repo ${payload.repository.full_name} is configured correctly for fork events 🎉`, | ||
); | ||
}); | ||
|
||
it('returns the message that was send to Twitch', async () => { | ||
const subject = new Ping({ streamlabs, twitchChat }); | ||
|
||
const { twitchChat: response } = await subject.handle({ | ||
payload: { | ||
...payload, | ||
hook: { | ||
events: ['pull_request'], | ||
}, | ||
}, | ||
}); | ||
|
||
expect(response).toEqual({ | ||
message: `🎉 Your repo ${payload.repository.full_name} is configured correctly for pull_request events 🎉`, | ||
notified: true, | ||
}); | ||
}); | ||
|
||
it('returns the message that was send to StreamLabs', async () => { | ||
const subject = new Ping({ streamlabs, twitchChat }); | ||
|
||
const { streamlabs: response } = await subject.handle({ | ||
payload: { | ||
...payload, | ||
hook: { | ||
events: ['star'], | ||
}, | ||
}, | ||
}); | ||
|
||
expect(response).toEqual({ | ||
message: `🎉 Your repo *${payload.repository.full_name}* is configured correctly for *star* events 🎉`, | ||
notified: true, | ||
}); | ||
}); | ||
}); | ||
}); |