diff --git a/tests/fixtures/playwright_dog_pic.jpg b/tests/fixtures/playwright_dog_pic.jpg new file mode 100644 index 0000000..56cf9a5 Binary files /dev/null and b/tests/fixtures/playwright_dog_pic.jpg differ diff --git a/tests/upload_image.spec.js b/tests/upload_image.spec.js new file mode 100644 index 0000000..c45bc2a --- /dev/null +++ b/tests/upload_image.spec.js @@ -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); +});