mirror of
https://github.com/netlight/my-finance-pal-backend.git
synced 2024-09-20 04:31:07 +02:00
Integration test wip
This commit is contained in:
parent
be1bcf8485
commit
0140e37fa6
1 changed files with 42 additions and 0 deletions
42
src/routes/budget/budgetRouter.integration.spec.ts
Normal file
42
src/routes/budget/budgetRouter.integration.spec.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { type BudgetDto, type NewBudgetDto } from "./dto/budget";
|
||||
import mongoose from "mongoose";
|
||||
import env from "../../config/environment";
|
||||
import request from "supertest";
|
||||
import app from "../../app";
|
||||
|
||||
describe("budgetRouter", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await mongoose.connect(env.DATABASE_CONNECTION_STRING, {
|
||||
dbName: env.DATABASE_NAME,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
afterEach(async () => {
|
||||
try {
|
||||
await mongoose.connection.close();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
it("calls the create function with the correct object", async () => {
|
||||
// GIVEN
|
||||
const newBudgetDto: NewBudgetDto = {
|
||||
name: "My Budget",
|
||||
limit: 250,
|
||||
};
|
||||
const expectedResponseDto: Omit<BudgetDto, "id"> = {
|
||||
limit: newBudgetDto.limit,
|
||||
spent: 0,
|
||||
name: newBudgetDto.name,
|
||||
};
|
||||
// WHEN
|
||||
const response = await request(app).post("/budgets").send(newBudgetDto);
|
||||
|
||||
// THEN
|
||||
expect(response.statusCode).toBe(201);
|
||||
expect(response.body).toEqual(expect.objectContaining(expectedResponseDto));
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue