-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.js
47 lines (41 loc) · 1.71 KB
/
main_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
const test = require('node:test');
const assert = require('assert');
const { Application, MailSystem } = require('./main');
test("Test Application's selectNextPerson", () => {
const app = new Application();
const initialSelectedLength = app.selected.length;
const selectedPerson = app.selectNextPerson();
assert.strictEqual(app.selected.length, initialSelectedLength + 1, "One person should be selected");
});
test("Test Application's notifySelected", () => {
const app = new Application();
const consoleSpy = jest.spyOn(console, 'log');
app.notifySelected();
expect(consoleSpy).toHaveBeenCalled();
});
test("Test MailSystem's write method", () => {
const mailSystem = new MailSystem();
const name = "John";
const context = mailSystem.write(name);
assert.strictEqual(context, `Congrats, ${name}!`, "Context should match expected");
});
test("Test MailSystem's send method", () => {
const mailSystem = new MailSystem();
const name = "John";
const context = "Test context";
const result = mailSystem.send(name, context);
assert(result === true || result === false, "send method should return a boolean");
});
test("Test Application's getRandomPerson", () => {
const app = new Application();
const getRandomPersonSpy = jest.spyOn(app, 'getRandomPerson');
app.getRandomPerson();
expect(getRandomPersonSpy).toHaveBeenCalled();
});
test("Test Application's getRandomPerson with stubbed getNames method", () => {
const app = new Application();
const stubbedNames = ['John', 'Jane', 'Doe'];
app.getNames = jest.fn().mockResolvedValue([stubbedNames, []]);
const randomPerson = app.getRandomPerson();
expect(stubbedNames).toContain(randomPerson);
});