Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better message for three way matches. #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/crons/matchify/__tests__/notify-match-pairs.test.ts
Original file line number Diff line number Diff line change
@@ -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"));
}
15 changes: 10 additions & 5 deletions src/crons/matchify/notify-match-pair.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
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(
userRecord.email
)})`;
});

// 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];
}