Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create pet #6

Closed
wants to merge 10 commits into from
Closed
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
Binary file added tests/fixtures/playwright_dog_pic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions tests/upload_image.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//@ts-check
import {test, expect} from "@playwright/test"
import path from "path";
import fs from "fs";

test("Create a pet and Upload image for the 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);

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

// setting file path and buffer
const file = path.resolve("tests/fixtures/", "playwright_dog_pic.jpg");
const image = fs.readFileSync(file);
const metaData = "Dog Image";

// uploading image
const uploadImg = await request.post(`${baseURL}pet/`+petId+'/uploadImage' , {
headers:{
ContentType: "multipart/form-data",
Accept: "*/*",
},
multipart: {
file : {
name : file,
mimeType : "image/jpeg",
buffer : image,
},
additionalMetadata : metaData
}
})

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

// assert that the correct metadata is getting returned
expect((await uploadImg.json()).message).toContain(metaData);
});
Loading