Skip to content

Commit

Permalink
chore: add code rabbit suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
DeboraSerra committed Nov 29, 2024
1 parent 954e848 commit 9e52502
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
22 changes: 21 additions & 1 deletion backend/src/test/e2e/hint.test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down
66 changes: 23 additions & 43 deletions backend/src/test/e2e/popup.test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 9e52502

Please sign in to comment.