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 ;
@@ -12,11 +13,13 @@ describe('UsersModule (e2e)', () => {
12
13
} ) . compile ( ) ;
13
14
14
15
app = moduleFixture . createNestApplication ( ) ;
15
- app . useGlobalPipes ( new ValidationPipe ( {
16
- whitelist : true ,
17
- forbidNonWhitelisted : true ,
18
- transform : true ,
19
- } ) ) ;
16
+ app . useGlobalPipes (
17
+ new ValidationPipe ( {
18
+ whitelist : true ,
19
+ forbidNonWhitelisted : true ,
20
+ transform : true ,
21
+ } ) ,
22
+ ) ;
20
23
await app . init ( ) ;
21
24
} ) ;
22
25
@@ -26,27 +29,29 @@ describe('UsersModule (e2e)', () => {
26
29
email : 'simone@example.com' ,
27
30
} ;
28
31
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
29
33
const res = await request ( app . getHttpServer ( ) )
30
34
. post ( '/api/v1/users' )
31
35
. send ( userDto )
32
36
. expect ( 201 ) ;
33
37
34
- expect ( res . body ) . toEqual ( {
35
- id : expect . any ( Number ) ,
36
- name : userDto . name ,
37
- email : userDto . email ,
38
- } ) ;
38
+ const user = res . body as User ;
39
+ expect ( typeof user . id ) . toBe ( 'number' ) ;
40
+ expect ( user . name ) . toBe ( userDto . name ) ;
41
+ expect ( user . email ) . toBe ( userDto . email ) ;
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