From 6f96b25ca6405f83f1939b1dd143eb7c9bcc707f Mon Sep 17 00:00:00 2001 From: artshllaku <77685827+artshllk@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:40:41 +0100 Subject: [PATCH] cy: improve api comments & contacts assertions and readability (#1604) * cy: improve api comments & contacts assertions and readability * remove assertion --- cypress/tests/api/api-comments.spec.ts | 8 +++++--- cypress/tests/api/api-contacts.spec.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cypress/tests/api/api-comments.spec.ts b/cypress/tests/api/api-comments.spec.ts index c40daccdb..547d25bd3 100644 --- a/cypress/tests/api/api-comments.spec.ts +++ b/cypress/tests/api/api-comments.spec.ts @@ -34,16 +34,18 @@ 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); 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); }); }); });