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

feat: [sc-129] Continuous Integration #20

Merged
merged 6 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}
46 changes: 46 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Continuous Integration

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
linting:
name: Prettier, Linting, Type Checking
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- run: yarn install --prefer-offline --frozen-lockfile --non-interactive
- name: ESLint check
run: yarn eslint .
- name: Prettier check
run: yarn prettier . --check **/*.{js,ts,tsx}
- name: Typescript check
run: yarn check-types

unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'
- run: yarn install --prefer-offline --frozen-lockfile --non-interactive
- name: Unit tests 🔎
run: yarn test
- name: Build 🔎
run: yarn build
2 changes: 1 addition & 1 deletion Src/Firebase/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function createEvent(event: Event): Promise<Event> {
export async function getAllEventsByOrgId(orgId: number): Promise<Event[]> {
const q = query(collection(db, 'events'), where('orgId', '==', orgId));
const eventsList = await getDocs(q);
let events: Event[] = [];
const events: Event[] = [];
eventsList.forEach((docSnap) => {
const startDate: Date = docSnap.data().start.toDate();
const endDate: Date = docSnap.data().end.toDate();
Expand Down
5 changes: 2 additions & 3 deletions Src/Firebase/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import jwt from 'jsonwebtoken';
import { SECRET_KEY } from '../secrets/jwtSecretKey';
import { BaseError } from '../errorHandler/baseErrors';
import { isValidUser } from '../errorHandler/validations';

const bcrypt = require('bcrypt');
import bcrypt from 'bcrypt';

//should return a token aswell
export async function createUser(newUser: User): Promise<User> {
Expand All @@ -31,7 +30,7 @@ export async function createUser(newUser: User): Promise<User> {
if (!isValidUser(newUser)) {
throw new BaseError('User is not valid', 400);
}
const hashedPassword: string = await bcrypt.hash(newUser.password, 10);
const hashedPassword: string = await bcrypt.hash(newUser.password!, 10);
const docRef = doc(collection(db, `users`));
const user: User = {
id: docRef.id,
Expand Down
4 changes: 1 addition & 3 deletions Src/errorHandler/handlerForExpress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express, { Request, Response, NextFunction } from 'express';
import { Request, Response, NextFunction } from 'express';
import { BaseError } from './baseErrors';

// Error handling Middleware function for logging the error message
Expand All @@ -18,7 +18,6 @@ export const errorResponder = (
error: Error,
request: Request,
response: Response,
next: NextFunction,
) => {
response.header('Content-Type', 'application/json');
if (error instanceof BaseError) {
Expand All @@ -33,7 +32,6 @@ export const errorResponder = (
export const invalidPathHandler = (
request: Request,
response: Response,
next: NextFunction,
) => {
response.status(404);
response.send('invalid path');
Expand Down
2 changes: 1 addition & 1 deletion Src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express, { Request, Response, NextFunction } from 'express';
import express, { Request, Response } from 'express';
import eventRoutes from './routes/events';
import userRoutes from './routes/users';
import cors from 'cors';
Expand Down
7 changes: 3 additions & 4 deletions Src/jest/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ import {
import { Event } from '../models/event';
import { app } from '../index';
import { BaseError } from '../errorHandler/baseErrors';

const request = require('supertest');
import request from 'supertest';

const orgId: number = Math.floor(Math.random() * 10000) + 1;
const startDate: Date = new Date('2018-12-17T23:24:00');
const endDate: Date = new Date('2019-12-17T03:24:00');
let testEvent: Event = {
const testEvent: Event = {
title: 'Test Event',
description: 'Test Description',
start: startDate,
end: endDate,
orgId: orgId,
};
let testEvent2: Event = {
const testEvent2: Event = {
title: 'Test Event 2',
description: 'Test Description 2',
start: startDate,
Expand Down
7 changes: 3 additions & 4 deletions Src/jest/users.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { app } from '../index';
//import { app } from '../index';
import { User } from '../models/user';
import { expect, test } from '@jest/globals';
import {
createUser,
getUserById,
getAllUsersByOrgId,
deleteUser,
updateUser,
userLogin,
} from '../firebase/users';
import { BaseError } from '../errorHandler/baseErrors';
Expand All @@ -16,9 +15,9 @@ import {
isValidEmail,
} from '../errorHandler/validations';

const request = require('supertest');
//const request = require('supertest'); //express

let testUser1: User = {
const testUser1: User = {
id: '',
firstName: 'Thor',
lastName: 'Hansen',
Expand Down
4 changes: 2 additions & 2 deletions Src/routes/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router, Request, Response, NextFunction } from 'express';
import { Router, Request, Response } from 'express';
import { body, validationResult } from 'express-validator';
import { Event } from '../models/event';
import { asyncHandler } from '../errorHandler/asyncHandler';
Expand Down Expand Up @@ -46,7 +46,7 @@ router.post(
// get all
router.get(
'/:orgId/',
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
asyncHandler(async (req: Request, res: Response) => {
const events = await getAllEventsByOrgId(parseInt(req.params.orgId));
res.json(events);
}),
Expand Down
6 changes: 3 additions & 3 deletions Src/routes/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router, Request, Response, NextFunction } from 'express';
import { Router, Request, Response } from 'express';

import { body, validationResult } from 'express-validator';
import { User } from '../models/user';
Expand All @@ -13,8 +13,8 @@ import {
getUserByToken,
} from '../firebase/users';
import { auth, CustomRequest } from './auth';
import bcrypt from 'bcrypt';

const bcrypt = require('bcrypt');
const router = Router();

const userValidationRules = [
Expand Down Expand Up @@ -65,7 +65,7 @@ router.post(
router.get(
'/:orgId/',
auth,
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
asyncHandler(async (req: Request, res: Response) => {
const users = await getAllUsersByOrgId(parseInt(req.params.orgId));
res.json(users);
}),
Expand Down
Loading
Loading