From 2b31c40f0486626508ca6696de36f52b69ac677b Mon Sep 17 00:00:00 2001 From: rrozek Date: Thu, 18 Apr 2024 10:17:04 +0200 Subject: [PATCH] rearrange test suite --- README.md | 5 ++++- src/{components/404 => tests}/404.test.ts | 0 src/{core/middlewares => tests}/apiKey.middleware.test.ts | 2 +- src/{components/dashboard => tests}/dashboard.test.ts | 0 src/{components/db-api => tests}/databaseInfo.test.ts | 4 ++-- .../middlewares => tests}/errorHandling.middleware.test.ts | 2 +- src/{components/healthcheck => tests}/healthCheck.test.ts | 0 src/{core/middlewares => tests}/validate.middleware.test.ts | 2 +- 8 files changed, 9 insertions(+), 6 deletions(-) rename src/{components/404 => tests}/404.test.ts (100%) rename src/{core/middlewares => tests}/apiKey.middleware.test.ts (95%) rename src/{components/dashboard => tests}/dashboard.test.ts (100%) rename src/{components/db-api => tests}/databaseInfo.test.ts (97%) rename src/{core/middlewares => tests}/errorHandling.middleware.test.ts (91%) rename src/{components/healthcheck => tests}/healthCheck.test.ts (100%) rename src/{core/middlewares => tests}/validate.middleware.test.ts (97%) diff --git a/README.md b/README.md index 7c462e2..fe57c8c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,10 @@ To get started with the dashboard builder server, follow these steps: 1. **Clone the Repository**: `git clone https://github.com/tokenguardio/dashboard-creator-server.git` 2. **Install Dependencies**: `npm install` or `yarn install` -3. **Run the Development Server**: `npm start` or `yarn start` +3. **Run the Development Server**: `npm start` or `yarn start` + +### Testing +1. **Run tests**: `npm test` ### Features diff --git a/src/components/404/404.test.ts b/src/tests/404.test.ts similarity index 100% rename from src/components/404/404.test.ts rename to src/tests/404.test.ts diff --git a/src/core/middlewares/apiKey.middleware.test.ts b/src/tests/apiKey.middleware.test.ts similarity index 95% rename from src/core/middlewares/apiKey.middleware.test.ts rename to src/tests/apiKey.middleware.test.ts index d2f9622..aec0a59 100644 --- a/src/core/middlewares/apiKey.middleware.test.ts +++ b/src/tests/apiKey.middleware.test.ts @@ -2,7 +2,7 @@ import httpMocks from 'node-mocks-http'; import { Response, Request, NextFunction } from 'express'; import config from '@config/config'; -import apiKey from './apiKey.middleware'; +import apiKey from '../core/middlewares/apiKey.middleware'; describe('ApiKey middleware', () => { test('should call next middleware in the stack if provided correct api key in the headers', () => { diff --git a/src/components/dashboard/dashboard.test.ts b/src/tests/dashboard.test.ts similarity index 100% rename from src/components/dashboard/dashboard.test.ts rename to src/tests/dashboard.test.ts diff --git a/src/components/db-api/databaseInfo.test.ts b/src/tests/databaseInfo.test.ts similarity index 97% rename from src/components/db-api/databaseInfo.test.ts rename to src/tests/databaseInfo.test.ts index 54ac407..0872c6e 100644 --- a/src/components/db-api/databaseInfo.test.ts +++ b/src/tests/databaseInfo.test.ts @@ -4,8 +4,8 @@ import httpStatus from 'http-status'; import { jest } from '@jest/globals'; import app from '@app'; -import mockData from './mocks/dashboardData.json'; -import queryResponses from './mocks/queryResponses.json'; +import mockData from '../components/db-api/mocks/dashboardData.json'; +import queryResponses from '../components/db-api/mocks/queryResponses.json'; jest.mock('axios'); const mockedAxios = axios as jest.Mocked; diff --git a/src/core/middlewares/errorHandling.middleware.test.ts b/src/tests/errorHandling.middleware.test.ts similarity index 91% rename from src/core/middlewares/errorHandling.middleware.test.ts rename to src/tests/errorHandling.middleware.test.ts index 4e112ad..3453737 100644 --- a/src/core/middlewares/errorHandling.middleware.test.ts +++ b/src/tests/errorHandling.middleware.test.ts @@ -3,7 +3,7 @@ import httpStatus from 'http-status'; import { Response } from 'express'; import errorHandler from '@core/utils/errorHandler'; -import errorHandling from './errorHandling.middleware'; +import errorHandling from '../core/middlewares/errorHandling.middleware'; describe('Error middleware', () => { test('should delegate error to the centralized error handler and send 500 response', () => { diff --git a/src/components/healthcheck/healthCheck.test.ts b/src/tests/healthCheck.test.ts similarity index 100% rename from src/components/healthcheck/healthCheck.test.ts rename to src/tests/healthCheck.test.ts diff --git a/src/core/middlewares/validate.middleware.test.ts b/src/tests/validate.middleware.test.ts similarity index 97% rename from src/core/middlewares/validate.middleware.test.ts rename to src/tests/validate.middleware.test.ts index 8160f5d..d0af13d 100644 --- a/src/core/middlewares/validate.middleware.test.ts +++ b/src/tests/validate.middleware.test.ts @@ -5,7 +5,7 @@ import { Response, Request } from 'express'; import Joi from 'joi'; import { ValidationSchema } from '@core/interfaces/validationSchema'; import AppError from '@core/utils/appError'; -import validate from './validate.middleware'; +import validate from '../core/middlewares/validate.middleware'; // example validation schema for node request with provided all three options to valid const validationSchemaWithAllOptions: ValidationSchema = {