Skip to content

Commit

Permalink
Add API tests for Edit and Delete User actions (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanteixeira committed Jul 8, 2022
1 parent 31158fd commit 26e2a50
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ jobs:
if: always()
uses: actions/upload-artifact@v2
with:
name: allure-results
name: allure-results-api
path: allure-results
retention-days: 10

e2e_tests:
name: End-to-end tests
Expand All @@ -58,12 +59,14 @@ jobs:
if: always()
uses: actions/upload-artifact@v2
with:
name: allure-results
name: allure-results-e2e
path: allure-results
retention-days: 10

- name: Save screenshots and trace in case of failure
if: failure()
uses: actions/upload-artifact@v2
with:
name: failure-screenshots-trace
path: test-results
retention-days: 10
31 changes: 28 additions & 3 deletions tests/api/user.api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ test.describe.parallel('User API', () => {
await expect(response).toBeOK()
})

test('creates an user successfully', async ({ request }) => {
test('creates a user successfully', async ({ request }) => {
const response = await request.post('/usuarios', { data: getUserBody() })

await expect(response).toBeOK()
})

test('fails to create an user if it already exists', async ({ request }) => {
test('fails to create a user if it already exists', async ({ request }) => {
const body = getUserBody()
await request.post('/usuarios', { data: body })

Expand All @@ -39,9 +39,34 @@ test.describe.parallel('User API', () => {
await expect(response).toBeOK()
})

test('fails to retrieve an user if it does not exist', async ({ request }) => {
test('fails to retrieve a user if it does not exist', async ({ request }) => {
const response = await request.get('/usuarios/nonExistingId')

await expect(response).not.toBeOK()
})

test('deletes a user successfully', async ({ request }) => {
const id = await getUserId(request, getUserBody())

const response = await request.delete(`/usuarios/${id}`)

await expect(response).toBeOK()
})

test('edits a user successfully', async ({ request }) => {
const id = await getUserId(request, getUserBody())
const editBody = getUserBody()

const response = await request.put(`/usuarios/${id}`, { data: editBody })

await expect(response.status()).toEqual(200)
})

test('creates a user by editing a non-existing one', async ({ request }) => {
const editBody = getUserBody()

const response = await request.put('/usuarios/nonExistingId', { data: editBody })

await expect(response.status()).toEqual(201)
})
})
2 changes: 1 addition & 1 deletion tests/e2e/create-user.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.describe.parallel('Create user', () => {
await expect(errors).toHaveCount(3)
})

test('creates an user successfully', async ({ page }) => {
test('creates a user successfully', async ({ page }) => {
await createUser(page)

await page.waitForNavigation()
Expand Down

0 comments on commit 26e2a50

Please sign in to comment.