From 9e525025d72e4879d7a27afaec8c5dd6b4eb5fbb Mon Sep 17 00:00:00 2001 From: Debora Serra Date: Thu, 28 Nov 2024 17:20:16 -0800 Subject: [PATCH] chore: add code rabbit suggestions --- backend/src/test/e2e/hint.test.js | 22 +++++++++- backend/src/test/e2e/popup.test.js | 66 +++++++++++------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/backend/src/test/e2e/hint.test.js b/backend/src/test/e2e/hint.test.js index ec6d6c2c..e13618f6 100644 --- a/backend/src/test/e2e/hint.test.js +++ b/backend/src/test/e2e/hint.test.js @@ -1,8 +1,8 @@ import { expect } from "chai"; import { after, afterEach, before, beforeEach, describe } from "mocha"; import waitOn from "wait-on"; -import app from "../../server.js"; import db from "../../models/index.js"; +import app from "../../server.js"; import mocks from "../mocks/hint.mock.js"; import { UserBuilder, validList } from "../mocks/user.mock.js"; import chai from "./index.js"; @@ -487,6 +487,25 @@ describe("E2e tests hint", () => { .set("Authorization", `Bearer ${token}`); expect(res).to.have.status(200); expect(res.body).to.be.have.length(10); + res.body.forEach((it) => { + expect(it).to.have.all.keys([ + "id", + "action", + "hintContent", + "actionButtonText", + "actionButtonUrl", + "headerBackgroundColor", + "headerColor", + "textColor", + "buttonBackgroundColor", + "buttonTextColor", + "createdBy", + "creator", + "header", + "targetElement", + "tooltipPlacement", + ]); + }); }); }); describe("GET /api/hint/hints", () => { @@ -552,6 +571,7 @@ describe("E2e tests hint", () => { expect(res).to.have.status(200); expect(res.body).not.to.be.deep.equal(hintList); expect(res.body).to.have.length(5); + expect(res.body.every((it) => it.createdBy === 1)).to.be.true; }); }); describe("GET /api/hint/get_hint/:id", () => { diff --git a/backend/src/test/e2e/popup.test.js b/backend/src/test/e2e/popup.test.js index 4662a4f9..6774038a 100644 --- a/backend/src/test/e2e/popup.test.js +++ b/backend/src/test/e2e/popup.test.js @@ -1,8 +1,8 @@ import { expect } from "chai"; import { after, afterEach, before, beforeEach, describe } from "mocha"; import waitOn from "wait-on"; -import app from "../../server.js"; import db from "../../models/index.js"; +import app from "../../server.js"; import mocks from "../mocks/popup.mock.js"; import { UserBuilder, validList } from "../mocks/user.mock.js"; import chai from "./index.js"; @@ -18,15 +18,25 @@ const dbReadyOptions = { const popup = mocks.PopupBuilder.popup; const popupList = mocks.popupList; -describe("E2e tests popup", () => { - describe("POST /api/popup/add_popup", () => { - before(async () => { - db.sequelize.connectionManager.initPools(); - }); - after(async () => { +const setupTestDatabase = () => { + before(async () => { + db.sequelize.connectionManager.initPools(); + }); + + after(async () => { + try { const conn = await db.sequelize.connectionManager.getConnection(); db.sequelize.connectionManager.releaseConnection(conn); - }); + } catch (error) { + console.error("Failed to release database connection:", error); + throw error; + } + }); +}; + +describe("E2e tests popup", () => { + describe("POST /api/popup/add_popup", () => { + setupTestDatabase(); let token; beforeEach(async () => { @@ -222,13 +232,7 @@ describe("E2e tests popup", () => { }); }); describe("DELETE /api/popup/delete_popup/:id", () => { - before(async () => { - db.sequelize.connectionManager.initPools(); - }); - after(async () => { - const conn = await db.sequelize.connectionManager.getConnection(); - db.sequelize.connectionManager.releaseConnection(conn); - }); + setupTestDatabase(); let token; beforeEach(async () => { @@ -327,13 +331,7 @@ describe("E2e tests popup", () => { }); }); describe("PUT /api/popup/edit_popup/:id", () => { - before(async () => { - db.sequelize.connectionManager.initPools(); - }); - after(async () => { - const conn = await db.sequelize.connectionManager.getConnection(); - db.sequelize.connectionManager.releaseConnection(conn); - }); + setupTestDatabase(); let token; beforeEach(async () => { @@ -535,13 +533,7 @@ describe("E2e tests popup", () => { }); }); describe("GET /api/popup/all_popups", () => { - before(async () => { - db.sequelize.connectionManager.initPools(); - }); - after(async () => { - const conn = await db.sequelize.connectionManager.getConnection(); - db.sequelize.connectionManager.releaseConnection(conn); - }); + setupTestDatabase(); let token; beforeEach(async () => { @@ -599,13 +591,7 @@ describe("E2e tests popup", () => { }); }); describe("GET /api/popup/popups", () => { - before(async () => { - db.sequelize.connectionManager.initPools(); - }); - after(async () => { - const conn = await db.sequelize.connectionManager.getConnection(); - db.sequelize.connectionManager.releaseConnection(conn); - }); + setupTestDatabase(); let token; beforeEach(async () => { @@ -664,13 +650,7 @@ describe("E2e tests popup", () => { }); }); describe("GET /api/popup/get_popup/:id", () => { - before(async () => { - db.sequelize.connectionManager.initPools(); - }); - after(async () => { - const conn = await db.sequelize.connectionManager.getConnection(); - db.sequelize.connectionManager.releaseConnection(conn); - }); + setupTestDatabase(); let token; beforeEach(async () => {