From 44ae1ae063e8394874645469c92c8bb403d97a6f Mon Sep 17 00:00:00 2001 From: artshllk Date: Sat, 21 Dec 2024 12:11:02 +0100 Subject: [PATCH 1/2] cy: improve api comments & contacts assertions and readability --- cypress/tests/api/api-comments.spec.ts | 9 ++++++--- cypress/tests/api/api-contacts.spec.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cypress/tests/api/api-comments.spec.ts b/cypress/tests/api/api-comments.spec.ts index c40daccdb..6886dee0b 100644 --- a/cypress/tests/api/api-comments.spec.ts +++ b/cypress/tests/api/api-comments.spec.ts @@ -34,19 +34,22 @@ describe("Comments API", function () { context("GET /comments/:transactionId", function () { it("gets a list of comments for a transaction", function () { - cy.request("GET", `${apiComments}/${ctx.transactionId}`).then((response) => { + const transactionId = ctx.transactionId!; + cy.request("GET", `${apiComments}/${transactionId}`).then((response) => { expect(response.status).to.eq(200); - expect(response.body.comments.length).to.eq(1); + expect(response.body.comments).to.be.an("array").that.has.length(1); }); }); }); context("POST /comments/:transactionId", function () { it("creates a new comment for a transaction", function () { - cy.request("POST", `${apiComments}/${ctx.transactionId}`, { + const transactionId = ctx.transactionId!; + cy.request("POST", `${apiComments}/${transactionId}`, { content: "This is my comment", }).then((response) => { expect(response.status).to.eq(200); + expect(response.body.comment.content).to.eq("This is my comment"); }); }); }); diff --git a/cypress/tests/api/api-contacts.spec.ts b/cypress/tests/api/api-contacts.spec.ts index d21d1b1dd..52cda995e 100644 --- a/cypress/tests/api/api-contacts.spec.ts +++ b/cypress/tests/api/api-contacts.spec.ts @@ -63,7 +63,7 @@ describe("Contacts API", function () { }, }).then((response) => { expect(response.status).to.eq(422); - expect(response.body.errors.length).to.eq(1); + expect(response.body.errors).to.be.an("array").that.has.length(1); }); }); }); From 542ccb381a53b93d4ca30a38629b8ec2a96e2832 Mon Sep 17 00:00:00 2001 From: artshllk Date: Sat, 21 Dec 2024 12:20:45 +0100 Subject: [PATCH 2/2] remove assertion --- cypress/tests/api/api-comments.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/cypress/tests/api/api-comments.spec.ts b/cypress/tests/api/api-comments.spec.ts index 6886dee0b..547d25bd3 100644 --- a/cypress/tests/api/api-comments.spec.ts +++ b/cypress/tests/api/api-comments.spec.ts @@ -49,7 +49,6 @@ describe("Comments API", function () { content: "This is my comment", }).then((response) => { expect(response.status).to.eq(200); - expect(response.body.comment.content).to.eq("This is my comment"); }); }); });