WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
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
66 changes: 66 additions & 0 deletions test-data/pets.Data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"order1": {
"id": 1,
"petId": 0,
"quantity": 0,
"shipDate": "2025-01-01T17:00:00.000Z",
"status": "placed",
"complete": true
},
"pet2": {
"id": 2,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": ["string"],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": ["available", "pending", "sold"]
},

"pet2update": {
"id": 2,
"category": {
"id": 0,
"name": "string",
"updatedName": "Updated Pet Name"
},
"name": "kitty",
"photoUrls": ["string"],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": ["available", "pending", "sold"]
},

"pet4": {
"id": 4,
"status": ["available", "pending", "sold"]
},

"pet6": {
"id": 6,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": ["string"],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
}
File renamed without changes.
91 changes: 19 additions & 72 deletions tests/petTests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect, request } from "@playwright/test";
import * as fs from "fs";
import * as path from "path";
import pets from "../test-data/pets.Data.json"

const backendURL: string = "https://petstore.swagger.io/v2/pet";

Expand Down Expand Up @@ -37,22 +38,7 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =
test("Add a new pet to the store", async () => {
const context = await request.newContext();
const response = await context.post(`${backendURL}`, {
data: {
id: 2,
category: {
id: 0,
name: "string",
},
name: "doggie",
photoUrls: ["string"],
tags: [
{
id: 0,
name: "string",
},
],
status: "available",
},
data:pets.pet2,
});
expect(response.status()).toBe(200);
const responseBody = await response.json();
Expand All @@ -62,22 +48,7 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =
test("Update an existing pet", async () => {
const context = await request.newContext();
const response = await context.post(`${backendURL}`, {
data: {
id: 2,
category: {
id: 0,
name: "string",
},
name: "kitty",
photoUrls: ["string"],
tags: [
{
id: 0,
name: "string",
},
],
status: "available",
},
data: pets.pet2update
});
expect(response.status()).toBe(200);
const responseBody = await response.json();
Expand All @@ -87,55 +58,51 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =

test.describe("Find pet by status: available, pending, sold", () => {
test('Should return pets with status "pending"', async ({ request }) => {
const status = "pending";
const response = await request.get(`${backendURL}/findByStatus`, {
params: { status },
params: pets.pet2.status[1],
});

expect(response.status()).toBe(200);

const responseBody = await response.json();
expect(Array.isArray(responseBody)).toBeTruthy();
responseBody.forEach((pet) => {
expect(pet.status).toBe("pending");
expect(pet.status).toBe(pets.pet2.status[1]);
});
});
});

test('Should return pets with status "available"', async ({ request }) => {
const status = "available";
const response = await request.get(`${backendURL}/findByStatus`, {
params: { status },
params: pets.pet2.status[0],
});

expect(response.status()).toBe(200);

const responseBody = await response.json();
expect(Array.isArray(responseBody)).toBeTruthy();
responseBody.forEach((pet) => {
expect(pet.status).toBe("available");
expect(pet.status).toBe(pets.pet2.status[0]);
});
});

test('Should return pets with status "sold"', async ({ request }) => {
const status = "sold";
const response = await request.get(`${backendURL}/findByStatus`, {
params: { status },
params: pets.pet2.status[2],
});

expect(response.status()).toBe(200);
const responseBody = await response.json();
expect(Array.isArray(responseBody)).toBeTruthy();
responseBody.forEach((pet) => {
expect(pet.status).toBe("sold");
expect(pet.status).toBe(pets.pet2.status[2]);
});
});

test.describe("Find pet by ID, update pet in the store", async () => {
test("Find pet", async () => {
const petId = 4;
const context = await request.newContext();
const response = await context.get(`${backendURL}/${petId}`);
const response = await context.get(`${backendURL}/${pets.pet4.id}`);
expect(response.status()).toBe(200);

const responseBody = await response.json();
Expand All @@ -144,44 +111,25 @@ test.describe("Find pet by ID, update pet in the store", async () => {
});

test("Update pet information", async () => {
const petId = 2;
const updatedName = "Updated Pet Name";
const updatedStatus = "sold";
const context = await request.newContext();
const response = await context.post(`${backendURL}/${petId}`, {
const response = await context.post(`${backendURL}/${pets.pet2update.id}`, {
form: {
name: updatedName,
status: updatedStatus,
name: pets.pet2update.name,
status: pets.pet2update.status[2]
},
});
expect(response.status()).toBe(200);

const responseBody = await response.json();
console.log(responseBody);
expect(responseBody.message).toBe(petId.toString());
expect(responseBody.message).toBe(pets.pet2update.id.toString());
});

test.describe("Delete pet by ID", async () => {
const petId = 6;
test.beforeAll(async () => {
const context = await request.newContext();
const response = await context.post(`${backendURL}`, {
data: {
id: petId,
category: {
id: 0,
name: "string",
},
name: "doggie",
photoUrls: ["string"],
tags: [
{
id: 0,
name: "string",
},
],
status: "available",
},
data: pets.pet6
});
expect(response.status()).toBe(200);
const responseBody = await response.json();
Expand All @@ -191,7 +139,7 @@ test.describe("Delete pet by ID", async () => {
test("Delete pet", async () => {
const context = await request.newContext();
const apiKey = "your_actual_api_key";
const response = await context.delete(`${backendURL}/${petId}`, {
const response = await context.delete(`${backendURL}/${pets.pet6.id}`, {
headers: {
api_key: apiKey,
},
Expand All @@ -203,10 +151,9 @@ test.describe("Delete pet by ID", async () => {
});

test.afterAll(async () => {
const petId = 6;
const context = await request.newContext();
const response = await context.delete(`${backendURL}/${petId}`);
const response = await context.delete(`${backendURL}/${pets.pet6.id}`);

expect(response.status()).toBe(404);
expect(response.status()).toBe(404);
});
});
});
2 changes: 1 addition & 1 deletion tests/userTests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import * as utilities from './utilities';
import { validUserName, validPassword } from '../playwright.config';
import testData from "../test-data/test.data.json"
import testData from "../test-data/users.data.json";

test.describe('User part tests', () => {
test('Create User', async () => {
Expand Down
Loading