Skip to content

Commit

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

export class Star extends Reaction {
canHandle({ payload, event }: ReactionCanHandleOptions): boolean {
return event === 'star' && payload.action === 'created';
}

getStreamLabsMessage({ payload }: ReactionHandleOptions): string {
return `*${payload.sender.login}* just starred *${payload.repository.full_name}*`;
}
Expand Down
24 changes: 24 additions & 0 deletions test/reactions/github/star.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,28 @@ describe('Star', () => {
});
});
});

describe('#canHandle', () => {
it('returns true if the event is star and actions is created', () => {
const subject = new Star(null as any, null as any);

const result = subject.canHandle({
event: 'star',
payload: { action: 'created' },
});

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

it('returns false if the event is star and actions is removed', () => {
const subject = new Star(null as any, null as any);

const result = subject.canHandle({
event: 'star',
payload: { action: 'removed' },
});

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

0 comments on commit 8079b7f

Please sign in to comment.