Skip to content

Commit

Permalink
Addressing code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
uLucasFraga authored and stefanteixeira committed Aug 4, 2022
1 parent 25775a7 commit 8503e71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"happo-e2e": "^1.2.0",
"happo-playwright": "^1.1.0",
"happo.io": "^7.2.1",
"http-status-codes": "^2.2.0",
"playwright": "^1.22.1",
"serverest": "2.25.3",
"wait-on": "^6.0.1"
Expand Down
25 changes: 13 additions & 12 deletions tests/api/cart.api.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { test, expect } = require('@playwright/test')
const { POST_SUCESS } = require('serverest/src/utils/constants')
const { StatusCodes } = require('http-status-codes')

const { getAuthToken, getProductBody, getProductId, getCartBody, getCartId } = require('../../lib/helpers')

Expand All @@ -17,20 +18,20 @@ test.describe.parallel('Carts API', () => {
})

test('retrieves an existing cart by its id', async ({ request }) => {
const idProduct = await getProductId(request, authorization, getProductBody())
const _id = await getCartId(request, authorization, getCartBody(idProduct))
const productId = await getProductId(request, authorization, getProductBody())
const cartId = await getCartId(request, authorization, getCartBody(productId))

const response = await request.get(`/carrinhos/${_id}`)
const response = await request.get(`/carrinhos/${cartId}`)

await expect(response).toBeOK()
})

test('creates a cart successfully', async ({ request }) => {
const authorization = await getAuthToken(request)
const idProduct = await getProductId(request, authorization, getProductBody())
const productId = await getProductId(request, authorization, getProductBody())

const response = await request.post('/carrinhos', {
data: getCartBody(idProduct),
data: getCartBody(productId),
headers: { 'Authorization': authorization }
})
const responseBody = JSON.parse(await response.text())
Expand All @@ -39,7 +40,7 @@ test.describe.parallel('Carts API', () => {
expect(responseBody.message).toEqual(POST_SUCESS)
})

test('delete an order successfully', async ({ request }) => {
test('deletes an order successfully', async ({ request }) => {
const idProduct = await getProductId(request, authorization, getProductBody())
await getCartId(request, authorization, getCartBody(idProduct))

Expand All @@ -54,7 +55,7 @@ test.describe.parallel('Carts API', () => {
await expect(responseBody.message).toBe('Registro excluído com sucesso')
})

test('delete an order without a cart', async ({ request }) => {
test('deletes an order without a cart', async ({ request }) => {
const response = await request.delete('/carrinhos/concluir-compra', {
headers: { 'Authorization': authorization }
})
Expand All @@ -66,19 +67,19 @@ test.describe.parallel('Carts API', () => {
await expect(responseBody.message).toBe('Não foi encontrado carrinho para esse usuário')
})

test('delete an order without a token', async ({ request }) => {
test('fails to delete an order if authorization token is not provided', async ({ request }) => {
const response = await request.delete('/carrinhos/concluir-compra', {
headers: { 'Authorization': '' }
})

await expect(response).not.toBeOK()
expect(response.status()).toEqual(StatusCodes.UNAUTHORIZED)

const responseBody = JSON.parse(await response.text())

await expect(responseBody.message).toBe('Token de acesso ausente, inválido, expirado ou usuário do token não existe mais')
})

test('cancel an order successfully', async ({ request }) => {
test('cancels an order successfully', async ({ request }) => {
const idProduct = await getProductId(request, authorization, getProductBody())
await getCartId(request, authorization, getCartBody(idProduct))

Expand All @@ -93,7 +94,7 @@ test.describe.parallel('Carts API', () => {
await expect(responseBody.message).toBe('Registro excluído com sucesso. Estoque dos produtos reabastecido')
})

test('cancel an order without a cart', async ({ request }) => {
test('cancels an order without a cart', async ({ request }) => {
const response = await request.delete('/carrinhos/cancelar-compra', {
headers: { 'Authorization': authorization }
})
Expand All @@ -105,7 +106,7 @@ test.describe.parallel('Carts API', () => {
await expect(responseBody.message).toBe('Não foi encontrado carrinho para esse usuário')
})

test('cancel an order without a token', async ({ request }) => {
test('fails to cancel an order if authorization token is not provided', async ({ request }) => {
const response = await request.delete('/carrinhos/cancelar-compra', {
headers: { 'Authorization': '' }
})
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,11 @@ http-signature@~1.2.0:
jsprim "^1.2.2"
sshpk "^1.7.0"

http-status-codes@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/http-status-codes/-/http-status-codes-2.2.0.tgz#bb2efe63d941dfc2be18e15f703da525169622be"
integrity sha512-feERVo9iWxvnejp3SEfm/+oNG517npqL2/PIA8ORjyOZjGC7TwCRQsZylciLS64i6pJ0wRYz3rkXLRwbtFa8Ng==

https-proxy-agent@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz#c59ef224a04fe8b754f3db0063a25ea30d0005d6"
Expand Down

0 comments on commit 8503e71

Please sign in to comment.