diff --git a/env/production.env b/env/production.env index f854c80..a9c5be3 100644 --- a/env/production.env +++ b/env/production.env @@ -1,4 +1,5 @@ ## Server ## PORT=8080 NODE_ENV=production +DATABASE_CONNECTION_STRING=mongodb://mongo:27017 DATABASE_NAME=my-finance-pal diff --git a/env/test.env b/env/test.env index 63ab6ed..f9ec032 100644 --- a/env/test.env +++ b/env/test.env @@ -1,3 +1,5 @@ ## Server ## PORT=3000 -NODE_ENV=test \ No newline at end of file +DATABASE_CONNECTION_STRING=mongodb://localhost:27017 +DATABASE_NAME=my-finance-pal +LOG_LEVEL=debug \ No newline at end of file diff --git a/package.json b/package.json index f0d4f94..bc6e3ec 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "moduleDirectories": [ "node_modules", "src" - ] + ], + "setupFiles": ["./src/preStart.ts"] } } diff --git a/src/config/environment.ts b/src/config/environment.ts index da716c4..1916061 100644 --- a/src/config/environment.ts +++ b/src/config/environment.ts @@ -1,13 +1,11 @@ -import { cleanEnv, port, str, testOnly, url } from "envalid"; +import { cleanEnv, port, str, url } from "envalid"; import * as process from "process"; const env = cleanEnv(process.env, { - PORT: port({ devDefault: testOnly(1234) }), - LOG_LEVEL: str({ default: "info", devDefault: testOnly("DEBUG") }), - DATABASE_CONNECTION_STRING: url({ - devDefault: testOnly("mongodb://mongo:27017"), - }), - DATABASE_NAME: str({ devDefault: testOnly("my-finance-pal") }), + PORT: port(), + LOG_LEVEL: str({ default: "info" }), + DATABASE_CONNECTION_STRING: url(), + DATABASE_NAME: str(), }); export default env; diff --git a/src/preStart.ts b/src/preStart.ts index edb3347..f87eb09 100644 --- a/src/preStart.ts +++ b/src/preStart.ts @@ -8,6 +8,7 @@ import dotenv from "dotenv"; import { parse } from "ts-command-line-args"; import path from "path"; +import * as process from "process"; // **** Types **** // @@ -21,7 +22,7 @@ interface Args { const args = parse({ env: { type: String, - defaultValue: "development", + defaultValue: process.env.NODE_ENV ?? "development", alias: "e", }, }); diff --git a/src/routes/budget/budgetRouter.integration.spec.ts b/src/routes/budget/budgetRouter.integration.spec.ts index 8beb02d..a1aa9a9 100644 --- a/src/routes/budget/budgetRouter.integration.spec.ts +++ b/src/routes/budget/budgetRouter.integration.spec.ts @@ -1,15 +1,13 @@ 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"; +import mongoDb from "../../config/mongoDb"; describe("budgetRouter", () => { beforeEach(async () => { try { - await mongoose.connect(env.DATABASE_CONNECTION_STRING, { - dbName: env.DATABASE_NAME, - }); + await mongoDb.connect(); } catch (error) { console.log(error); }