Skip to content

Commit

Permalink
script to update a pet (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
akashbalhara committed May 6, 2023
2 parents d3c311a + 2606124 commit 9da6fdb
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/update_pet.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//@ts-check
import {test, expect} from "@playwright/test"

test("Create and update pet", 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);

// assert that the data is correct
expect(((await response.json()).category).name).toBe("playwright cat");
expect(((await response.json()).tags[0]).name).toBe("white");

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

// updating the created pet
const updatePet = await request.put(`${baseURL}pet`, {
data : {
"id": petId,
"category": {
"id": 8077,
"name": "playwright dog"
},
"name": "playwright duffy",
"photoUrls": [
"string"
],
"tags": [
{
"id": 7017,
"name": "black"
}
],
"status": "available"
}
})

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

// assert that the correct changes were made
expect(((await updatePet.json()).category).name).toBe("playwright dog");
expect(((await updatePet.json()).tags[0]).name).toBe("black");

});

0 comments on commit 9da6fdb

Please sign in to comment.