1
1
import { Test , TestingModule } from '@nestjs/testing' ;
2
2
import { INestApplication , ValidationPipe } from '@nestjs/common' ;
3
3
import request from 'supertest' ;
4
- import { AppModule } from '../src/app.module' ;
4
+ import { AppModule } from 'src/app.module' ;
5
+ import { User } from 'src/users/entities/user.entity' ;
5
6
6
7
describe ( 'UsersModule (e2e)' , ( ) => {
7
8
let app : INestApplication ;
@@ -26,27 +27,31 @@ describe('UsersModule (e2e)', () => {
26
27
email : 'simone@example.com' ,
27
28
} ;
28
29
30
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
29
31
const res = await request ( app . getHttpServer ( ) )
30
32
. post ( '/api/v1/users' )
31
33
. send ( userDto )
32
34
. expect ( 201 ) ;
33
35
34
- expect ( res . body ) . toEqual ( {
36
+ const user = res . body as User ;
37
+ expect ( user ) . toEqual ( {
35
38
id : expect . any ( Number ) ,
36
39
name : userDto . name ,
37
40
email : userDto . email ,
38
41
} ) ;
39
42
} ) ;
40
43
41
44
it ( '/api/v1/users (GET) should return all users' , async ( ) => {
45
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
42
46
const res = await request ( app . getHttpServer ( ) )
43
47
. get ( '/api/v1/users' )
44
48
. expect ( 200 ) ;
45
49
46
- expect ( Array . isArray ( res . body ) ) . toBe ( true ) ;
47
- expect ( res . body [ 0 ] ) . toHaveProperty ( 'id' ) ;
48
- expect ( res . body [ 0 ] ) . toHaveProperty ( 'name' ) ;
49
- expect ( res . body [ 0 ] ) . toHaveProperty ( 'email' ) ;
50
+ const users = res . body as User [ ] ;
51
+ expect ( Array . isArray ( users ) ) . toBe ( true ) ;
52
+ expect ( users [ 0 ] ) . toHaveProperty ( 'id' ) ;
53
+ expect ( users [ 0 ] ) . toHaveProperty ( 'name' ) ;
54
+ expect ( users [ 0 ] ) . toHaveProperty ( 'email' ) ;
50
55
} ) ;
51
56
52
57
afterAll ( async ( ) => {
0 commit comments