From 29149bb582913898f5e942989e774bee54dd2b02 Mon Sep 17 00:00:00 2001 From: Alex Stefan Date: Sun, 28 Jan 2024 01:28:10 +0200 Subject: [PATCH 1/2] added apiTestsAlex --- tests/apiTests/apiTestsAlex.spec.js | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/apiTests/apiTestsAlex.spec.js diff --git a/tests/apiTests/apiTestsAlex.spec.js b/tests/apiTests/apiTestsAlex.spec.js new file mode 100644 index 0000000..54be88b --- /dev/null +++ b/tests/apiTests/apiTestsAlex.spec.js @@ -0,0 +1,67 @@ +import { test, expect } from "@playwright/test"; + +test("Get", async ({ request }) => { + const response = await await request.get( + "https://martioli.com/apifortesting" + ); + expect(response.ok()).toBeTruthy(); + const data = await response.json(); +}); + +let id; +test("CREATE", async ({ request }) => { + const newData = { + developer: "Imaginatie", + QA: "Distrugere", + manager: "Sefu", + automation: "Yes", + task: "Faceti bani", + story_points: 10, + }; + + const response = await request.post("https://martioli.com/apifortesting", { + data: newData, + }); + expect(response.ok()).toBeTruthy(); + const data = await response.json(); + id = data.id; + expect(data.QA).toBe(newData.QA); +}); + +test("PATCH", async ({ request }) => { + const dataChange = { QA: "Testarica", task: "distrugeti" }; + const response = await request.patch( + `https://martioli.com/apifortesting/id/${id}`, + { data: dataChange } + ); + expect(response.ok()).toBeTruthy(); + const data = await response.json(); + expect(data.QA).toBe(dataChange.QA); + expect(data.task).toBe(dataChange.task); +}); + +test("PUT", async ({ request }) => { + const dataChange = { + developer: "Ghita", + QA: "Developer-ul", + manager: "Angajam", + automation: "nu promitem", + task: "Proiect bun", + story_points: 10, + }; + const response = await request.put( + `https://martioli.com/apifortesting/id/${id}`, + { data: dataChange } + ); + expect(response.ok()).toBeTruthy(); + const data = await response.json(); + expect(data.QA).toBe(dataChange.QA); + expect(data.task).toBe(dataChange.task); +}); + +test("DELETE", async ({ request }) => { + const response = await request.delete( + `https://martioli.com/apifortesting/id/${id}` + ); + expect(response.ok()).toBeTruthy(); +}); From 9e14d9f818a8a321fb54ed08c82a0292df02efc2 Mon Sep 17 00:00:00 2001 From: Alex Stefan Date: Sat, 10 Feb 2024 21:44:29 +0200 Subject: [PATCH 2/2] combined in one test --- tests/apiTests/apiTestsAlex.spec.js | 71 +++++++++++++---------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/tests/apiTests/apiTestsAlex.spec.js b/tests/apiTests/apiTestsAlex.spec.js index 54be88b..34e2f8e 100644 --- a/tests/apiTests/apiTestsAlex.spec.js +++ b/tests/apiTests/apiTestsAlex.spec.js @@ -1,15 +1,12 @@ import { test, expect } from "@playwright/test"; -test("Get", async ({ request }) => { - const response = await await request.get( - "https://martioli.com/apifortesting" - ); - expect(response.ok()).toBeTruthy(); - const data = await response.json(); -}); +test("CRUD Operations", async ({ request }) => { + // GET + const getResponse = await request.get("https://martioli.com/apifortesting"); + expect(getResponse.ok()).toBeTruthy(); + const initialData = await getResponse.json(); -let id; -test("CREATE", async ({ request }) => { + // CREATE const newData = { developer: "Imaginatie", QA: "Distrugere", @@ -19,29 +16,26 @@ test("CREATE", async ({ request }) => { story_points: 10, }; - const response = await request.post("https://martioli.com/apifortesting", { + const createResponse = await request.post("https://martioli.com/apifortesting", { data: newData, }); - expect(response.ok()).toBeTruthy(); - const data = await response.json(); - id = data.id; - expect(data.QA).toBe(newData.QA); -}); + expect(createResponse.ok()).toBeTruthy(); + const createdData = await createResponse.json(); + expect(createdData.QA).toBe(newData.QA); -test("PATCH", async ({ request }) => { - const dataChange = { QA: "Testarica", task: "distrugeti" }; - const response = await request.patch( - `https://martioli.com/apifortesting/id/${id}`, - { data: dataChange } + // PATCH + const dataChangePatch = { QA: "Testarica", task: "distrugeti" }; + const patchResponse = await request.patch( + `https://martioli.com/apifortesting/id/${createdData.id}`, + { data: dataChangePatch } ); - expect(response.ok()).toBeTruthy(); - const data = await response.json(); - expect(data.QA).toBe(dataChange.QA); - expect(data.task).toBe(dataChange.task); -}); + expect(patchResponse.ok()).toBeTruthy(); + const patchedData = await patchResponse.json(); + expect(patchedData.QA).toBe(dataChangePatch.QA); + expect(patchedData.task).toBe(dataChangePatch.task); -test("PUT", async ({ request }) => { - const dataChange = { + // PUT + const dataChangePut = { developer: "Ghita", QA: "Developer-ul", manager: "Angajam", @@ -49,19 +43,18 @@ test("PUT", async ({ request }) => { task: "Proiect bun", story_points: 10, }; - const response = await request.put( - `https://martioli.com/apifortesting/id/${id}`, - { data: dataChange } + const putResponse = await request.put( + `https://martioli.com/apifortesting/id/${createdData.id}`, + { data: dataChangePut } ); - expect(response.ok()).toBeTruthy(); - const data = await response.json(); - expect(data.QA).toBe(dataChange.QA); - expect(data.task).toBe(dataChange.task); -}); + expect(putResponse.ok()).toBeTruthy(); + const putData = await putResponse.json(); + expect(putData.QA).toBe(dataChangePut.QA); + expect(putData.task).toBe(dataChangePut.task); -test("DELETE", async ({ request }) => { - const response = await request.delete( - `https://martioli.com/apifortesting/id/${id}` + // DELETE + const deleteResponse = await request.delete( + `https://martioli.com/apifortesting/id/${createdData.id}` ); - expect(response.ok()).toBeTruthy(); + expect(deleteResponse.ok()).toBeTruthy(); });