Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.17.x]
node-version: [20.15.0]
steps:
- uses: actions/checkout@v2
- name: Setup environment
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.17.x]
node-version: [20.15.0]
steps:
- uses: actions/checkout@v2
- name: Setup environment
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage-report-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.17.x]
node-version: [20.15.0]
steps:
- uses: actions/checkout@v2
- name: Setup environment
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ typings/
.env
.env.local
.env.development
.env.docker

# next.js build output
.next

dist
.env.development
.env.docker
report.json

1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
FROM node:14.17-alpine AS build1
FROM node:20-alpine AS build1
ARG ENVIRONMENT_NAME
ENV ENVIRONMENT_NAME $ENVIRONMENT_NAME
RUN mkdir -p /app-build
ADD . /app-build
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use COPY instead of ADD for files and folders.

According to hadolint, COPY should be used instead of ADD for files and folders.

- ADD . /app-build
+ COPY . /app-build

- ADD package.json /
- ADD . /
+ COPY package.json /
+ COPY . /

Also applies to: 16-17

Tools
Hadolint

[error] 5-5: Use COPY instead of ADD for files and folders

(DL3020)

WORKDIR /app-build
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn --frozen-lockfile
RUN yarn
RUN yarn build:dev
RUN yarn build:$ENVIRONMENT_NAME

FROM node:14.17-alpine
FROM node:20-alpine
ARG ENVIRONMENT_NAME
ENV ENVIRONMENT_NAME $ENVIRONMENT_NAME
RUN apk add yarn
RUN yarn add bull
ADD package.json /
ADD . /
COPY --from=build1 /app-build/dist ./dist
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ A basic starter for a web app with node, express and mongoose -->
- Execute the following command: `k6 run __tests__/__load__/script.js`
## Build and run docker container locally

- docker-compose down
- docker-compose build
- docker-compose up
- docker-compose --env-file=.env.docker down
- docker-compose --env-file=.env.docker build
- docker-compose --env-file=.env.docker up

# Shard setup

Expand Down
8 changes: 0 additions & 8 deletions __tests__/server/api/cronJob/aggregateJob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('aggregateCheck function tests', () => {
const date = moment(REDIS_IMPLEMENTATION_DATE).subtract(1, 'day');
const amt = 25000;
const count = 1500;
const mockError = new Error('Mock Error');

beforeEach(() => {
jest.spyOn(orderFns, 'getEarliestOrderCreatedDate').mockResolvedValue(
Expand Down Expand Up @@ -58,11 +57,4 @@ describe('aggregateCheck function tests', () => {
await aggregateCheck();
expect(redisSpy).toBeCalledTimes(7);
});

it('should thrown an error if there is error thrown from db', async () => {
jest.spyOn(redis, 'get').mockRejectedValueOnce(mockError);
expect(async () => {
await aggregateCheck();
}).rejects.toThrow(mockError);
});
});
20 changes: 1 addition & 19 deletions __tests__/server/middlewares/auth/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import message from 'utils/i18n/message';
import * as utils from 'utils/apiUtils';
import { checkRole } from 'middlewares/auth';
import { ownershipBasedAccessControl } from 'middlewares/auth/ownershipBasedAccessControl';

jest.mock('middlewares/auth/ownershipBasedAccessControl', () => ({
ownershipBasedAccessControl: jest.fn()
}));
Expand Down Expand Up @@ -77,23 +78,4 @@ describe('checkRole tests', () => {
await checkRole(req, res, next);
expect(next).toBeCalled();
});

it(`should return error from catch block`, async () => {
const mockError = new Error('test');
req.user['https://node-express-demo/roles'] = 'STORE_ADMIN';
req.user[`https://node-express-demo/email`] = 'asser@wednesday.com';
req.params = { _id: '62861b5be1897fc8b1d82360' };
req.baseUrl = '/stores';
req.route.path = '/:_id';
req.method = 'GET';
jest.spyOn(mocks, 'ownershipBasedAccessControl').mockImplementationOnce(
() => {
throw mockError;
}
);

expect(async () => {
await checkRole(req, res, next);
}).rejects.toThrowError('test');
});
});
31 changes: 31 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = function (api) {
api.cache(true); // Caches the computed configuration

const presets = [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: 3
}
],
'@babel/preset-flow'
];
const plugins = [
'@babel/plugin-proposal-throw-expressions',
'@babel/plugin-proposal-class-properties',
'@babel/transform-runtime',
'@babel/plugin-transform-async-generator-functions'
];

