-
Notifications
You must be signed in to change notification settings - Fork 1
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 #14 from MatheusSanchez/SFD-43-e2e-tests-get-user-…
…routes E2E tests get user routes
- Loading branch information
Showing
7 changed files
with
293 additions
and
14 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,61 @@ | ||
import { it } from 'vitest' | ||
import { afterAll, beforeAll, describe, expect, test } from 'vitest' | ||
import request from 'supertest' | ||
import { app } from '../../app' | ||
import { compare } from 'bcryptjs' | ||
|
||
it('ok', () => {}) | ||
describe('Get User By email E2E', () => { | ||
beforeAll(async () => { | ||
await app.ready() | ||
}) | ||
|
||
afterAll(async () => { | ||
await app.close() | ||
}) | ||
|
||
test('should be able to get an user by e-mail', async () => { | ||
const email = '[email protected]' | ||
const name = 'John' | ||
const surname = 'Doe' | ||
const password = 'password' | ||
|
||
await request(app.server).post('/user').send({ | ||
email, | ||
name, | ||
surname, | ||
password, | ||
}) | ||
|
||
const getUserByEmailResponse = await request(app.server) | ||
.get(`/user`) | ||
.query({ email }) | ||
|
||
expect(getUserByEmailResponse.statusCode).toEqual(200) | ||
expect(getUserByEmailResponse.body.user).toEqual( | ||
expect.objectContaining({ | ||
email, | ||
name, | ||
surname, | ||
password_hash: expect.any(String), | ||
}), | ||
) | ||
|
||
const passwordMatches = await compare( | ||
password, | ||
getUserByEmailResponse.body.user.password_hash, | ||
) | ||
expect(passwordMatches).toEqual(true) | ||
}) | ||
|
||
test('should not be able to get an user by e-mail that does not exist', async () => { | ||
const email = '[email protected]' | ||
|
||
const getUserByEmailResponse = await request(app.server) | ||
.get(`/user`) | ||
.query({ email }) | ||
|
||
expect(getUserByEmailResponse.statusCode).toEqual(200) | ||
expect(getUserByEmailResponse.body.user).toEqual( | ||
expect.objectContaining({}), | ||
) | ||
}) | ||
}) |
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
Oops, something went wrong.