-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathmain_test.js
More file actions
58 lines (42 loc) · 1.47 KB
/
main_test.js
File metadata and controls
58 lines (42 loc) · 1.47 KB
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
55
56
57
58
const test = require('node:test');
const assert = require('assert');
const { Application, MailSystem } = require('./main');
const sinon = require('sinon');
test('test getRandomPerson in main.js', async () => {
const app = new Application();
app.getNames = async () => {
app.people = ['Annika', 'Billy', 'Cecilia'];
};
await app.getNames();
const person = app.getRandomPerson();
assert.ok(app.people.includes(person), 'the person is not in list');
});
test('test mains selectNextPerson to not select same person twice', async () => {
const app = new Application();
app.getNames = async () => {
app.people = ['Annika', 'Billy', 'Cecilia'];
app.selected = [];
};
await app.getNames();
const person1 = app.selectNextPerson();
const person2 = app.selectNextPerson();
assert.notStrictEqual(person1, person2, 'Same person was selected twice');
});
test('test mains notifySelected that it calls send()', async () => {
const mailSystem = new MailSystem();
const sendSpy = sinon.spy(mailSystem, 'send');
const app = new Application();
app.mailSystem = mailSystem;
app.getNames = async () => {
app.people = ['Annika', 'Billy', 'Cecilia'];
app.selected = [];
};
await app.getNames();
const person = app.selectNextPerson();
app.selected = [person];
await app.notifySelected();
assert.ok(
sendSpy.calledWith(person, `Congrats, ${person}!`),
`send() didn't work with args. Captured calls: ${JSON.stringify(sendSpy.args)}`
);
});