-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from olaviolacerda/feature/testing-unit
test: add controllers tests
- Loading branch information
Showing
8 changed files
with
76 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { HttpStatus, INestApplication } from '@nestjs/common'; | ||
import request from 'supertest'; | ||
import { TestingModule, Test } from '@nestjs/testing'; | ||
|
||
import { AppModule } from '../../src/core/modules/app.module'; | ||
|
||
describe('AuthController (e2e)', () => { | ||
let app: INestApplication; | ||
|
||
beforeAll(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it('it should login a valid user', () => { | ||
const credentials = { | ||
username: 'test', | ||
password: '123', | ||
}; | ||
|
||
return request(app.getHttpServer()) | ||
.post(`/auth/login`) | ||
.send(credentials) | ||
.expect(({ body }: request.Response) => { | ||
expect(body).toBeDefined(); | ||
expect(body['accessToken']).toBeDefined(); | ||
expect(body['refreshToken']).toBeDefined(); | ||
}) | ||
.expect(HttpStatus.OK); | ||
}); | ||
|
||
it('it should NOT login a user with invalid password', () => { | ||
const credentials = { | ||
username: 'test', | ||
password: 'fakepass', | ||
}; | ||
|
||
return request(app.getHttpServer()) | ||
.post(`/auth/login`) | ||
.send(credentials) | ||
.expect(HttpStatus.UNAUTHORIZED); | ||
}); | ||
|
||
it('it should NOT login an user if it not exists', () => { | ||
const credentials = { | ||
username: 'idonotexist', | ||
password: '123', | ||
}; | ||
|
||
return request(app.getHttpServer()) | ||
.post(`/auth/login`) | ||
.send(credentials) | ||
.expect(({ body }: request.Response) => { | ||
expect(body).toBeDefined(); | ||
expect(body.message).toBe('Something is wrong with your credentials'); | ||
}) | ||
.expect(HttpStatus.BAD_REQUEST); | ||
}); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters