-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pet store entity and added small sanity tests
- Loading branch information
Romario
authored and
Romario
committed
Nov 28, 2023
1 parent
8b6ad9e
commit 70f3743
Showing
9 changed files
with
169 additions
and
16 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
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,5 +1,6 @@ | ||
export enum ApiEndpoints { | ||
PET_STORE_ENDPOINT = 'pet', | ||
PET = 'pet', | ||
UPLOAD_IMAGE = 'uploadImage', | ||
POKEMON_API = '', | ||
GO_REST_API = '', | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { fa, faker } from "@faker-js/faker"; | ||
|
||
export default class Randomizer { | ||
|
||
public static getDogNameBreed(): string { | ||
return faker.animal.dog() | ||
} | ||
|
||
public static getCatNameBreed(): string { | ||
return faker.animal.cat() | ||
} | ||
|
||
public static getRandomLongNumber(): number { | ||
return faker.number.int({ min: 1000, max: 5000 }) | ||
} | ||
|
||
public static getRandomName(): string { | ||
return faker.internet.domainName() | ||
} | ||
} |
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,5 +1,17 @@ | ||
export interface Ipet<T> { | ||
export interface Ipet { | ||
id?: number, | ||
category?: { [key: string]: T }, | ||
category?: { [key: string]: any }, | ||
name: string, | ||
photoUrls: string[] | ||
tags?: { [key: string]: any }, | ||
status?: string, | ||
} | ||
|
||
export interface Ipokemon { | ||
|
||
} | ||
|
||
|
||
export interface IgoRestApi { | ||
|
||
} |
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
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,21 +1,80 @@ | ||
import { expect, test } from '@playwright/test' | ||
import { PetStoreCrudActions } from '../../../infra/api/entities/petStore/PetStoreCrudActions' | ||
import { STATUS_CODES } from 'http'; | ||
import { StatusCode } from '../../../infra/api/apiRequests/ApiRequests'; | ||
import { Ipet } from '../../../infra/api/interfaces/ApiObjectsInterfaces'; | ||
import Randomizer from '../../../infra/api/helpers/faker/Randomizer'; | ||
|
||
test.describe('CRUD API tests for the Pet Store API', async () => { | ||
let petStoreCrudActions: PetStoreCrudActions; | ||
let petId: number = 10; | ||
let createdPedtId: number = 3193; | ||
|
||
|
||
test.beforeEach(async ({ request }) => { | ||
petStoreCrudActions = new PetStoreCrudActions(request) | ||
}) | ||
|
||
test('get a specific pet resource', async () => { | ||
test('get a specific pet for sanity checkup @PET_STORE', async () => { | ||
await test.step('make an api request to a specific pet ID', async () => { | ||
let response = await petStoreCrudActions.getPet(petId) | ||
let responseJson = await response?.json() | ||
console.log(responseJson); | ||
expect(response?.status()).toBe(200) | ||
let responseJson: Ipet = await response?.json() | ||
expect(response?.status()).toBe(StatusCode.OK) | ||
expect(responseJson.name).toBe('doggie') | ||
}) | ||
}) | ||
|
||
test('create a new pet @PET_STORE', async () => { | ||
await test.step('create a new pet via post request', async () => { | ||
let petData = { | ||
id: Randomizer.getRandomLongNumber(), | ||
category: { | ||
id: Randomizer.getRandomLongNumber(), | ||
name: Randomizer.getRandomName() | ||
}, | ||
name: Randomizer.getDogNameBreed(), | ||
photoUrls: ['https://ibb.co/wLWCrSX'], | ||
tags: [ | ||
{ | ||
id: Randomizer.getRandomLongNumber(), | ||
name: Randomizer.getRandomName(), | ||
} | ||
], | ||
status: 'available' | ||
} | ||
let response = await petStoreCrudActions.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 the pet existance', async () => { | ||
await test.step('validate the pet that was created from previous test now exists', async () => { | ||
let response = await petStoreCrudActions.getPet(createdPedtId) | ||
let responseBody: Ipet = await response?.json(); | ||
expect(response).toBeTruthy() | ||
expect(response?.status()).toBe(StatusCode.OK) | ||
expect(responseBody.id).toEqual(createdPedtId) | ||
expect(responseBody.name).toEqual('Shiloh Shepherd') | ||
}) | ||
}) | ||
|
||
test('create pet image', async () => { | ||
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(createdPedtId, imageFileName); | ||
expect(response?.status()).toBe(StatusCode.OK); | ||
|
||
}) | ||
}) | ||
|
||
// (property) multipart?: { | ||
// [key: string]: string | number | boolean | ReadStream | { | ||
// name: string; | ||
// mimeType: string; | ||
// }; | ||
// } | undefined | ||
|
||
}) |