Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariovyord committed Jan 8, 2024
1 parent 04dcfd2 commit 48925b1
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 50 deletions.
11 changes: 11 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
NODE_ENV=development
PORT=5000
ALLOW_ORIGIN="*"
ALLOW_METHODS="GET,PUT,POST,PATCH,DELETE,HEAD,OPTIONS"
ALLOW_HEADERS="Content-Type,Cache-Control,Expires"
JWT_SECRET=SUPERSECRET
DB_NAME="test_express_app"
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
7 changes: 7 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "3"
services:
app:
command:
- "npm"
- "run"
- "test"
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
preset: "ts-jest",
testEnvironment: "node",
setupFiles: ["./tests/setup-tests.ts"],
};
198 changes: 198 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"reflect-metadata": "^0.2.1",
"swagger-ui-express": "^5.0.0",
"typeorm": "^0.3.19",
"typeorm-extension": "^3.2.0",
"winston": "^3.11.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import router from "./router";
import path from "path";
import handleErrors from "./middleware/error-middleware";
import loggerMiddleware from "./middleware/logger-middleware";
import getConfig from "./config/get-config";
import { getConfig } from "./config/get-config";
import * as swaggerDoc from "./swagger.json";
import swagger from "swagger-ui-express";
import helmet from "helmet";
Expand Down
4 changes: 2 additions & 2 deletions src/config/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "reflect-metadata";
import { Article } from "../features/article/article-entity";
import { Comment } from "../features/comment/comment-entity";
import { User } from "../features/user/user-entity";
import getConfig from "./get-config";
import { getConfig } from "./get-config";

const config = getConfig();

Expand All @@ -13,7 +13,7 @@ export const AppDataSource = new DataSource({
port: parseInt(config.DB_PORT),
username: config.DB_USERNAME,
password: config.DB_PASSWORD,
database: "express_app",
database: config.DB_NAME,
synchronize: config.NODE_ENV === "production" ? false : true,
logging: true,
entities: [Article, Comment, User],
Expand Down
10 changes: 6 additions & 4 deletions src/config/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import dotenv from "dotenv";
/**
* Load enviroment variables
*/
dotenv.config();
dotenv.config({ path: `.env.local`, override: true });
if (!process.env.NODE_ENV) {
dotenv.config();
dotenv.config({ path: `.env.local`, override: true });
}

export default function getConfig() {
console.log(process.env);
export function getConfig() {
return {
NODE_ENV: process.env.NODE_ENV,
PORT: process.env.PORT,
ALLOW_ORIGIN: process.env.ALLOW_ORIGIN,
ALLOW_METHODS: process.env.ALLOW_METHODS,
ALLOW_HEADERS: process.env.ALLOW_HEADERS,
JWT_SECRET: process.env.JWT_SECRET,
DB_NAME: process.env.DB_NAME,
DB_HOST: process.env.DB_HOST,
DB_PORT: process.env.DB_PORT,
DB_PASSWORD: process.env.DB_PASSWORD,
Expand Down
2 changes: 1 addition & 1 deletion src/features/user/user-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jwt from "jsonwebtoken";
import getConfig from "../../config/get-config";
import { getConfig } from "../../config/get-config";
import { IUserLocal, ISignUpUserData, UserDto, IUpdateUserData } from "./user-types";
import { BadRequestError, InternalServerError, NotFoundError, UnauthorizedError } from "../../utils/app-error";
import { User } from "./user-entity";
Expand Down
Loading

0 comments on commit 48925b1

Please sign in to comment.