Skip to content

Commit b83e55d

Browse files
rootroot
authored andcommitted
0317
1 parent 491abe7 commit b83e55d

File tree

316 files changed

+102907
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

316 files changed

+102907
-2
lines changed

lab2/main_test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
const test = require('node:test');
22
const assert = require('assert');
33
const { Application, MailSystem } = require('./main');
4+
const sinon = require('sinon');
5+
6+
test('notifySelected sends mail to all selected people', async () => {
7+
const mockMailSystem = sinon.createStubInstance(MailSystem);
8+
mockMailSystem.send.returns(true); // 假設發送郵件總是成功
9+
10+
const app = new Application();
11+
app.mailSystem = mockMailSystem; // 使用模擬的 MailSystem
12+
13+
// 假設 getNames 方法返回特定的名單
14+
app.getNames = async () => {
15+
return [['Alice', 'Bob', 'Charlie'], ['Alice']];
16+
};
17+
18+
await app.getNames();
19+
app.selectNextPerson(); // 選擇下一個人(假設為 Bob)
20+
app.notifySelected();
21+
22+
// 驗證 send 方法是否被調用了正確的次數(應為已選擇人數)
23+
assert.strictEqual(mockMailSystem.send.callCount, app.selected.length);
24+
25+
// 確保 send 方法被正確的參數調用
26+
app.selected.forEach((person) => {
27+
assert(mockMailSystem.send.calledWith(person, `Congrats, ${person}!`));
28+
});
29+
});
30+
431

5-
// TODO: write your tests here test
6-
// Remember to use Stub, Mock, and Spy when necessary

lab2/name_list.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Alice
2+
Bob
3+
Charlie

lab2/node_modules/.package-lock.json

Lines changed: 125 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lab2/node_modules/@sinonjs/commons/LICENSE

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lab2/node_modules/@sinonjs/commons/README.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lab2/node_modules/@sinonjs/commons/lib/called-in-order.js

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lab2/node_modules/@sinonjs/commons/lib/called-in-order.test.js

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)