mirror of
https://github.com/netlight/my-finance-pal-backend.git
synced 2024-11-09 16:41:56 +01:00
Fix MongoDB config in integration tests
This commit is contained in:
parent
0140e37fa6
commit
0ea70f0be7
6 changed files with 15 additions and 14 deletions
1
env/production.env
vendored
1
env/production.env
vendored
|
@ -1,4 +1,5 @@
|
|||
## Server ##
|
||||
PORT=8080
|
||||
NODE_ENV=production
|
||||
DATABASE_CONNECTION_STRING=mongodb://mongo:27017
|
||||
DATABASE_NAME=my-finance-pal
|
||||
|
|
4
env/test.env
vendored
4
env/test.env
vendored
|
@ -1,3 +1,5 @@
|
|||
## Server ##
|
||||
PORT=3000
|
||||
NODE_ENV=test
|
||||
DATABASE_CONNECTION_STRING=mongodb://localhost:27017
|
||||
DATABASE_NAME=my-finance-pal
|
||||
LOG_LEVEL=debug
|
|
@ -79,6 +79,7 @@
|
|||
"moduleDirectories": [
|
||||
"node_modules",
|
||||
"src"
|
||||
]
|
||||
],
|
||||
"setupFiles": ["./src/preStart.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;
|
||||
|
|
|
@ -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<Args>({
|
||||
env: {
|
||||
type: String,
|
||||
defaultValue: "development",
|
||||
defaultValue: process.env.NODE_ENV ?? "development",
|
||||
alias: "e",
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue