Skip to content

Commit

Permalink
Merge pull request #6 from fga-eps-mds/devel
Browse files Browse the repository at this point in the history
[fix:34] - fix benefits test
  • Loading branch information
saracampss authored Aug 23, 2024
2 parents b276b88 + 3d9b7fa commit 3e96f2c
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/__tests__/benefitsFormController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const routes = require("../routes");
const BenefitsModel = require("../Models/benefitsFormSchema");
const { MongoMemoryServer } = require("mongodb-memory-server");

const mockedBenefit = {
nome: "Health Benefits",
razaoSocial: "Empresa Saúde S/A",
statusConvenio: "Ativo",
considerarIr: "Sim",
descontoAut: "Não",
};

const app = express();
let mongoServer;

Expand All @@ -22,29 +30,25 @@ app.use(express.urlencoded({ extended: true }));
// Rotas
app.use("/", routes);

beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const uri = mongoServer.getUri();

await mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
describe("BenefitsForm Controller Tests", () => {
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const uri = mongoServer.getUri();

await mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
});
});

afterAll(async () => {
await mongoose.connection.close();
await mongoServer.stop();
});
afterAll(async () => {
await mongoose.connection.close();
await mongoServer.stop();
});

describe("BenefitsForm Controller Tests", () => {
const mockedBenefit = {
nome: "Health Benefits",
razaoSocial: "Empresa Saúde S/A",
statusConvenio: "Ativo",
considerarIr: "Sim",
descontoAut: "Não",
};
afterEach(async () => {
await BenefitsModel.deleteMany({});
});

it("should create a new benefit", async () => {
const res = await request(app)
Expand All @@ -64,16 +68,16 @@ describe("BenefitsForm Controller Tests", () => {

const res = await request(app).get(`/benefits/${createdBenefit._id}`);

expect(res.status).toBe(200);
expect(res.body).toMatchObject(createdBenefit);
expect(res.status).toBe(200);
});

it("should get benefits", async () => {
const benefitsModelCount = await BenefitsModel.countDocuments({});
const res = await request(app).get("/benefits");

expect(res.status).toBe(200);
expect(res.body.length).toBe(benefitsModelCount);
expect(res.status).toBe(200);
});

it("should delete benefit", async () => {
Expand All @@ -88,8 +92,8 @@ describe("BenefitsForm Controller Tests", () => {
`/benefits/delete/${createdBenefit._id}`
);

expect(res.status).toBe(200);
expect(res.body).toMatchObject(createdBenefit);
expect(res.status).toBe(200);
});

it("should update benefit", async () => {
Expand Down

0 comments on commit 3e96f2c

Please sign in to comment.