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
55 changes: 24 additions & 31 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,49 @@
# This is a basic workflow to help you get started with Actions

name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]
on: [push]

jobs:
build:
# https://github.com/actions/runner-images#available-images
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup Node.js environment
uses: actions/setup-node@v1.4.4
uses: actions/setup-node@v3
with:
node-version: '14.16.1'

- name: Install npm dependencies
run: npm ci

- name: Prisma generate
run: npm run prisma:generate

- name: Unit tests
run: npm run test:cov

- name: Codacy Coverage Reporter
uses: codacy/codacy-coverage-reporter-action@0.2.0
with:
project-token: ${{ secrets.CODACY_TOKEN }}

- name: Setup PostgreSQL
uses: Harmon758/postgresql-action@v1.0.0
with:
postgresql db: vrt_db_dev
postgresql user: postgres
postgresql password: postgres
- name: Build and run containers
run: docker-compose up --build -d

- name: Wait untill DB started (workaround of https://github.com/Harmon758/postgresql-action/issues/7)
uses: jakejarvis/wait-action@v0.1.0
# FIXME: This action is unmaintained.
- name: Wait untill service started (replace with health status check)
uses: jakejarvis/wait-action@v0.1.1
with:
time: '5s'
time: '10s'

- name: Apply Manual DB migrations
run: npx ts-node ./prisma/manual_migrations.ts

- name: Apply DB migrations
run: npx prisma migrate up -c --experimental

- name: Seed DB data
run: npx ts-node ./prisma/seed.ts
- name: Run acceptance tests
run: npm run test:acceptance

- name: Run e2e tests
run: npm run test:e2e

- name: Stop containers
if: always()
run: docker-compose down

- name: Codacy Coverage Reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_TOKEN }}
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Using LTS version https://github.com/nodejs/release#release-schedule
FROM node:lts-alpine AS builder
# https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker/issues/137
FROM node:14-alpine3.17 AS builder

# Create app directory
WORKDIR /app
Expand All @@ -19,7 +19,8 @@ COPY src ./src

RUN npm run build

FROM node:lts-alpine
# https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker/issues/137
FROM node:14-alpine3.17
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/dist ./dist
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## Local setup

- Install Node `14`
- clone repo
- Update `.env` and `prisma/.env`
- Make sure Postgres is up and running
Expand Down
64 changes: 39 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
version: "3.7"
services:
# api:
# build:
# context: .
# dockerfile: Dockerfile
# environment:
# DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
# JWT_SECRET: ${JWT_SECRET}
# JWT_LIFE_TIME: ${JWT_LIFE_TIME}
# BODY_PARSER_JSON_LIMIT: ${BODY_PARSER_JSON_LIMIT}
# APP_FRONTEND_URL: ${APP_FRONTEND_URL}
# ports:
# - "${APP_PORT}:3000"
# expose:
# - "${APP_PORT}"
# depends_on:
# - postgres
api:
container_name: vrt_api
build:
context: .
dockerfile: Dockerfile
environment:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
JWT_SECRET: ${JWT_SECRET}
JWT_LIFE_TIME: ${JWT_LIFE_TIME}
BODY_PARSER_JSON_LIMIT: ${BODY_PARSER_JSON_LIMIT}
APP_FRONTEND_URL: ${APP_FRONTEND_URL}
ports:
- "${APP_PORT}:3000"
expose:
- "${APP_PORT}"
depends_on:
- postgres
migration:
container_name: vrt_migration
build:
context: prisma
dockerfile: Dockerfile
environment:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
depends_on:
- postgres
postgres:
image: postgres:12
container_name: postgres
image: postgres:12-alpine3.18
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
Expand All @@ -29,13 +40,16 @@ services:
- "${POSTGRES_PORT}"
volumes:
- postgres:/var/lib/postgresql/data
# migration:
# build:
# context: prisma
# dockerfile: Dockerfile
# environment:
# DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
# depends_on:
# - postgres
pgadmin:
container_name: pgadmin4
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "5050:80"
depends_on:
- postgres
volumes:
postgres:
6 changes: 5 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/** @returns {Promise<import('jest').Config>} */
module.exports = async () => {
return {
projects: ['./test/jest.config.ts', './src/jest.config.ts'],
projects: [
'./src/jest.config.ts',
'./test/jest.config.ts',
'./test_acceptance/jest.config.ts'
],
roots: ['./'],
testTimeout: 30000,
};
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"prisma:generate": "prisma generate",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --projects src",
"test:watch": "jest --projects src --watch",
"test:cov": "jest --projects src --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --projects src --runInBand",
"test:e2e": "jest --projects test"
"test:e2e": "jest --projects test",
"test:acceptance": "jest --projects test_acceptance"
},
"dependencies": {
"@nestjs/common": "^8.4.1",
Expand Down
4 changes: 2 additions & 2 deletions prisma/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Using LTS version https://github.com/nodejs/release#release-schedule
FROM node:lts-alpine
# https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker/issues/137
FROM node:14-alpine3.17

RUN apk add --no-cache bash

Expand Down
30 changes: 30 additions & 0 deletions test_acceptance/acceptance.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { User } from '@prisma/client';
import axios from 'axios'
import { UserLoginRequestDto } from 'src/users/dto/user-login-request.dto';
import { UserLoginResponseDto } from 'src/users/dto/user-login-response.dto';
import uuidAPIKey from 'uuid-apikey';

axios.defaults.baseURL = 'http://localhost:4200';

let user: Partial<User> = {
email: `${uuidAPIKey.create().uuid}@example.com`,
password: '123456',
firstName: 'fName',
lastName: 'lName',
};
const loginData: UserLoginRequestDto = {
email: user.email,
password: user.password,
}

describe('Acceptance', () => {

test('Register and login', async () => {
await axios.post<User>('/users/register', user);

const response = await axios.post<UserLoginResponseDto>('/users/login', loginData)

expect(response.status).toBe(201)
expect(response.data.token).toBeDefined()
})
})
15 changes: 15 additions & 0 deletions test_acceptance/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** @returns {Promise<import('jest').Config>} */
module.exports = async () => {
return {
name: 'Acceptance',
displayName: 'Acceptance',
roots: ['./'],
testTimeout: 30000,
testRegex: '.spec.ts$',
moduleFileExtensions: ['js', 'json', 'ts'],
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
testEnvironment: 'node',
};
};