From 7c36b2cdc89ede5da71ab2328333ad81d0bc439b Mon Sep 17 00:00:00 2001 From: 839 <8398a7@gmail.com> Date: Mon, 30 Dec 2019 16:56:08 +0900 Subject: [PATCH] [#26] If csv contains space, normalize it. --- __tests__/client.test.ts | 33 +++++++++++++++++++++++++++++++++ src/client.ts | 9 +++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/__tests__/client.test.ts b/__tests__/client.test.ts index 214c30b..33ba91e 100644 --- a/__tests__/client.test.ts +++ b/__tests__/client.test.ts @@ -246,6 +246,39 @@ describe('8398a7/action-slack', () => { }); }); + it('removes csv space', async () => { + const withParams: With = { + status: '', + mention: 'user_id, user_id2', + author_name: '', + only_mention_fail: '', + username: '', + icon_emoji: '', + icon_url: '', + channel: '', + }; + let client = new Client(withParams, process.env.GITHUB_TOKEN, ''); + const msg = 'hello'; + + let text = `<@user_id> <@user_id2> ${successMsg}\n${msg}`; + attachments[0].color = 'good'; + expect(await client.success(msg)).toStrictEqual({ + attachments, + text, + }); + + withParams.mention = ''; + withParams.only_mention_fail = 'user_id, user_id2'; + client = new Client(withParams, process.env.GITHUB_TOKEN, ''); + + text = `<@user_id> <@user_id2> ${failMsg}\n${msg}`; + attachments[0].color = 'danger'; + expect(await client.fail(msg)).toStrictEqual({ + attachments, + text, + }); + }); + it('returns the expected template', async () => { const withParams: With = { status: '', diff --git a/src/client.ts b/src/client.ts index 3e0aa16..a4c53f9 100644 --- a/src/client.ts +++ b/src/client.ts @@ -167,10 +167,11 @@ export class Client { } private mentionText(mention: string) { - if (groupMention.includes(mention)) { - return ` `; - } else if (mention !== '') { - const text = mention + const normalized = mention.replace(/ /g, ''); + if (groupMention.includes(normalized)) { + return ` `; + } else if (normalized !== '') { + const text = normalized .split(',') .map(userId => `<@${userId}>`) .join(' ');