Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion infra/api/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { default } from './mocks/mocks';
export * from './urls/ApplicationUrl';
export * from './types/api-request-types';
export * from './types/api-types';
export * from './test-tags/test-tags';
export * from './test-tags/test-tags';
export * from './fixtures/test-fixtures';
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { expect, test } from '@playwright/test'
import { PetStoreApi } from '@api-entities'
import { expect } from '@playwright/test';
import { test } from '@api-helpers';
import MockDataGenerator, { IPet, StatusCode, TestTags } from '@api-helpers';

test.describe.serial('CRUD API tests for the Pet Store API', async () => {
let petStoreCrudActions: PetStoreApi;
let id: number = 10;
let petId: number = 3193;


test.beforeEach(async ({ request }) => {
petStoreCrudActions = new PetStoreApi(request)
})

test('get a specific pet for sanity checkup - [GET] /pet/:petId', { tag: [TestTags.PET_STORE] }, async () => {
test('get a specific pet for sanity checkup - [GET] /pet/:petId', { tag: [TestTags.PET_STORE] }, async ({ petStoreApi }) => {
await test.step('make an api request to a specific pet ID', async () => {
let response = await petStoreCrudActions.getPet(id)
let response = await petStoreApi.getPet(id)
let responseJson: IPet = await response?.json()
expect(response?.status()).toBe(StatusCode.OK)
expect(responseJson.name).toBe('doggie')
})
})

test('create a new pet - [POST] /pet', { tag: [TestTags.PET_STORE] }, async () => {
test('create a new pet - [POST] /pet', { tag: [TestTags.PET_STORE] }, async ({ petStoreApi }) => {
await test.step('create a new pet via post request', async () => {
let petData = {
id: petId,
Expand All @@ -39,17 +33,17 @@ test.describe.serial('CRUD API tests for the Pet Store API', async () => {
],
status: 'available'
}
let response = await petStoreCrudActions.createNewPet(petData)
let response = await petStoreApi.createNewPet(petData)
let responseBody: IPet = await response?.json();
expect(response?.status()).toBe(StatusCode.OK);
expect(responseBody).toEqual(petData);
expect(response?.statusText()).toBe('OK');
})
})

test('validate pet exists - [GET] /pet/:petId', { tag: [TestTags.PET_STORE] }, async () => {
test('validate pet exists - [GET] /pet/:petId', { tag: [TestTags.PET_STORE] }, async ({ petStoreApi }) => {
await test.step('validate the pet that was created from previous test now exists', async () => {
let response = await petStoreCrudActions.getPet(petId)
let response = await petStoreApi.getPet(petId)
let responseBody: IPet = await response?.json();
expect(response).toBeTruthy()
expect(response?.status()).toBe(StatusCode.OK)
Expand All @@ -58,15 +52,15 @@ test.describe.serial('CRUD API tests for the Pet Store API', async () => {
})
})

test.skip('create pet image - [POST] /pet/:petId', { tag: [TestTags.PET_STORE] }, async () => {
test.skip('create pet image - [POST] /pet/:petId', { tag: [TestTags.PET_STORE] }, async ({ petStoreApi }) => {
await test.step('upload another image to the pet that was created in the previous test', async () => {
let imageFileName: string = 'pug.png'
let response = await petStoreCrudActions.uploadPetImage(petId, imageFileName);
let response = await petStoreApi.uploadPetImage(petId, imageFileName);
expect(response?.status()).toBe(StatusCode.OK);
})
})

test('update pet - [PATCH] /pet/:petId', { tag: [TestTags.PET_STORE] }, async () => {
test('update pet - [PATCH] /pet/:petId', { tag: [TestTags.PET_STORE] }, async ({ petStoreApi }) => {
await test.step('update the newly created pet that was created in previous test', async () => {
let petData = {
id: petId,
Expand All @@ -84,21 +78,21 @@ test.describe.serial('CRUD API tests for the Pet Store API', async () => {
],
status: 'available'
}
let response = await petStoreCrudActions.updatePet(petData)
let response = await petStoreApi.updatePet(petData)
let responseBody: IPet = await response?.json();
expect(response?.status()).toBe(StatusCode.OK)
expect(responseBody.name).toEqual('Pokey');
})
})

test('delete pet - [DELETE] /pet/:petId', { tag: [TestTags.PET_STORE] }, async () => {
test('delete pet - [DELETE] /pet/:petId', { tag: [TestTags.PET_STORE] }, async ({ petStoreApi }) => {
await test.step('delete the pet that was created and updated in previous tests', async () => {
let response = await petStoreCrudActions.deletePet(petId)
let response = await petStoreApi.deletePet(petId)
expect(response?.status()).toBe(StatusCode.OK)
})

await test.step('retrieve the deleted pet and validate it does not exist by validating response returns 404', async () => {
let deletedPet = await petStoreCrudActions.getPet(petId)
let deletedPet = await petStoreApi.getPet(petId)
expect(deletedPet?.status()).toBe(StatusCode.NOT_FOUND);
})
})
Expand Down
14 changes: 5 additions & 9 deletions tests/api_tests/pokemon/PokemonApiTests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { expect, test } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from '@api-helpers';
import { PokemonApi } from '@api-entities';
import { StatusCode } from '@api-helpers';
import { TestTags } from '@api-helpers';

test.describe('Pokemon API CRUD tests', async () => {
let pokemonApi: PokemonApi
let limit: number = 100;
let offset: number = 0

test.beforeEach(async ({ request }) => {
pokemonApi = new PokemonApi(request);
})

test('GET the pokemon resources - [GET] /pokemon', { tag: [TestTags.POKEMON_API] }, async () => {
test('GET the pokemon resources - [GET] /pokemon', { tag: [TestTags.POKEMON_API] }, async ({ pokemonApi }) => {
await test.step('GET first 20 pokemon resources by default and validate initial response', async () => {
let res = await pokemonApi.getPokemon();
let jsonResponse = await res?.json()
Expand All @@ -27,15 +23,15 @@ test.describe('Pokemon API CRUD tests', async () => {
})
})

test('get all pokemon resources pagination - [GET] /pokemon', { tag: [TestTags.POKEMON_API] }, async () => {
test('get all pokemon resources pagination - [GET] /pokemon', { tag: [TestTags.POKEMON_API] }, async ({ pokemonApi }) => {
await test.step('get all pokemon recourses via limit and offset pagination', async () => {
let response = await pokemonApi.getAllPokemonRecourses(limit, offset)
let responseLength = response?.length
expect(responseLength).toBe(1304)
})
})

test('response keys type validation - [GET] /pokemon', { tag: [TestTags.POKEMON_API] }, async () => {
test('response keys type validation - [GET] /pokemon', { tag: [TestTags.POKEMON_API] }, async ({ pokemonApi }) => {
await test.step('validate that each key in the results response object are equals to strings', async () => {
let res = await pokemonApi.getPokemon()
let resJson = await res?.json()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { test, expect } from '@playwright/test'
import { expect } from '@playwright/test';
import { test } from '@api-helpers';
import { Users } from '@api-entities';
import { StatusCode, TestTags } from '@api-helpers';

test.describe('Api tests for GoRestApi endpoints', async () => {
let users: Users;
let pageNumber: number = 1

test.beforeEach(async ({ request }) => {
users = new Users(request);
})

test('sanity check - [GET] /users', { tag: [TestTags.GO_REST_API] }, async () => {
await test.step('get users endpoint - validate status, body type of obejct properties and default length of the response', async () => {
let response = await users.getUsers();
test('sanity check - [GET] /users', { tag: [TestTags.GO_REST_API] }, async ({ usersApi }) => {
await test.step('get users endpoint - validate status, body type of object properties and default length of the response', async () => {
let response = await usersApi.getUsers();
expect(response?.status()).toBe(StatusCode.OK)
expect(response?.body()).toBeTruthy()
let actualObjectProperties = await users.getTypeOfUserProperties()
let actualObjectProperties = await usersApi.getTypeOfUserProperties()
let expectedObjectProperties = new Array(actualObjectProperties.length).fill(['number', 'string', 'string', 'string', 'string'])
expect(actualObjectProperties).toEqual(expectedObjectProperties)
})
Expand All @@ -24,32 +19,32 @@ test.describe('Api tests for GoRestApi endpoints', async () => {
/**
* @description there is a bug with this endpoint - it does not authorize any generated toke=n whatsoever
*/
test('gender equality - [POST] /users', { tag: [TestTags.GO_REST_API] }, async () => {
test('gender equality - [POST] /users', { tag: [TestTags.GO_REST_API] }, async ({ usersApi }) => {
await test.step('make an api request to make both male and female genders equal', async () => {
await users.makeBothGendersEven();
let maleGender = await users.getGender('male')
let femaleGender = await users.getGender('female')
await usersApi.makeBothGendersEven();
let maleGender = await usersApi.getGender('male')
let femaleGender = await usersApi.getGender('female')
expect(maleGender).toEqual(femaleGender)
})
})

test('replace email extension of users - [PATCH] /users/:userId', { tag: [TestTags.GO_REST_API] }, async () => {
test('replace email extension of users - [PATCH] /users/:userId', { tag: [TestTags.GO_REST_API] }, async ({ usersApi }) => {
await test.step('extract extension of each user email and replace each extension with co.il', async () => {
let response = await users.replaceEmailExtensionForUsers()
let response = await usersApi.replaceEmailExtensionForUsers()
expect(response?.status()).toBe(StatusCode.OK)
})
await test.step('validate previous extensions were replaced with co.il extension', async () => {
let actualEmailExtensions = await users.getCurrentUserEmailExtension()
let actualEmailExtensions = await usersApi.getCurrentUserEmailExtension()
let expectedExtensions = new Array(actualEmailExtensions.length).fill('.co.il')
expect(actualEmailExtensions).toEqual(expectedExtensions)
})
})

test('delete inactive users - [DELETE] /users/:userId', { tag: [TestTags.GO_REST_API] }, async () => {
test('delete inactive users - [DELETE] /users/:userId', { tag: [TestTags.GO_REST_API] }, async ({ usersApi }) => {
await test.step('make a request to delete all users that have an inactive status', async () => {
let response = await users.deleteInactiveUsers()
let response = await usersApi.deleteInactiveUsers()
expect(response?.status()).toBe(StatusCode.UNAUTHORIZED)
let actualInactiveUsers = await users.getInActiveUsers()
let actualInactiveUsers = await usersApi.getInActiveUsers()
let expectedInactiveUsersLength = actualInactiveUsers.length
expect(expectedInactiveUsersLength).toBe(0)
})
Expand Down