Skip to content

Commit 81bdcd5

Browse files
committed
fix send mail
1 parent d4c0246 commit 81bdcd5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lab2/main_test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ test('MailSystem should write mail correctly', (t) => {
2121
// });
2222

2323
test('MailSystem should send mail correctly', (t) => {
24-
const sendMock = t.mock.fn(MailSystem.prototype.send);
25-
const success = sendMock('Alice', 'Congrats, Alice!');
26-
assert.strictEqual(typeof success, 'boolean');
24+
t.mock.method(Math, 'random').mock.mockImplementation(() => 0.6);
25+
const success = MailSystem.prototype.send('Alice', 'Congrats, Alice!');
26+
assert.strictEqual(success, true);
27+
t.mock.method(Math, 'random').mock.mockImplementation(() => 0.4);
28+
const failure = MailSystem.prototype.send('Alice', 'Congrats, Alice!');
29+
assert.strictEqual(failure, false);
2730
});
2831

32+
2933
test('Application should read file correctly', async (t) => {
3034

3135
fs.writeFileSync(TestData, 'Alice\nBob\nCharlie', 'utf8');
@@ -71,21 +75,21 @@ test('Application should select next person', async (t) => {
7175
});
7276

7377
test('Application should notify person', async (t) => {
78+
const nameList = ['Alice', 'Bob', 'Charlie'];
7479
t.mock.method(Application.prototype, 'getNames', async () => {
75-
return [['Alice', 'Bob', 'Charlie'], []];
80+
return [nameList, []];
7681
});
7782
const app = new Application();
7883
await app.getNames();
7984

80-
app.selectNextPerson();
81-
console.log(app.selected);
85+
app.selected = nameList;
8286
const writeMock = t.mock.method(MailSystem.prototype, 'write', () => {
8387
return true;
8488
});
8589
const sendMock = t.mock.method(MailSystem.prototype, 'send', () => {
8690
return true;
8791
});
8892
app.notifySelected();
89-
assert.strictEqual(writeMock.mock.callCount(), 1);
90-
assert.strictEqual(sendMock.mock.callCount(), 1);
93+
assert.strictEqual(writeMock.mock.callCount(), app.selected.length);
94+
assert.strictEqual(sendMock.mock.callCount(), app.selected.length);
9195
});

0 commit comments

Comments
 (0)