Skip to content

Commit

Permalink
feat: improve code structure and test cases with coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-simform committed Jun 5, 2024
1 parent ecbe142 commit 5024580
Show file tree
Hide file tree
Showing 48 changed files with 1,822 additions and 2,015 deletions.
5 changes: 3 additions & 2 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
NODE_ENV="development"

# APP
APP_NAME="nestjs-starter"
APP_DEBUG=true
NODE_ENV="development"
HTTP_HOST="0.0.0.0"
HTTP_PORT=3001
HTTP_VERSIONING_ENABLE=true
Expand All @@ -14,7 +15,7 @@ AUTH_ACCESS_TOKEN_EXP="1d"
AUTH_REFRESH_TOKEN_EXP="7d"

# DATABASE CONFIG
DATABASE_URL="postgresql://admin:master123@postgres:5432/postgres?schema=public"
DATABASE_URL="postgresql://postgres:master123@postgres:5432/postgres?schema=public"

# AWS
AWS_ACCESS_KEY=""
Expand Down
7 changes: 4 additions & 3 deletions .env.local
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
NODE_ENV="development"

# APP
APP_NAME="nestjs-starter"
APP_DEBUG=false
NODE_ENV="development"
APP_DEBUG=true
HTTP_HOST="0.0.0.0"
HTTP_PORT=3001
HTTP_VERSIONING_ENABLE=true
Expand All @@ -14,7 +15,7 @@ AUTH_ACCESS_TOKEN_EXP="1d"
AUTH_REFRESH_TOKEN_EXP="7d"

# DATABASE CONFIG
DATABASE_URL="postgresql://admin:master123@localhost:5432/postgres?schema=public"
DATABASE_URL="postgresql://postgres:master123@localhost:5432/postgres?schema=public"

# AWS
AWS_ACCESS_KEY=""
Expand Down
11 changes: 0 additions & 11 deletions .github/dependabot.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:

- name: Run Jest tests
run: yarn test

- name: Update Coverage Badge
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
uses: we-cli/coverage-badge-action@main
34 changes: 26 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@ dist/
tmp/
temp/

# Files
junit.xml
.env.development
.env.stage
.env.prod
.env.test
.env
yarn-error.log
# jest
coverage

# environment
.env*
!.env.example
config.yaml
config.yml
yarn-error.log

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# yarn
.yarn/*
.pnp.*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.json
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
"source.fixAll.eslint": "always"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand All @@ -32,5 +32,8 @@
},
"[prisma]": {
"editor.defaultFormatter": "Prisma.prisma"
},
"[github-actions-workflow]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
FROM node:18 AS builder
FROM node:20-alpine AS builder

RUN apk add --no-cache --virtual .build-deps alpine-sdk python3

WORKDIR /app

COPY package.json ./
COPY yarn.lock ./
COPY prisma ./prisma/
COPY package.json yarn.lock ./

RUN yarn install --frozen-lockfile

COPY prisma ./prisma
RUN yarn generate

COPY . .

RUN yarn build

FROM node:18
FROM node:18-alpine

WORKDIR /app

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
Expand All @@ -23,4 +26,4 @@ COPY --from=builder /app/dist ./dist

EXPOSE 3001

CMD [ "yarn", "start" ]
CMD ["yarn", "start"]
4 changes: 3 additions & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node:18
FROM node:20-alpine

RUN apk add --no-cache --virtual .build-deps alpine-sdk python3

WORKDIR /app

Expand Down
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# NestJS Starter Boilerplate
[![CodeQL](https://github.com/hmake98/nestjs-starter/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/hmake98/nestjs-starter/actions/workflows/github-code-scanning/codeql)
[![Run Tests](https://github.com/hmake98/nestjs-starter/actions/workflows/main.yml/badge.svg)](https://github.com/hmake98/nestjs-starter/actions/workflows/main.yml)
[![Coverage](https://hmake98.github.io/nestjs-starter/badges/coverage.svg)](https://github.com/hmake98/nestjs-starter/actions)


## Installation

Expand Down
40 changes: 19 additions & 21 deletions buildspec.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# Don't change this version, this version is buildspec.yml file's version
version: 0.2

phases:
install:
runtime-versions:
nodejs: 18
pre_build:
commands:
- yarn install --frozen-lockfile
- echo Logging in to Amazon ECR...
- aws --version
- $(aws ecr get-login --region $AWS_REGION --no-include-email)
- REPOSITORY_URI=<URI>
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=build-$(echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}')
build:
commands:
- yarn build

- echo Build started on `date`
- docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"auth","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
- cat imagedefinitions.json
artifacts:
files:
- '**/*'
discard-paths: no

