Skip to content

Commit

Permalink
test: Implemented mock model to avoid hitting the DB
Browse files Browse the repository at this point in the history
mock model make use of map to store tempory data in memory, and some mock functions of the model
  • Loading branch information
AllStackDev1 committed Aug 5, 2024
1 parent 3aab045 commit 9d2b137
Show file tree
Hide file tree
Showing 21 changed files with 564 additions and 157 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.env
.env.development
.env.test
build
coverage
react-email-starter
Expand Down
27 changes: 18 additions & 9 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@ declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'development' | 'production' | 'test';
TEST_MODEL: 'mock' | 'real';

PORT?: string;
HOSTNAME: string;
HOSTNAME?: string;

DB_HOST: string;
DB_PORT: string;
DB_NAME: string;
DB_USERNAME: string;
DB_PASSWORD: string;
DB_HOST?: string;
DB_PORT?: string;
DB_NAME?: string;
DB_USERNAME?: string;
DB_PASSWORD?: string;

REDIS_URL: string;
REDIS_URL?: string;
REDIS_HOST?: string;
REDIS_PORT?: string;

SESSION_SECRET: string;
SESSION_SECRET?: string;

HASHING_SALT: string;
JWT_SECRET_KEY?: string;
JWT_EXPIRES_IN?: string;

COOKIES_SECRET_KEY?: string;
COOKIES_MAX_AGE?: string;

HASHING_SALT?: string;

// Add other environment variables here
}
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const config: Config = {
coverageProvider: 'v8',
testEnvironment: 'node',
roots: ['<rootDir>'],
testTimeout: 15000,
setupFilesAfterEnv: ['reflect-metadata'],
modulePaths: [compilerOptions.baseUrl],
coverageDirectory: './coverage',
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
"db:create": "pnpm run build && NODE_ENV=development npx sequelize-cli db:create",
"db:migrate:up": "pnpm run build && NODE_ENV=development npx sequelize-cli db:migrate",
"db:migrate:undo": "pnpm run build && NODE_ENV=development npx sequelize-cli db:migrate:undo",
"test": "env NODE_ENV=test jest",
"test:watch": "env NODE_ENV=test jest --runInBand --watch ./src/tests/server.test.ts",
"test": "NODE_ENV=test TEST_MODEL=mock jest",
"test:watch": "NODE_ENV=test TEST_MODEL=real jest --runInBand --watch .",
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts"
},
"author": "Chinedu",
"license": "ISC",
"dependencies": {
"@type-cacheable/core": "^14.0.1",
"@type-cacheable/ioredis-adapter": "^15.0.1",
"bcrypt": "^5.1.1",
"connect-redis": "^7.1.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
Expand All @@ -42,15 +45,17 @@
"@eslint/js": "^10.0.0",
"@tsconfig/node16": "^16.1.3",
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.7",
"@types/express": "^4.17.21",
"@types/express-session": "^1.18.0",
"@types/jest": "^29.5.12",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^22.0.0",
"@types/safe-regex": "^1.1.6",
"@types/supertest": "^6.0.2",
"@types/validator": "^13.12.0",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
Expand All @@ -66,6 +71,6 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.5.3",
"typescript-eslint": "^7.16.1"
"typescript-eslint": "^8.0.0"
}
}
Loading

0 comments on commit 9d2b137

Please sign in to comment.