From 0140e37fa6b32d07aebc680a9ac7f627d845e0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20=C3=96zdere?= Date: Sun, 2 Apr 2023 00:34:46 +0200 Subject: [PATCH] Integration test wip --- .../budget/budgetRouter.integration.spec.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/routes/budget/budgetRouter.integration.spec.ts diff --git a/src/routes/budget/budgetRouter.integration.spec.ts b/src/routes/budget/budgetRouter.integration.spec.ts new file mode 100644 index 0000000..8beb02d --- /dev/null +++ b/src/routes/budget/budgetRouter.integration.spec.ts @@ -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 = { + 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)); + }); +});