reports:
jest_reports:
files:
- 'junit.xml'
file-format: JUNITXML
base-directory: '.'

cache:
paths:
- node_modules
files: imagedefinitions.json
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
ports:
- '5432:5432'
environment:
- POSTGRES_USER=admin
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=master123
- POSTGRES_DB=postgres
volumes:
Expand Down
59 changes: 17 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"author": "hmake98",
"license": "MIT",
"main": "main.js",
"resolutions": {
"jackspeak": "2.1.1"
},
"scripts": {
"build": "nest build",
"dev": "dotenv -e .env.local -- nest start --watch",
Expand All @@ -12,17 +15,15 @@
"start": "node dist/main",
"migrate": "dotenv -e .env.local -- prisma migrate dev",
"migrate:prod": "prisma migrate deploy",
"studio": "prisma studio",
"update:packages": "npx npm-check-updates -u",
"lint": "eslint '{src,test}/**/*.ts'",
"lint:fix": "eslint --fix '{src,test}/**/*.ts'",
"format": "prettier --write 'src/**/*.ts'",
"test": "dotenv -e .env.local -- jest --runInBand --forceExit",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:e2e": "jest --config ./test/jest-e2e.json --forceExit"
"test": "jest --config test/jest.json --runInBand --passWithNoTests --forceExit"
},
"engines": {
"node": ">=18.0.0"
"node": ">=20.0.0"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.583.0",
Expand All @@ -43,8 +44,7 @@
"@nestjs/terminus": "^10.2.3",
"@nestjs/throttler": "^5.1.2",
"@prisma/client": "^5.14.0",
"aws-sdk-client-mock": "^4.0.0",
"bcrypt": "5.1.1",
"argon2": "^0.40.3",
"bull": "^4.12.9",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
Expand All @@ -54,7 +54,6 @@
"handlebars": "^4.7.8",
"helmet": "^7.1.0",
"ioredis": "^5.4.1",
"jest-junit": "^16.0.0",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"moment": "^2.30.1",
Expand All @@ -73,7 +72,6 @@
"@commitlint/config-conventional": "^19.2.2",
"@nestjs/cli": "^10.3.2",
"@nestjs/testing": "^10.3.8",
"@types/bcrypt": "^10.0.28-alpha",
"@types/bull": "^3.15.9",
"@types/copyfiles": "^2.4.4",
"@types/eslint": "~8.56.10",
Expand All @@ -86,7 +84,7 @@
"@types/lint-staged": "^13.3.0",
"@types/lodash": "^4.17.4",
"@types/morgan": "^1.9.9",
"@types/node": "^20.12.12",
"@types/node": "^20.12.13",
"@types/nodemailer": "^6.4.15",
"@types/passport": "^1.0.16",
"@types/passport-jwt": "^4.0.1",
Expand All @@ -97,8 +95,8 @@
"@types/rimraf": "^3.0.2",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "^4.1.6",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"cross-env": "^7.0.3",
"dotenv-cli": "^7.4.2",
"eslint": "^8.3.0",
Expand All @@ -110,45 +108,22 @@
"globals": "^15.3.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.4",
"lint-staged": "^15.2.5",
"prettier": "^3.2.5",
"prisma": "^5.14.0",
"stop-only": "^3.3.1",
"supertest": "^7.0.0",
"ts-jest": "^29.1.3",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "5.4.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "./",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"reporters": [
"default",
[
"jest-junit",
{
"outputDirectory": ".",
"outputName": "junit.xml"
}
]
]
},
"lint-staged": {
"src/.{js,ts}": "eslint --fix",
"*.{ts,js,json,md}": "prettier --write"
"{src,test}/**/*.{ts,js,json}": [
"prettier --write '{src,test}/**/*.ts'",
"eslint",
"stop-only --file"
]
}
}
24 changes: 0 additions & 24 deletions prisma/migrations/20240117115739_init/migration.sql

This file was deleted.

Loading

0 comments on commit 5024580

Please sign in to comment.