From df70babbee95ad5efa81b99962a5bd4498799320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9d=C3=A9e=20d=27Aboville?= Date: Wed, 4 Mar 2020 17:41:03 -0500 Subject: [PATCH] Better message for three way matches. If you are in a three way match you won't see "you two have been matched". Also adds a test for the notifyMatchPair function (minus sending the messages). --- .../__tests__/notify-match-pairs.test.ts | 65 +++++++++++++++++++ src/crons/matchify/notify-match-pair.ts | 15 +++-- 2 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/crons/matchify/__tests__/notify-match-pairs.test.ts diff --git a/src/crons/matchify/__tests__/notify-match-pairs.test.ts b/src/crons/matchify/__tests__/notify-match-pairs.test.ts new file mode 100644 index 0000000..0358671 --- /dev/null +++ b/src/crons/matchify/__tests__/notify-match-pairs.test.ts @@ -0,0 +1,65 @@ +import { buildNotifications } from '../notify-match-pair' +import { matchPair } from '../../../db/models/user_model'; + +// Mock Data: +let matchAl; +let matchBob; +let matchCat; + +describe('buildNotifications(): ', () => { + beforeAll(() => { + // Mocks + matchAl = { + id: 1, + email: 'al@email.com', + full_name: 'al gore', + coffee_days: '12', + warning_exception: 1, + skip_next_match: 0, + is_active: 1, + is_faculty: 0, + is_admin: 0, + prevMatches: [], + num_matches: 0 + } ; + + matchBob = { + id: 1, + email: 'bob@email.com', + full_name: 'bob dylan', + coffee_days: '12', + warning_exception: 1, + skip_next_match: 0, + is_active: 1, + is_faculty: 0, + is_admin: 0, + prevMatches: [], + num_matches: 0 + }; + matchCat = { + id: 1, + email: 'cat@email.com', + full_name: 'cat stevens', + coffee_days: '12', + warning_exception: 1, + skip_next_match: 0, + is_active: 1, + is_faculty: 0, + is_admin: 0, + prevMatches: [], + num_matches: 0 + }; + }); + + it('should work for two person matches', () => { + let userMatches: matchPair = [matchAl, matchBob]; + let [emailList, msg] = buildNotifications(userMatches); + expect(emailList.length).toBe(userMatches.length); + expect(msg.includes("two of you")); + }) + it('should work for three person matches', () => { + let userMatches: matchPair = [matchAl, matchBob, matchCat]; + let [emailList, msg] = buildNotifications(userMatches); + expect(emailList.length).toBe(userMatches.length); + expect(msg.includes("three person")); + } \ No newline at end of file diff --git a/src/crons/matchify/notify-match-pair.ts b/src/crons/matchify/notify-match-pair.ts index 7d70272..3e85694 100644 --- a/src/crons/matchify/notify-match-pair.ts +++ b/src/crons/matchify/notify-match-pair.ts @@ -1,10 +1,14 @@ import { sendGenericMessage } from '../../zulip-messenger'; import { matchPair } from '../../db/models/user_model'; -// TODO: need to test this! export function notifyMatchPair(match: matchPair) { + let [emailList, msgContent] = buildNotifications(match); + sendGenericMessage(emailList, msgContent); +} + +//Exported in order to test +export function buildNotifications(match: matchPair): [string[], string] { const emailList = match.map(userRecord => userRecord.email); - // const userNames = match.map(userRecord => userRecord.full_name.split(' ')[0]); const nameLinks = match.map(userRecord => { const firstName = userRecord.full_name.split(' ')[0]; return `[${firstName}](https://www.recurse.com/directory?q=${encodeURIComponent( @@ -12,10 +16,11 @@ export function notifyMatchPair(match: matchPair) { )})`; }); - // TODO: add links to the names of the users here + let match2 = "The two of you have been paired for a chat today."; + let match3 = "✨ You've been blessed with a rare three person chat today! ✨"; const msgContent = `☀️ Good morning ${nameLinks.join( ' and ' - )}! \nThe two of you have been paired for a chat today. Hope you get a chance to chat over coffee or tea or anything that you fancy -- enjoy!`; + )}! \n${match.length == 2 ? match2 : match3} Hope you get a chance to chat over coffee or tea or anything that you fancy -- enjoy!`; - sendGenericMessage(emailList, msgContent); + return [emailList, msgContent]; }