@@ -5,11 +5,12 @@ import { UsersService } from '../src/users/users.service';
55import { requestWithAuth , haveUserLogged } from './preconditions' ;
66import { ProjectsService } from '../src/projects/projects.service' ;
77import uuidAPIKey from 'uuid-apikey' ;
8+ import { UserLoginResponseDto } from 'src/users/dto/user-login-response.dto' ;
89
910const project = {
1011 id : uuidAPIKey . create ( ) . uuid ,
11- name : 'Test project'
12- }
12+ name : 'Test project' ,
13+ } ;
1314
1415const projectServiceMock = {
1516 findAll : ( ) => [ 'test' ] ,
@@ -20,7 +21,7 @@ const projectServiceMock = {
2021describe ( 'Projects (e2e)' , ( ) => {
2122 let app : INestApplication ;
2223 let usersService : UsersService ;
23- let loggedUser
24+ let loggedUser : UserLoginResponseDto ;
2425
2526 beforeAll ( async ( ) => {
2627 const moduleFixture : TestingModule = await Test . createTestingModule ( {
@@ -31,10 +32,18 @@ describe('Projects (e2e)', () => {
3132 . compile ( ) ;
3233
3334 app = moduleFixture . createNestApplication ( ) ;
34- usersService = moduleFixture . get < UsersService > ( UsersService )
35+ usersService = moduleFixture . get < UsersService > ( UsersService ) ;
36+ usersService = moduleFixture . get < UsersService > ( UsersService ) ;
3537
3638 await app . init ( ) ;
37- loggedUser = await haveUserLogged ( usersService )
39+ } ) ;
40+
41+ beforeEach ( async ( ) => {
42+ loggedUser = await haveUserLogged ( usersService ) ;
43+ } ) ;
44+
45+ afterEach ( async ( ) => {
46+ await usersService . delete ( loggedUser . id ) ;
3847 } ) ;
3948
4049 afterAll ( async ( ) => {
@@ -47,47 +56,39 @@ describe('Projects (e2e)', () => {
4756 . expect ( 201 )
4857 . expect ( res => {
4958 expect ( res . body . name ) . toBe ( project . name ) ;
50- } )
59+ } ) ;
5160 } ) ;
5261
5362 it ( '401' , ( ) => {
54- return requestWithAuth ( app , 'post' , '/projects' , project , '' )
55- . expect ( 401 )
63+ return requestWithAuth ( app , 'post' , '/projects' , project , '' ) . expect ( 401 ) ;
5664 } ) ;
57- } )
65+ } ) ;
5866
5967 describe ( 'GET /' , ( ) => {
6068 it ( '200' , async ( ) => {
61- const res = await requestWithAuth ( app , 'get' , '/projects' , { } , loggedUser . token )
62- . expect ( 200 )
69+ const res = await requestWithAuth ( app , 'get' , '/projects' , { } , loggedUser . token ) . expect ( 200 ) ;
6370
64- expect ( res . body ) . toEqual ( expect . arrayContaining ( projectServiceMock . findAll ( ) ) )
71+ expect ( res . body ) . toEqual ( expect . arrayContaining ( projectServiceMock . findAll ( ) ) ) ;
6572 } ) ;
6673
6774 it ( '401' , async ( ) => {
68- await requestWithAuth ( app , 'get' , '/projects' , { } , '' )
69- . expect ( 401 )
75+ await requestWithAuth ( app , 'get' , '/projects' , { } , '' ) . expect ( 401 ) ;
7076 } ) ;
71- } )
72-
77+ } ) ;
7378
7479 describe ( 'DELETE /' , ( ) => {
75-
7680 it ( 'can delete' , async ( ) => {
77- const res = await requestWithAuth ( app , 'delete' , `/projects/${ project . id } ` , { } , loggedUser . token )
78- . expect ( 200 )
81+ const res = await requestWithAuth ( app , 'delete' , `/projects/${ project . id } ` , { } , loggedUser . token ) . expect ( 200 ) ;
7982
80- expect ( res . body ) . toStrictEqual ( projectServiceMock . remove ( ) )
81- } )
83+ expect ( res . body ) . toStrictEqual ( projectServiceMock . remove ( ) ) ;
84+ } ) ;
8285
8386 it ( 'not valid UUID' , async ( ) => {
84- await requestWithAuth ( app , 'delete' , `/projects/123` , { } , loggedUser . token )
85- . expect ( 400 )
86- } )
87+ await requestWithAuth ( app , 'delete' , `/projects/123` , { } , loggedUser . token ) . expect ( 400 ) ;
88+ } ) ;
8789
8890 it ( 'not valid token' , async ( ) => {
89- await requestWithAuth ( app , 'delete' , `/projects/${ project . id } ` , { } , 'asd' )
90- . expect ( 401 )
91- } )
92- } )
91+ await requestWithAuth ( app , 'delete' , `/projects/${ project . id } ` , { } , 'asd' ) . expect ( 401 ) ;
92+ } ) ;
93+ } ) ;
9394} ) ;
0 commit comments