mirror of
https://github.com/netlight/my-finance-pal-backend.git
synced 2024-11-12 17:44:15 +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 ##
|
## Server ##
|
||||||
PORT=8080
|
PORT=8080
|
||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
|
DATABASE_CONNECTION_STRING=mongodb://mongo:27017
|
||||||
DATABASE_NAME=my-finance-pal
|
DATABASE_NAME=my-finance-pal
|
||||||
|
|
4
env/test.env
vendored
4
env/test.env
vendored
|
@ -1,3 +1,5 @@
|
||||||
## Server ##
|
## Server ##
|
||||||
PORT=3000
|
PORT=3000
|
||||||
NODE_ENV=test
|
DATABASE_CONNECTION_STRING=mongodb://localhost:27017
|
||||||
|
DATABASE_NAME=my-finance-pal
|
||||||
|
LOG_LEVEL=debug
|
|
@ -79,6 +79,7 @@
|
||||||
"moduleDirectories": [
|
"moduleDirectories": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"src"
|
"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";
|
import * as process from "process";
|
||||||
|
|
||||||
const env = cleanEnv(process.env, {
|
const env = cleanEnv(process.env, {
|
||||||
PORT: port({ devDefault: testOnly(1234) }),
|
PORT: port(),
|
||||||
LOG_LEVEL: str({ default: "info", devDefault: testOnly("DEBUG") }),
|
LOG_LEVEL: str({ default: "info" }),
|
||||||
DATABASE_CONNECTION_STRING: url({
|
DATABASE_CONNECTION_STRING: url(),
|
||||||
devDefault: testOnly("mongodb://mongo:27017"),
|
DATABASE_NAME: str(),
|
||||||
}),
|
|
||||||
DATABASE_NAME: str({ devDefault: testOnly("my-finance-pal") }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default env;
|
export default env;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { parse } from "ts-command-line-args";
|
import { parse } from "ts-command-line-args";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import * as process from "process";
|
||||||
|
|
||||||
// **** Types **** //
|
// **** Types **** //
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ interface Args {
|
||||||
const args = parse<Args>({
|
const args = parse<Args>({
|
||||||
env: {
|
env: {
|
||||||
type: String,
|
type: String,
|
||||||
defaultValue: "development",
|
defaultValue: process.env.NODE_ENV ?? "development",
|
||||||
alias: "e",
|
alias: "e",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
import { type BudgetDto, type NewBudgetDto } from "./dto/budget";
|
import { type BudgetDto, type NewBudgetDto } from "./dto/budget";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import env from "../../config/environment";
|
|
||||||
import request from "supertest";
|
import request from "supertest";
|
||||||
import app from "../../app";
|
import app from "../../app";
|
||||||
|
import mongoDb from "../../config/mongoDb";
|
||||||
|
|
||||||
describe("budgetRouter", () => {
|
describe("budgetRouter", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
try {
|
try {
|
||||||
await mongoose.connect(env.DATABASE_CONNECTION_STRING, {
|
await mongoDb.connect();
|
||||||
dbName: env.DATABASE_NAME,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue