Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,28 @@ module.exports = {
// },
setupFiles: ['./tests/setupTest.js'],
moduleNameMapper: {
// This will be removed in the future versions
'^Config(.*)$': '<rootDir>/src/config$1',
// This will be removed in the future versions
'^Constants/errorCodes(.*)$': '<rootDir>/src/constants/errorCodes$1',
// This will be removed in the future versions
'^Core(.*)$': '<rootDir>/src/core$1',
// This will be removed in the future versions
'^Exceptions/ErrorException(.*)$':
'<rootDir>/src/exceptions/ErrorException$1',
// This will be removed in the future versions
'^Models(.*)$': '<rootDir>/src/models$1',
'^Utils/logger$': '<rootDir>/tests/__mocks__/utils/logger.js',
'^Utils/queue$': '<rootDir>/tests/__mocks__/utils/queue.js',
'^Utils/database$': '<rootDir>/node_modules/lesgo/src/utils/database.js',
'^Utils/sentry$': '<rootDir>/node_modules/lesgo/src/utils/sentry.js',
'^config(.*)$': '<rootDir>/src/config$1',
'^constants/errorCodes(.*)$': '<rootDir>/src/constants/errorCodes$1',
'^core(.*)$': '<rootDir>/src/core$1',
'^exceptions/ErrorException(.*)$':
'<rootDir>/src/exceptions/ErrorException$1',
'^models(.*)$': '<rootDir>/src/models$1',
'^lesgo/utils/logger$': '<rootDir>/tests/__mocks__/utils/logger.js',
'^lesgo/utils/queue$': '<rootDir>/tests/__mocks__/utils/queue.js',
'^lesgo/utils/sentry$': '<rootDir>/node_modules/lesgo/src/utils/sentry.js',
'^lesgo/utils/database$':
'<rootDir>/node_modules/lesgo/src/utils/database.js',
'^@sentry/node$': '<rootDir>/node_modules/@sentry/node/dist/index.js',
},
transformIgnorePatterns: ['/node_modules/(?!lesgo).+\\.js$'],
Expand Down
28 changes: 28 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,34 @@
],
"Utils/*": [
"src/utils/*",
"../lesgo-framework/src/utils/*",
"node_modules/lesgo/src/utils/*"
],
"config/*": ["src/config/*"],
"constants/*": ["src/constants/*"],
"core/*": ["src/core/*"],
"exceptions/*": ["src/exceptions/*"],
"handlers/*": ["src/handlers/*"],
"middlewares/*": ["src/middlewares/*"],
"models/*": ["src/models/*"],
"services/*": ["src/services/*"],
"utils/*": ["src/utils/*"],
"lesgo/exceptions/*": [
"../lesgo-framework/src/exceptions/*",
"node_modules/lesgo/src/exceptions/*",
"node_modules/@types/lesgo/exceptions/*"
],
"lesgo/middlewares/*": [
"../lesgo-framework/src/middlewares/*",
"node_modules/lesgo/src/middlewares/*",
"node_modules/@types/lesgo/middlewares/*"
],
"lesgo/services/*": [
"../lesgo-framework/src/services/*",
"node_modules/lesgo/src/services/*",
"node_modules/@types/lesgo/services/*"
],
"lesgo/utils/*": [
"../lesgo-framework/src/utils/*",
"node_modules/lesgo/src/utils/*",
"node_modules/@types/lesgo/utils/*"
Expand Down
6 changes: 3 additions & 3 deletions src/core/ping.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logger from 'Utils/logger';
import ErrorException from 'Exceptions/ErrorException';
import { ERROR_SAMPLE, ERROR_UNKNOWN_PARAMETER } from 'Constants/errorCodes';
import logger from 'lesgo/utils/logger';
import ErrorException from 'exceptions/ErrorException';
import { ERROR_SAMPLE, ERROR_UNKNOWN_PARAMETER } from 'constants/errorCodes';

const ping = input => {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/ErrorException.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ERROR_EXCEPTION } from 'Constants/errorCodes';
import { ERROR_EXCEPTION } from 'constants/errorCodes';

export default class ErrorException extends Error {
constructor(
Expand Down
11 changes: 6 additions & 5 deletions src/handlers/ping.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import { connectSentry } from 'Utils/sentry';
import ping from 'Core/ping';
import app from 'Config/app';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import ping from 'core/ping';
import app from 'config/app';
import exampleMiddleware from 'middlewares/exampleMiddleware';

connectSentry();

Expand All @@ -13,4 +14,4 @@ const originalHandler = event => {
// eslint-disable-next-line import/prefer-default-export
export const handler = middy(originalHandler);

handler.use(httpMiddleware({ debugMode: app.debug }));
handler.use(httpMiddleware({ debugMode: app.debug })).use(exampleMiddleware());
10 changes: 5 additions & 5 deletions src/handlers/samples/cache.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-console */
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import { connectSentry } from 'Utils/sentry';
import app from 'Config/app';
import cache from 'Utils/cache';
import ErrorException from 'Exceptions/ErrorException';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import cache from 'lesgo/utils/cache';
import ErrorException from 'exceptions/ErrorException';
import app from 'config/app';

connectSentry();

Expand Down
8 changes: 4 additions & 4 deletions src/handlers/samples/database.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import { connectSentry } from 'Utils/sentry';
import app from 'Config/app';
import db from 'Utils/database';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import db from 'lesgo/utils/database';
import app from 'config/app';

connectSentry();

Expand Down
8 changes: 4 additions & 4 deletions src/handlers/samples/db.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import app from 'Config/app';
import { connectSentry } from 'Utils/sentry';
import { db, dbRead, connectDb } from 'Utils/database';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import { db, dbRead, connectDb } from 'lesgo/utils/database';
import app from 'config/app';

connectDb();
connectSentry();
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/samples/elasticsearch.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import { connectSentry } from 'Utils/sentry';
import app from 'Config/app';
import es from 'Utils/elasticsearch';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import es from 'lesgo/utils/elasticsearch';
import app from 'config/app';

connectSentry();

Expand Down
12 changes: 6 additions & 6 deletions src/handlers/samples/errorHandling.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-console */
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import { connectSentry } from 'Utils/sentry';
import app from 'Config/app';
import logger from 'Utils/logger';
import ErrorException from 'Exceptions/ErrorException';
import { ERROR_SAMPLE, ERROR_UNKNOWN_PARAMETER } from 'Constants/errorCodes';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import logger from 'lesgo/utils/logger';
import ErrorException from 'exceptions/ErrorException';
import { ERROR_SAMPLE, ERROR_UNKNOWN_PARAMETER } from 'constants/errorCodes';
import app from 'config/app';

connectSentry();

Expand Down
10 changes: 5 additions & 5 deletions src/handlers/samples/jwt.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import verifyJwtMiddleware from 'Middlewares/verifyJwtMiddleware';
import { connectSentry } from 'Utils/sentry';
import ping from 'Core/ping';
import app from 'Config/app';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import verifyJwtMiddleware from 'lesgo/middlewares/verifyJwtMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import ping from 'core/ping';
import app from 'config/app';

connectSentry();

Expand Down
8 changes: 4 additions & 4 deletions src/handlers/samples/objectStore.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import { connectSentry } from 'Utils/sentry';
import app from 'Config/app';
import ping from 'Core/ping';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import app from 'config/app';
import ping from 'core/ping';

connectSentry();

Expand Down
8 changes: 4 additions & 4 deletions src/handlers/samples/queue.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import middy from '@middy/core';
import httpMiddleware from 'Middlewares/httpMiddleware';
import { connectSentry } from 'Utils/sentry';
import app from 'Config/app';
import { dispatch } from 'Utils/queue';
import httpMiddleware from 'lesgo/middlewares/httpMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import { dispatch } from 'lesgo/utils/queue';
import app from 'config/app';

connectSentry();

Expand Down
8 changes: 4 additions & 4 deletions src/handlers/samples/queueProcessor.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import middy from '@middy/core';
import normalizeSQSMessageMiddleware from 'Middlewares/normalizeSQSMessageMiddleware';
import { connectSentry } from 'Utils/sentry';
import ErrorException from 'Exceptions/ErrorException';
import normalizeSQSMessageMiddleware from 'lesgo/middlewares/normalizeSQSMessageMiddleware';
import { connectSentry } from 'lesgo/utils/sentry';
import ErrorException from 'exceptions/ErrorException';
import {
PING_QUEUE_PROCESSOR_SAMPLE_ERROR,
ERROR_EMPTY_PARAMETER,
} from 'Constants/errorCodes';
} from 'constants/errorCodes';

connectSentry();

Expand Down
6 changes: 3 additions & 3 deletions src/handlers/samples/scheduledEvent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logger from 'Utils/logger';
import { connectSentry } from 'Utils/sentry';
import ping from 'Core/ping';
import logger from 'lesgo/utils/logger';
import { connectSentry } from 'lesgo/utils/sentry';
import ping from 'core/ping';

connectSentry();

Expand Down
2 changes: 1 addition & 1 deletion src/models/Model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import db from 'Utils/database';
import db from 'lesgo/utils/database';
import { Model as BaseModel } from 'objection/lib/model/Model';

BaseModel.knex(db().query);
Expand Down
4 changes: 2 additions & 2 deletions tests/core/ping.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ping from 'Core/ping';
import { ERROR_SAMPLE, ERROR_UNKNOWN_PARAMETER } from 'Constants/errorCodes';
import ping from 'core/ping';
import { ERROR_SAMPLE, ERROR_UNKNOWN_PARAMETER } from 'constants/errorCodes';

describe('test ping core', () => {
it('ping request should return Pong', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/exceptions/ErrorException.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ErrorException from 'Exceptions/ErrorException';
import { ERROR_EXCEPTION, ERROR_SAMPLE } from 'Constants/errorCodes';
import ErrorException from 'exceptions/ErrorException';
import { ERROR_EXCEPTION, ERROR_SAMPLE } from 'constants/errorCodes';

describe('test ErrorException', () => {
it('test ErrorException with default parameters', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/database.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import User from 'Models/User';
import User from 'models/User';

describe('test model', () => {
it('should return the table name', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/sentry.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { connectSentry } from 'Utils/sentry';
import { connectSentry } from 'lesgo/utils/sentry';

describe('test sentry utils', () => {
it('should connect to sentry', () => {
Expand Down
Loading