Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions tests/api-handling.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import { test, expect } from '@playwright/test'

test('@API - (POST) Verify login', async ({ request }) => {
const response = await request.post(
'https://automationexercise.com/api/verifyLogin',
{
data: {
email: 'johnDoe24@gmail.com',
password: 'johnDoe#24',
},
const response = await request.post('https://automationexercise.com/api/verifyLogin', {
data: {
email: 'johnDoe24@gmail.com',
password: 'johnDoe#24',
},
)
})
expect(response.status()).toBe(200)
})
test('@API - (POST) Verify login with wrong credentials', async ({
request,
}) => {
const response = await request.post(
'https://automationexercise.com/api/verifyLogin',
{
data: {
email: 'dsdsd@dest.com',
password: 'dsdsfsd',
},

test('@API - (POST) Verify login with wrong credentials', async ({ request }) => {
const response = await request.post('https://automationexercise.com/api/verifyLogin', {
data: {
email: 'dsdsd@dest.com',
password: 'dsdsfsd',
},
)
})

// HTTP status is 200 because the request itself succeeded
expect(response.status()).toBe(200)
Expand All @@ -32,13 +25,18 @@ test('@API - (POST) Verify login with wrong credentials', async ({
const body = await response.json()
console.log(body) // Verifies actual API response
expect(body.responseCode).toBe(400) // API seems to returned 400 code instead of 404.
expect(body.message).toBe(
'Bad request, email or password parameter is missing in POST request.',
) // API returns a different message than "User not found!" (Website docs might be outdated)
expect(body.message).toBe('Bad request, email or password parameter is missing in POST request.') // API returns a different message than "User not found!" (Website docs might be outdated)
})

test('@API - (GET) Get all products', async ({ request }) => {
const response = await request.get(
'https://automationexercise.com/api/productsList',
)
const response = await request.get('https://automationexercise.com/api/productsList')
expect(response.status()).toBe(200)
})

// Additional API tests
test('@API - (POST) - To All Product List is invalid', async ({ request }) => {
const response = await request.post('https://automationexercise.com/api/productsList')
expect(response.status()).toBe(200)
const body = await response.json()
expect(body.message).toBe('This request method is not supported.')
})
Loading