Skip to content

Commit

Permalink
Merge pull request #7 from Jrc356/jrc356/fix-reactions
Browse files Browse the repository at this point in the history
only give out avocados on avocado reactions
  • Loading branch information
Jrc356 authored Dec 16, 2022
2 parents 42aea44 + 1128e9d commit c604adc
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/avokudos.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Avokudos {

hearReactionAdded = async (res) => {
const { client, event } = res
if (event.reaction !== 'avocado') {
return
}
const message = await this.getMessage(
client,
event.item.channel,
Expand Down Expand Up @@ -91,6 +94,9 @@ class Avokudos {

hearReactionRemoved = async (res) => {
const { client, event } = res
if (event.reaction !== 'avocado') {
return
}
const message = await this.getMessage(
client,
event.item.channel,
Expand Down
71 changes: 70 additions & 1 deletion test/avokudos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('avokudos', () => {
expect(mockSlackClient.chat.postMessage.mock.calls.length).toBe(0)
})

it('gives users mentioned in a message an avocado if someone reacts to a message that mentions users', async () => {
it('gives users mentioned in a message an avocado if someone reacts to a message that mentions users with an avocado', async () => {
const text =
'hey <@test> <@test2> <@test3> :avocado: for helping with that issue!'

Expand All @@ -105,6 +105,7 @@ describe('avokudos', () => {
await avokudos.hearReactionAdded({
event: {
user: 'test4',
reaction: 'avocado',
item_user: 'test2',
item: {
channel: 'test_channel',
Expand All @@ -119,6 +120,36 @@ describe('avokudos', () => {
expect(mockSlackClient.chat.postMessage.mock.calls.length).toBe(3)
})

it('does not give users an avocado if the reaction used is not an avocado', async () => {
const text =
'hey <@test> <@test2> <@test3> :avocado: for helping with that issue!'

mockSlackClient.conversations.history.mockReturnValueOnce({
messages: [
{
text
}
]
})

await avokudos.hearReactionAdded({
event: {
user: 'test4',
reaction: 'raised_hands',
item_user: 'test2',
item: {
channel: 'test_channel',
ts: 'test_ts'
}
},
client: mockSlackClient
})
expect(keeper.keeper.test).toBe(undefined)
expect(keeper.keeper.test2).toBe(undefined)
expect(keeper.keeper.test3).toBe(undefined)
expect(mockSlackClient.chat.postMessage.mock.calls.length).toBe(0)
})

it('gives a user mentioned in a message a single avocado if someone reacts to a message that mentions the same user multiple times', async () => {
const text =
'hey <@test> <@test> :avocado: for helping with that issue!'
Expand All @@ -135,6 +166,7 @@ describe('avokudos', () => {
event: {
user: 'test4',
item_user: 'test2',
reaction: 'avocado',
item: {
channel: 'test_channel',
ts: 'test_ts'
Expand Down Expand Up @@ -162,6 +194,7 @@ describe('avokudos', () => {
event: {
user: 'test',
item_user: 'test2',
reaction: 'avocado',
item: {
channel: 'test_channel',
ts: 'test_ts'
Expand All @@ -187,6 +220,7 @@ describe('avokudos', () => {
event: {
user: 'test4',
item_user: 'test2',
reaction: 'avocado',
item: {
channel: 'test_channel',
ts: 'test_ts'
Expand Down Expand Up @@ -214,6 +248,7 @@ describe('avokudos', () => {
event: {
user: 'test2',
item_user: 'test2',
reaction: 'avocado',
item: {
channel: 'test_channel',
ts: 'test_ts'
Expand Down Expand Up @@ -246,6 +281,7 @@ describe('avokudos', () => {
event: {
user: 'test4',
item_user: 'test',
reaction: 'avocado',
item: {
channel: 'test_channel',
ts: 'test_ts'
Expand Down Expand Up @@ -277,6 +313,7 @@ describe('avokudos', () => {
event: {
user: 'test4',
item_user: 'test',
reaction: 'avocado',
item: {
channel: 'test_channel',
ts: 'test_ts'
Expand Down Expand Up @@ -305,6 +342,7 @@ describe('avokudos', () => {
event: {
user: 'test4',
item_user: 'test',
reaction: 'avocado',
item: {
channel: 'test_channel',
ts: 'test_ts'
Expand Down Expand Up @@ -332,6 +370,7 @@ describe('avokudos', () => {
client: mockSlackClient,
event: {
user: 'test',
reaction: 'avocado',
item_user: 'test',
item: {
channel: 'test_channel',
Expand Down Expand Up @@ -361,6 +400,36 @@ describe('avokudos', () => {
event: {
user: 'test',
item_user: 'test',
reaction: 'avocado',
item: {
channel: 'test_channel',
ts: 'test_ts'
}
}
})

expect(keeper.keeper.test).toBe(1)
expect(mockSlackClient.chat.postMessage.mock.calls.length).toBe(0)
})

it('does not remove an avocado from someone if the reaction removed is not an avocado', async () => {
keeper.keeper.test = 1

const text = "I'm weird and want to remove an avocado from myself!"
mockSlackClient.conversations.history.mockReturnValueOnce({
messages: [
{
text
}
]
})

await avokudos.hearReactionRemoved({
client: mockSlackClient,
event: {
user: 'test',
item_user: 'test2',
reaction: 'raised_hands',
item: {
channel: 'test_channel',
ts: 'test_ts'
Expand Down

0 comments on commit c604adc

Please sign in to comment.