@@ -21,18 +21,34 @@ beforeEach(async () => {
21
21
} )
22
22
23
23
test ( 'Should signup a new user' , async ( ) => {
24
- await request ( app ) . post ( '/users' ) . send ( {
24
+ const response = await request ( app ) . post ( '/users' ) . send ( {
25
25
name : 'Andrew' ,
26
26
27
27
password : 'MyPass777!'
28
28
} ) . expect ( 201 )
29
+
30
+ // Assert that the database was changed correctly
31
+ const user = await User . findById ( response . body . user . _id )
32
+ expect ( user ) . not . toBeNull ( )
33
+
34
+ // Assertions about the response
35
+ expect ( response . body ) . toMatchObject ( {
36
+ user : {
37
+ name : 'Andrew' ,
38
+
39
+ } ,
40
+ token : user . tokens [ 0 ] . token
41
+ } )
42
+ expect ( user . password ) . not . toBe ( 'MyPass777!' )
29
43
} )
30
44
31
45
test ( 'Should login existing user' , async ( ) => {
32
- await request ( app ) . post ( '/users/login' ) . send ( {
46
+ const response = await request ( app ) . post ( '/users/login' ) . send ( {
33
47
email : userOne . email ,
34
48
password : userOne . password
35
49
} ) . expect ( 200 )
50
+ const user = await User . findById ( userOneId )
51
+ expect ( response . body . token ) . toBe ( user . tokens [ 1 ] . token )
36
52
} )
37
53
38
54
test ( 'Should not login nonexistent user' , async ( ) => {
@@ -63,6 +79,8 @@ test('Should delete account for user', async () => {
63
79
. set ( 'Authorization' , `Bearer ${ userOne . tokens [ 0 ] . token } ` )
64
80
. send ( )
65
81
. expect ( 200 )
82
+ const user = await User . findById ( userOneId )
83
+ expect ( user ) . toBeNull ( )
66
84
} )
67
85
68
86
test ( 'Should not delete account for unauthenticate user' , async ( ) => {
0 commit comments