@@ -9,35 +9,34 @@ const path = require('path');
9
9
10
10
test ( 'MailSystem should return the correct message context.' , ( ) => {
11
11
const mailSystem = new MailSystem ( ) ;
12
- const recipient = 'Justin' ;
12
+ const message = mailSystem . write ( 'Justin' ) ;
13
13
14
- const message = mailSystem . write ( recipient ) ;
15
14
assert . strictEqual ( message , 'Congrats, Justin!' ) ;
16
15
} ) ;
17
16
18
- test ( 'MailSystem should send mail corrctly' , ( t ) => {
17
+ test ( 'MailSystem should send mail corrctly' , ( ) => {
19
18
const mailSystem = new MailSystem ( ) ;
20
19
21
- // SUCCESS
22
- t . mock . method ( Math , 'random' , ( ) => 1 ) ;
20
+ // SUCCESSFUL CASE
21
+ test . mock . method ( Math , 'random' , ( ) => 1 ) ;
23
22
let isMailSent = mailSystem . send ( 'Alice' , "Hello Message" ) ;
24
- assert . strictEqual ( isMailSent , true ) ;
23
+ assert . strictEqual ( isMailSent , true , 'Mail should be sent successfully when Math.random() returns 1' ) ;
25
24
26
- // FAIL
27
- t . mock . method ( Math , 'random' , ( ) => 0.5 ) ;
25
+ // FAIL CASE
26
+ test . mock . method ( Math , 'random' , ( ) => 0.5 ) ;
28
27
isMailSent = mailSystem . send ( 'Alice' , "Hello Message" ) ;
29
- assert . strictEqual ( isMailSent , false ) ;
28
+ assert . strictEqual ( isMailSent , false , 'Mail should fail to send when Math.random() returns a value less than 0.5' ) ;
30
29
} ) ;
31
30
32
31
test ( 'Application should read names from file correctly' , async ( ) => {
33
- const nameList = 'Alice\nBob\nCharlie' ;
34
- const filePath = path . join ( 'name_list.txt' ) ;
32
+ const nameList = 'Alice\nBob\nCharlie\nSam ' ;
33
+ const filePath = path . resolve ( 'name_list.txt' ) ;
35
34
fs . writeFileSync ( filePath , nameList ) ;
36
35
37
36
const app = new Application ( ) ;
38
37
const [ names , selected ] = await app . getNames ( filePath ) ;
39
38
40
- assert . deepStrictEqual ( names , [ 'Alice' , 'Bob' , 'Charlie' ] ) ;
39
+ assert . deepStrictEqual ( names , [ 'Alice' , 'Bob' , 'Charlie' , 'Sam' ] ) ;
41
40
assert . deepStrictEqual ( selected , [ ] ) ;
42
41
} ) ;
43
42
0 commit comments