Skip to content

Commit f289473

Browse files
committed
lab2 v5.0
1 parent 63ff260 commit f289473

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lab2/main_test.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const test = require('node:test');
22
const assert = require('assert');
3+
const fs = require('fs');
4+
const os = require('os');
5+
const path = require('path');
36

47
const { Application, MailSystem } = require('./main');
58

@@ -31,12 +34,28 @@ test('should return true if mail is sent successfully', (t) => {
3134

3235

3336

37+
38+
3439
test('should return name_list ', async()=>{
3540

41+
// Write mock name list to a temporary file
42+
const nameListContent = 'Alice\nBob\nCharlie';
43+
const tempFilePath = path.join('name_list.txt');
44+
fs.writeFileSync(tempFilePath, nameListContent);
45+
46+
// Attach cleanup handler to the process exit event
47+
process.on('exit', () => {
48+
if (tempFilePath) {
49+
// Clean up: Delete the temporary directory
50+
fs.unlinkSync(tempFilePath);
51+
}
52+
});
53+
54+
// Instantiate Application class and call getNames with the temporary file path
3655
const app = new Application();
37-
const [people, selected] = await app.getNames(); // Provide the path to the temporary file
56+
const [people, selected] = await app.getNames(tempFilePath);
3857

39-
// Assert that the returned list matches the expected list
58+
// Assert the results
4059
assert.deepStrictEqual(people, ['Alice', 'Bob', 'Charlie']);
4160
assert.deepStrictEqual(selected, []);
4261

@@ -121,4 +140,7 @@ test('should call write and send methods of MailSystem for each selected person'
121140

122141
assert.strictEqual(mailSystem.writeCallCount, 3);
123142
assert.strictEqual(mailSystem.sendCallCount, 3);
143+
144+
124145
});
146+

lab2/name_list.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)