Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to production 19.02.2021 #71

Merged
merged 18 commits into from
Feb 19, 2021
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
18 changes: 10 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: '[Bug report]:'
labels: 'bug'
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: '[Feature request]:'
labels: 'enhancement'
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
27 changes: 21 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# For all config options check: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#reviewersę

version: 2
updates:
- package-ecosystem: "yarn"
directory: "/"
- package-ecosystem: 'npm'
directory: '/'
reviewers:
- 'Jozwiaczek'
- 'Mefjus'
schedule:
interval: "monthly"
day: "friday"
time: "16:00"
timezone: "Europe/Warsaw"
interval: 'monthly'
day: 'friday'
time: '16:00'
timezone: 'Europe/Warsaw'
- package-ecosystem: 'github-actions'
directory: '/'
reviewers:
- 'Jozwiaczek'
- 'Mefjus'
schedule:
interval: 'monthly'
day: 'friday'
time: '16:00'
timezone: 'Europe/Warsaw'
56 changes: 56 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: 'CodeQL'

on:
push:
branches: [main, production]
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
schedule:
- cron: '23 18 * * 4'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: ['javascript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
32 changes: 30 additions & 2 deletions .github/workflows/continous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,52 @@ name: Continuous Integration
on: [pull_request]

env:
NODE_VERSION: '14.x'
NODE_VERSION: '12.x'

jobs:
Validate:
name: 'Validate Pull Request'
timeout-minutes: 10
runs-on: ubuntu-latest
container: node
env:
DB_PORT: 5432
DB_HOST: postgres
DB_USERNAME: postgres
DB_PASSWORD: postgres_password
DB_DATABASE_TEST: smart_gate_db_test
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres_password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: 'Git checkout'
uses: actions/checkout@v2
- name: 'Use cached node_modules'
uses: actions/cache@v2
uses: actions/cache@v2.1.4
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: 'Install dependency'
run: yarn install --frozen-lockfile
- name: 'Audit dependencies'
run: /bin/sh -c 'yarn audit --level high; [[ $? -ge 8 ]] && exit 1 || exit 0'
- name: 'Run Prettier'
run: yarn prettier
- name: 'Run ESLint'
run: yarn lint
- name: 'Setup test database'
run: yarn ci:setup:db
- name: 'Run unit tests'
run: yarn test
- name: 'Run E2E tests'
run: yarn test:e2e
- name: 'Build API'
run: cd packages/api && yarn build
- name: 'Build Client'
Expand Down
1 change: 0 additions & 1 deletion .huskyrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
hooks: {
'pre-commit': 'yarn type-check && lint-staged',
'pre-push': 'yarn test && yarn test:e2e',
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
},
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[![Netlify Status](https://api.netlify.com/api/v1/badges/426cfdcb-e5e4-4067-97f2-c6106bde9195/deploy-status)](https://app.netlify.com/sites/smart-gate/deploys)
![CI](https://github.com/Jozwiaczek/smart-gate/workflows/Continuous%20Integration/badge.svg)
![GitHub last commit](https://img.shields.io/github/last-commit/Jozwiaczek/smart-gate)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FJozwiaczek%2Fsmart-gate.svg?type=small)](https://app.fossa.com/projects/git%2Bgithub.com%2FJozwiaczek%2Fsmart-gate?ref=badge_small)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FJozwiaczek%2Fsmart-gate.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FJozwiaczek%2Fsmart-gate?ref=badge_shield)

## 🚩 Table of Contents

Expand Down
71 changes: 71 additions & 0 deletions ci/setupTestDatabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Client } from 'pg';

interface CreateClientAndConnectParams {
host: string;
port: number;
user: string;
password: string;
database?: string;
}

const createClientAndConnect = async ({
host,
port,
user,
password,
database,
}: CreateClientAndConnectParams) => {
const client = new Client({
host,
port,
user,
password,
database,
});

await client.connect();

return client;
};

const setupTestDatabase = async (): Promise<void> => {
const requiredVariables = [
'DB_HOST',
'DB_USERNAME',
'DB_PASSWORD',
'DB_DATABASE_TEST',
'DB_PORT',
];
const missingVariables = requiredVariables.filter((key) => !process.env[key]);
if (missingVariables.length > 0) {
throw new Error(`Missing environment variables: ${missingVariables.join(', ')}`);
}

const adminClient = await createClientAndConnect({
host: process.env.DB_HOST,
port: +(process.env.DB_PORT as string),
user: process.env.DB_USERNAME as string,
password: process.env.DB_PASSWORD as string,
});

await adminClient.query(`CREATE DATABASE ${process.env.DB_DATABASE_TEST}`);

const testDatabaseClient = await createClientAndConnect({
host: process.env.DB_HOST,
port: +(process.env.DB_PORT as string),
user: process.env.DB_USERNAME as string,
password: process.env.DB_PASSWORD as string,
database: process.env.DB_DATABASE_TEST,
});

await testDatabaseClient.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"');
};

setupTestDatabase()
.then(() => {
process.exit();
})
.catch((error) => {
console.error(error);
process.exit(1);
});
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"scripts": {
"build": "lerna run build",
"check": "yarn lint:fix && yarn prettier:fix && yarn type-check && yarn test && yarn test:e2e && yarn sortPackageJson",
"ci:setup:db": "yarn ts-node ci/setupTestDatabase.ts",
"heroku-postbuild": "yarn install && cd packages/api && yarn build",
"preinstall": "node -e \"if (process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('Use yarn for installing')\"",
"lint": "lerna run lint",
Expand All @@ -35,10 +36,15 @@
"test:e2e": "lerna run test:e2e",
"type-check": "lerna run type-check"
},
"dependencies": {
"dotenv": "^8.2.0",
"pg": "^8.5.1"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@commitlint/config-lerna-scopes": "^11.0.0",
"@types/pg": "^7.14.10",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"enquirer": "^2.3.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"workbox-navigation-preload": "^5.1.3",
"workbox-precaching": "^5.1.3",
"workbox-range-requests": "^5.1.3",
"workbox-routing": "^5.1.3",
"workbox-routing": "^6.1.0",
"workbox-strategies": "^5.1.3",
"workbox-streams": "^5.1.3"
},
Expand All @@ -42,7 +42,7 @@
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"@types/react-dom": "^17.0.1",
"ra-data-nestjsx-crud": "^1.1.5",
"react-scripts": "4.0.1",
"serve": "^11.3.2",
Expand Down
1 change: 1 addition & 0 deletions packages/api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ module.exports = {
coverageDirectory: '../coverage',
coverageReporters: ['html', 'text'],
testEnvironment: 'node',
globalSetup: '../test/globalSetup.ts',
};
3 changes: 2 additions & 1 deletion packages/api/nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
"sourceRoot": "src/modules",
"entryFile": "src/main"
}
1 change: 0 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"ms": "^2.1.3",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"pg": "^8.5.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/interfaces/cookie-types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request } from '@nestjs/common';
import { CookieOptions } from 'express';

import { UserEntity } from '../database/entities/user.entity';
import { UserEntity } from '../modules/database/entities/user.entity';

type Modify<T, R> = Omit<T, keyof R> & R;
export interface LoginRequest
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dotenv/config';
import { NestFactory } from '@nestjs/core';
import cookieParser from 'cookie-parser';

import { AppModule } from './app.module';
import { AppModule } from './modules/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
UseGuards,
} from '@nestjs/common';

import { CookieRequest, CookieResponse, LoginRequest } from '../interfaces/cookie-types';
import { TokenPayload } from '../interfaces/token-types';
import { CookieRequest, CookieResponse, LoginRequest } from '../../interfaces/cookie-types';
import { TokenPayload } from '../../interfaces/token-types';
import { constants, cookiesUtils } from '../../utils';
import { CreateUserDto } from '../users/dto/create-user.dto';
import { constants, cookiesUtils } from '../utils';
import { AuthService } from './auth.service';
import { CookiePayload } from './decorators/cookiePayload.decorator';
import { LocalAuthGuard } from './strategies/local/local-auth.guard';
Expand All @@ -30,7 +30,7 @@ export class AuthController {
} = request;
const genTokens = await this.authService.login(user, keepMeLoggedIn);
const { setCookies } = cookiesUtils;
setCookies(genTokens, keepMeLoggedIn, response, true);
setCookies(genTokens, keepMeLoggedIn, response, false);
// TODO: add separate method for extracting user
// eslint-disable-next-line no-unused-vars
const { password, ...rest } = user;
Expand All @@ -47,7 +47,7 @@ export class AuthController {
});
const genTokens = await this.authService.login(newUser, false);
const { setCookies } = cookiesUtils;
setCookies(genTokens, false, response, true);
setCookies(genTokens, false, response, false);
// TODO: add separate method for extracting user
// eslint-disable-next-line no-unused-vars
const { password, ...rest } = user;
Expand Down
Loading