Skip to content

Commit

Permalink
added scripts for creating and searching a pet (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
akashbalhara committed May 4, 2023
2 parents 2ccf92a + 1014dc2 commit d3c311a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/add_pet.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// @ts-check
import {test, expect} from "@playwright/test"

test ("Create a new pet", async({request, baseURL}) => {

const response = await request.post(`${baseURL}pet`, {
data: {
"id": 6199,
"category": {
"id": 2107,
"name": "playwright dog"
},
"name": "playwright Tommy",
"photoUrls": [
"string"
],
"tags": [
{
"id": 1708,
"name": "black"
}
],
"status": "available"

}
});

// assert that the api is working as expected
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);

// saving created pet info
const petDetail = await response.json();

});
46 changes: 46 additions & 0 deletions tests/get_pet.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// @ts-check
import {test, expect} from "@playwright/test"

test("Create a pet and fetch its detail", async({request, baseURL}) => {
const response = await request.post(`${baseURL}pet`, {
data : {
"id": Date.now(),
"category": {
"id": 8077,
"name": "playwright cat"
},
"name": "playwright duffy",
"photoUrls": [
"string"
],
"tags": [
{
"id": 7017,
"name": "white"
}
],
"status": "available"
}
});

// assert that the api is working as expected
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);

// saving the pet id of the newly created pet
const petInfo = await response.json();
const petId = petInfo.id

// getting the details of the pet using petid
const getPet = await request.get(`${baseURL}pet/`+petId);

// assert that the api is working as expected
expect(getPet.ok()).toBeTruthy();
expect(getPet.status()).toBe(200);


// stroing the pet details and assert that the petid is correct
const pet_Info = await getPet.json();
expect(pet_Info.id).toBe(petId);

});

0 comments on commit d3c311a

Please sign in to comment.