-
Notifications
You must be signed in to change notification settings - Fork 0
/
secretSanta.test.js
54 lines (45 loc) · 1.8 KB
/
secretSanta.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import encryptedSecretSanta from "./output/secretSanta.json";
import blacklist from "./input/blacklist.json";
import participants from "./input/participants.json";
import { decrypt } from "./encrypt.js";
const secretSanta = JSON.parse(decrypt(encryptedSecretSanta));
describe("secretSanta", () => {
it("should not have duplicate names", () => {
const names = secretSanta.map(({ name }) => name);
expect(new Set(names).size).toBe(names.length);
});
it("should not have duplicate numbers", () => {
const numbers = secretSanta.map(({ number }) => number);
expect(new Set(numbers).size).toBe(numbers.length);
});
it("should not have duplicate buyingFor", () => {
const buyingFor = secretSanta.map(({ buyingFor }) => buyingFor);
expect(new Set(buyingFor).size).toBe(buyingFor.length);
});
it("should not have any participants buying for themselves", () => {
const buyingForYourself = secretSanta.filter(
({ name, buyingFor }) => name === buyingFor
);
expect(buyingForYourself.length).toBe(0);
});
it("should not have any participants buying for someone on their blacklist", () => {
const buyingForBlacklistedPerson = secretSanta.filter(
({ name, buyingFor }) => blacklist[name].includes(buyingFor)
);
expect(buyingForBlacklistedPerson.length).toBe(0);
});
it("should have a secret santa for every participant", () => {
expect(secretSanta.length).toBe(participants.length);
});
it("should match phone number of participant in secret santa", () => {
const badMatches = secretSanta.filter(({ name, number }) => {
return (
participants.filter(
(participant) =>
participant.name === name && participant.number === number
).length === 0
);
});
expect(badMatches.length).toBe(0);
});
});