// Environment-specific configuration
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (env !== 'test') {
plugins.push(['@babel/plugin-transform-modules-commonjs']);
}

return {
presets,
plugins
};
};
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
ports:
- "9000:9000"
env_file:
- .env.local
- .env.docker
environment:
- REDIS_DOMAIN=redis
- MONGO_BASE_URI=mongo
Expand Down
31 changes: 20 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
"description": "A basic starter web app with node, express and mongoose",
"main": "index.js",
"scripts": {
"test": "jest --coverage",
"test": "jest --silent --forceExit --ci --coverage --testLocationInResults --json --outputFile=\"report.json\"",
"start": "node dist/main.js",
"start:development": "ENVIRONMENT_NAME=development node dist/main.js",
"build:docker": "export ENVIRONMENT_NAME=docker && webpack-cli --config webpack/production.config.js --stats-error-details",
"build:local": "export ENVIRONMENT_NAME=local && webpack-cli --config webpack/production.config.js --stats-error-details",
"build:env": "webpack-cli --config webpack/production.config.js --stats-error-details",
"build:dev": "webpack-cli --config webpack/dev.config.js --stats-error-details",
"start:local": "ENVIRONMENT_NAME=local && yarn build:dev && yarn start",
"start:sharded": "export MONGO_PORT=60000 && yarn start",
"postinstall": "link-module-alias",
"preinstall": "source /usr/local/opt/nvm/nvm.sh; nvm use; command -v link-module-alias && link-module-alias clean || true",
"preinstall": "command -v link-module-alias && link-module-alias clean || true",
"format": "prettier-standard './**/**/*.js'",
"lint": "npm run lint:js",
"lint:eslint": "eslint --ignore-path .eslintignore --ignore-pattern server/bin",
Expand All @@ -39,7 +41,7 @@
"author": "Wednesday Solutions",
"license": "MIT",
"engines": {
"node": "14.17.x"
"node": "20.15.x"
},
"bugs": {
"url": "https://github.com/wednesday-solutions/node-mongo-express/issues"
Expand Down Expand Up @@ -69,7 +71,7 @@
"mongoose-to-swagger": "^1.4.0",
"node-fetch": "2",
"nodemon": "^2.0.15",
"opossum": "^6.3.0",
"opossum": "^8.1.4",
"pluralize": "^8.0.0",
"response-time": "^2.3.2",
"slack-notify": "^2.0.2",
Expand All @@ -79,18 +81,25 @@
"webpack-hot-middleware": "^2.25.2"
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.18.2",
"@babel/node": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.18.10",
"@babel/preset-env": "^7.18.2",
"@babel/cli": "^7.24.7",
"@babel/core": "^7.24.7",
"@babel/eslint-parser": "^7.24.7",
"@babel/node": "^7.24.7",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-throw-expressions": "^7.24.7",
"@babel/plugin-transform-async-generator-functions": "^7.24.7",
"@babel/plugin-transform-modules-commonjs": "^7.24.7",
"@babel/plugin-transform-runtime": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-flow": "^7.24.7",
"@faker-js/faker": "^6.0.0-alpha.5",
"babel-loader": "^8.2.5",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"file-loader": "^6.2.0",
"jest": "^27.4.7",
"jest": "^29.7.0",
"jest-coverage-badges": "^1.1.2",
"link-module-alias": "^1.2.0",
"mockingoose": "^2.15.2",
Expand Down
4 changes: 2 additions & 2 deletions server/database/models/storeProducts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const { schema: Store } = require('./stores');
const { schema: Product } = require('./products');
const schema = new mongoose.Schema({
productId: {
type: mongoose.Types.ObjectId,
type: mongoose.ObjectId,
required: true
},
storeId: {
type: mongoose.Types.ObjectId,
type: mongoose.ObjectId,
required: true
},
store: Store,
Expand Down
4 changes: 2 additions & 2 deletions server/database/models/supplierProducts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const { schema: Supplier } = require('./suppliers');
const { schema: Product } = require('./products');
const schema = new mongoose.Schema({
productId: {
type: mongoose.Types.ObjectId,
type: mongoose.ObjectId,
required: true
},
supplierId: {
type: mongoose.Types.ObjectId,
type: mongoose.ObjectId,
required: true
},
supplier: Supplier,
Expand Down
Loading