Skip to content

Commit

Permalink
chore: add 'canHandle' method to 'Ping'
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiMA10 committed Apr 19, 2020
1 parent 85ee4b7 commit 6876c9e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/reactions/github/ping.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { Reaction, ReactionHandleOptions } from './reaction';
import {
Reaction,
ReactionCanHandleOptions,
ReactionHandleOptions,
} from './reaction';

export class Ping extends Reaction {
canHandle({ payload, event }: ReactionCanHandleOptions): boolean {
return (
event === 'ping' &&
(payload.hook.events.includes('star') ||
payload.hook.events.includes('fork') ||
payload.hook.events.includes('pull_request'))
);
}
getStreamLabsMessage({ payload }: ReactionHandleOptions): string {
return `🎉 Your repo *${payload.repository.full_name}* is configured correctly for *${payload.hook.events}* events 🎉`;
}
Expand Down
57 changes: 57 additions & 0 deletions test/reactions/github/ping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,61 @@ describe('Ping', () => {
expect(notified).toEqual(false);
});
});

describe('#canHandle', () => {
it('returns true if the event is ping and the hook.events array contains star', () => {
const subject = new Ping(null as any, null as any);

const result = subject.canHandle({
event: 'ping',
payload: { hook: { events: ['star'] } },
});

expect(result).toEqual(true);
});

it('returns false if the event is not ping', () => {
const subject = new Ping(null as any, null as any);

const result = subject.canHandle({
event: 'fork',
payload: { hook: { events: ['star'] } },
});

expect(result).toEqual(false);
});

it('returns false if the hook.events only contains status', () => {
const subject = new Ping(null as any, null as any);

const result = subject.canHandle({
event: 'ping',
payload: { hook: { events: ['status'] } },
});

expect(result).toEqual(false);
});

it('returns true if the event is ping and the hook.events array contains fork', () => {
const subject = new Ping(null as any, null as any);

const result = subject.canHandle({
event: 'ping',
payload: { hook: { events: ['fork'] } },
});

expect(result).toEqual(true);
});

it('returns true if the event is ping and the hook.events array contains pull_request', () => {
const subject = new Ping(null as any, null as any);

const result = subject.canHandle({
event: 'ping',
payload: { hook: { events: ['pull_request'] } },
});

expect(result).toEqual(true);
});
});
});

0 comments on commit 6876c9e

Please sign in to comment.