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

[NO TICKET] Epic Remote Update #136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c4948fa
grammar edit
brok3turtl3 May 23, 2024
a392e6a
Merge pull request #123 from Code-Hammers/template-edit
brok3turtl3 May 23, 2024
8feb574
initial commit with prelim prettier config
seantokuzo May 28, 2024
ae452c0
eslint config started
seantokuzo May 29, 2024
5678452
i did not steal this script - totally my original work
seantokuzo May 29, 2024
d0f5369
remove derp.js ignore
seantokuzo May 29, 2024
c319c8d
add decoration util script
seantokuzo May 29, 2024
720f379
add config names and comments
seantokuzo May 29, 2024
67ba1fe
add vscode project settings
seantokuzo May 29, 2024
29decc7
add prettier and eslint pkgs
seantokuzo May 29, 2024
52b28b1
update colors and decorate
seantokuzo May 29, 2024
2b22b55
add linting and formmating readme doc
seantokuzo May 29, 2024
cc52f91
define files for prettier to ignore
seantokuzo May 29, 2024
74ce0c3
remove unnecessary ignores
seantokuzo May 29, 2024
14fcc83
add docker lint scripts
seantokuzo May 29, 2024
ceff495
add docker-compose-lint.yml
seantokuzo May 29, 2024
01cded2
update root volume
seantokuzo May 29, 2024
1344fdf
add jest specific eslint rules
seantokuzo May 30, 2024
4c4da05
change eslint config file to commonjs
seantokuzo May 30, 2024
5bb43b2
update pr template file names
seantokuzo May 31, 2024
47445b0
Merge pull request #125 from Code-Hammers/CHE-165/task/PR-Template-Bu…
seantokuzo Jun 1, 2024
775c971
deleted old pr template and rename new one
seantokuzo Jun 1, 2024
8fea87d
initial commit with prelim prettier config
seantokuzo May 28, 2024
1f483b4
eslint config started
seantokuzo May 29, 2024
f450fb7
i did not steal this script - totally my original work
seantokuzo May 29, 2024
8bfa33a
remove derp.js ignore
seantokuzo May 29, 2024
03717f7
add decoration util script
seantokuzo May 29, 2024
a5aa19d
add config names and comments
seantokuzo May 29, 2024
d278837
add vscode project settings
seantokuzo May 29, 2024
e72205d
add prettier and eslint pkgs
seantokuzo May 29, 2024
51e07be
update colors and decorate
seantokuzo May 29, 2024
bbc9792
add linting and formmating readme doc
seantokuzo May 29, 2024
a0db676
define files for prettier to ignore
seantokuzo May 29, 2024
03eb52a
remove unnecessary ignores
seantokuzo May 29, 2024
3464da8
add docker lint scripts
seantokuzo May 29, 2024
2f6e43b
add docker-compose-lint.yml
seantokuzo May 29, 2024
e029bf6
update root volume
seantokuzo May 29, 2024
8d5fb05
add jest specific eslint rules
seantokuzo May 30, 2024
34b0522
change eslint config file to commonjs
seantokuzo May 30, 2024
156713c
change image used for docker-test:all to ch-dev-dep-test
seantokuzo Jun 1, 2024
d44ffd8
update base node image to lts version 20.14.0
seantokuzo Jun 1, 2024
4af8665
update and remove extra colors
seantokuzo Jun 1, 2024
f561050
add build check script
seantokuzo Jun 1, 2024
b5d1568
add npm script for docker build check and add --colors flag to test s…
seantokuzo Jun 1, 2024
fc49293
Merge branch 'CHE-162/task/Add-Prettier-Config-And-Linting' of https:…
seantokuzo Jun 1, 2024
ab78abb
fix bad remote pull
seantokuzo Jun 1, 2024
8e8bed8
replace pr template in /docs directory with new one - delete pr templ…
seantokuzo Jun 1, 2024
adaa0ba
Merge pull request #126 from Code-Hammers/CHE-166/task/PR-Template-Bu…
brok3turtl3 Jun 1, 2024
815f574
remove unnecessary recommended rule overrides
seantokuzo Jun 1, 2024
4ff0d4c
prettier + eslint auto fixes
seantokuzo Jun 1, 2024
ab7d6e2
tighten up config - edit rules, consolidate rule overrides
seantokuzo Jun 2, 2024
fe19b92
add linting to github action workflow
seantokuzo Jun 2, 2024
aeda236
manual lint fixes
seantokuzo Jun 2, 2024
5b9ef12
pull dev
seantokuzo Jun 2, 2024
00de249
update image name to match images used in docker-compose files
seantokuzo Jun 2, 2024
385114d
remove react import and unnecessary component type
seantokuzo Jun 3, 2024
6f6c645
importing react is mid - make react slap
seantokuzo Jun 3, 2024
03e7db5
set mode according to docs
seantokuzo Jun 3, 2024
3d3f922
CHE-162 Cleaning up dirty consoles
brok3turtl3 Jun 3, 2024
d93a5ab
CHE-162 More console logs removed
brok3turtl3 Jun 3, 2024
52ca3ce
CHE-162 Smashing console logs
brok3turtl3 Jun 3, 2024
8795fa8
CHE-162 Code cleanup
brok3turtl3 Jun 3, 2024
11dd03a
update react type usage and imports
seantokuzo Jun 3, 2024
e19eee5
Merge branch 'CHE-162/task/Add-Prettier-Config-And-Linting' of https:…
seantokuzo Jun 3, 2024
4c11457
remove last JSX.Element type and update TS style guide
seantokuzo Jun 3, 2024
980ed79
remove mode from webpack config - setting mode in CLI script
seantokuzo Jun 3, 2024
4b25527
CHE-162 Updated image names in compose files
brok3turtl3 Jun 5, 2024
153ef27
Merge remote-tracking branch 'origin/CHE-162/task/Add-Prettier-Config…
brok3turtl3 Jun 5, 2024
3950dac
CHE-162 Updated naming in workflows for consistency
brok3turtl3 Jun 5, 2024
75db4bd
Merge pull request #128 from Code-Hammers/CHE-162/task/Add-Prettier-C…
brok3turtl3 Jun 5, 2024
2428831
CHE-188 Updated script to remove all volumes and images except mongo …
brok3turtl3 Jun 5, 2024
7910943
Merge pull request #132 from Code-Hammers/CHE-188/task/Update-Docker-…
brok3turtl3 Jun 6, 2024
5bf274c
dev merge
brok3turtl3 Jun 7, 2024
0ce80fe
CHE-140 temp image change
brok3turtl3 Jun 7, 2024
4ef0807
CHE-140 Post merge clean up
brok3turtl3 Jun 7, 2024
59917c9
Merge branch 'CHE-140/epic/Create-Job-Application-Tracker' of https:/…
brok3turtl3 Jun 7, 2024
be2cdf8
Code cleanup for linter
brok3turtl3 Jun 8, 2024
99b15da
Further linting clean up
brok3turtl3 Jun 8, 2024
192adad
shakes fist at linter
brok3turtl3 Jun 8, 2024
f9d07a8
Prettier formatting updates
brok3turtl3 Jun 8, 2024
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
11 changes: 5 additions & 6 deletions .github/workflows/build-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "18.17.1"
node-version: '18.17.1'
- name: Build Docker Image
run: docker build -t codehammers/cd-testv1:latest -f Dockerfile-dev .
run: docker build -t codehammers/ch-dev-dep-v2:latest -f Dockerfile-dev .
- name: Install Root Dependencies
run: docker run codehammers/cd-testv1:latest npm install
run: docker run codehammers/ch-dev-dep-v2:latest npm install
- name: Install Client Dependencies
run: docker run codehammers/cd-testv1:latest /bin/sh -c "cd client && npm install"
#- name: List node_modules
#run: docker run codehammers/cd-testv1:latest /bin/sh -c "ls node_modules && cd client && ls node_modules"
run: docker run codehammers/ch-dev-dep-v2:latest /bin/sh -c "cd client && npm install"
- run: LINT_COMMAND=lint docker-compose -f docker-compose-lint.yml up --abort-on-container-exit
- run: docker-compose -f docker-compose-test.yml up --abort-on-container-exit
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# These files should always be ignored by Prettier.

build/
coverage/
dist/
node_modules/
package-lock.json
*.test.jsx.snap
*.test.tsx.snap
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"jsxSingleQuote": false,
"printWidth": 100,
"tabWidth": 2,
"trailingComma": "all"
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,

"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
}
}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set Node.js version
FROM node:18.17.1 as builder
FROM node:20.14.0 as builder

# Set the working directory
WORKDIR /usr/src/app
Expand All @@ -22,7 +22,7 @@ RUN cd client && npm run build
RUN npm run build

# Set up the final image
FROM node:18.17.1
FROM node:20.14.0

# Set the working directory
WORKDIR /usr/src/app
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set Node version
FROM node:18.17.1
FROM node:20.14.0

# Install webpack globally
RUN npm install webpack -g
Expand Down
31 changes: 0 additions & 31 deletions PULL_REQUEST_TEMPLATE.md

This file was deleted.

38 changes: 17 additions & 21 deletions __tests__/db.test.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
import mongoose from "mongoose";
import connectDB from "../server/config/db";
import mongoose from 'mongoose';
import connectDB from '../server/config/db';

jest.mock("mongoose", () => ({
jest.mock('mongoose', () => ({
connect: jest.fn().mockImplementation(() =>
Promise.resolve({
connection: { host: "test-host" },
})
connection: { host: 'test-host' },
}),
),
}));

describe("connectDB", () => {
describe('connectDB', () => {
let mockExit: jest.SpyInstance;
let mockConsoleError: jest.SpyInstance;
let mockConsoleLog: jest.SpyInstance;

beforeEach(() => {
mockExit = jest
.spyOn(process, "exit")
.mockImplementation((_code) => undefined as never);
mockConsoleError = jest.spyOn(console, "error").mockImplementation();
mockConsoleLog = jest.spyOn(console, "log").mockImplementation();
mockExit = jest.spyOn(process, 'exit').mockImplementation((_code) => undefined as never);
mockConsoleError = jest.spyOn(console, 'error').mockImplementation();
});

afterEach(() => {
jest.clearAllMocks();
});

it("should call mongoose.connect with MONGO_URI", async () => {
process.env.MONGO_URI = "test-mongo-uri";
it('should call mongoose.connect with MONGO_URI', async () => {
process.env.MONGO_URI = 'test-mongo-uri';
await connectDB();
expect(mongoose.connect).toHaveBeenCalledWith("test-mongo-uri");
expect(mongoose.connect).toHaveBeenCalledWith('test-mongo-uri');
});

it("should log an error and exit the process if mongoose.connect fails", async () => {
process.env.MONGO_URI = "test-mongo-uri";
it('should log an error and exit the process if mongoose.connect fails', async () => {
process.env.MONGO_URI = 'test-mongo-uri';
(mongoose.connect as jest.Mock).mockImplementationOnce(() => {
throw new Error("test error");
throw new Error('test error');
});

await connectDB();

expect(mockConsoleError).toHaveBeenCalledWith("test error");
expect(mockConsoleError).toHaveBeenCalledWith('test error');
expect(mockExit).toHaveBeenCalledWith(1);
});

it("should throw an error if MONGO_URI is not defined", async () => {
it('should throw an error if MONGO_URI is not defined', async () => {
delete process.env.MONGO_URI;

await connectDB();

expect(mockConsoleError).toHaveBeenCalledWith(
"MONGO_URI must be defined in the environment variables."
'MONGO_URI must be defined in the environment variables.',
);
expect(mockExit).toHaveBeenCalledWith(1);
});
Expand Down
25 changes: 10 additions & 15 deletions __tests__/errorController.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from "express";
import { notFound, errorHandler } from "../server/controllers/errorControllers";
import { Request, Response, NextFunction } from 'express';
import { notFound, errorHandler } from '../server/controllers/errorControllers';

describe("Middleware Tests", () => {
describe('Middleware Tests', () => {
let mockRequest: Partial<Request>;
let mockResponse: Partial<Response>;
let mockNext: NextFunction;
Expand All @@ -15,29 +15,24 @@ describe("Middleware Tests", () => {
mockNext = jest.fn();
});

describe("notFound Middleware", () => {
it("should return 404 and the original URL", () => {
describe('notFound Middleware', () => {
it('should return 404 and the original URL', () => {
notFound(mockRequest as Request, mockResponse as Response, mockNext);
expect(mockResponse.status).toHaveBeenCalledWith(404);
expect(mockNext).toHaveBeenCalled();
});
});

describe("errorHandler Middleware", () => {
it("should handle the error correctly", () => {
const mockError = new Error("Some error");
errorHandler(
mockError,
mockRequest as Request,
mockResponse as Response,
mockNext
);
describe('errorHandler Middleware', () => {
it('should handle the error correctly', () => {
const mockError = new Error('Some error');
errorHandler(mockError, mockRequest as Request, mockResponse as Response, mockNext);
expect(mockResponse.status).toHaveBeenCalledWith(400);
expect(mockResponse.json).toHaveBeenCalledWith(
expect.objectContaining({
message: expect.anything(),
stack: expect.any(String),
})
}),
);
});
});
Expand Down
50 changes: 25 additions & 25 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import request from "supertest";
import app, { startServer } from "../server/index";
import { Server } from "http";
import request from 'supertest';
import app, { startServer } from '../server/index';
import { Server } from 'http';
import mongoose from 'mongoose';

let server: Server;
// TODO
/*eslint jest/no-disabled-tests: "off"*/

import mongoose from "mongoose";
let server: Server;

beforeEach(() => {
server = startServer();
Expand All @@ -24,49 +26,47 @@ afterAll(async () => {
await mongoose.connection.close();
});

describe("API Endpoints", () => {
xit("should get the API Running message in development", async () => {
const res = await request(app).get("/api");
describe('API Endpoints', () => {
xit('should get the API Running message in development', async () => {
const res = await request(app).get('/api');
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty("message", "API Running - Hazzah!");
expect(res.body).toHaveProperty('message', 'API Running - Hazzah!');
});

xit("should serve the frontend files in production", async () => {
process.env.NODE_ENV = "production";
xit('should serve the frontend files in production', async () => {
process.env.NODE_ENV = 'production';

const res = await request(app).get("/");
const res = await request(app).get('/');
expect(res.statusCode).toEqual(200);

expect(res.headers["content-type"]).toContain("text/html");
expect(res.headers['content-type']).toContain('text/html');
});

xit("should catch all routes and serve the frontend in production", async () => {
process.env.NODE_ENV = "production";
const res = await request(app).get("/nonexistentroute");
xit('should catch all routes and serve the frontend in production', async () => {
process.env.NODE_ENV = 'production';
const res = await request(app).get('/nonexistentroute');
expect(res.statusCode).toEqual(200);
expect(res.headers["content-type"]).toContain("text/html");
expect(res.headers['content-type']).toContain('text/html');
});
});

describe("Server Start-Up", () => {
it("should start up the server if required as main module", async () => {
describe('Server Start-Up', () => {
it('should start up the server if required as main module', async () => {
const originalLog = console.log;
const logCalls: string[] = [];
console.log = jest.fn((...args: any[]) => {
logCalls.push(args.join(" "));
console.log = jest.fn((...args: string[]) => {
logCalls.push(args.join(' '));
});

jest.resetModules();

await new Promise((resolve) => {
if (server) {
server.on("listening", resolve);
server.on('listening', resolve);
}
});

const hasExpectedLog = logCalls.some((log) =>
log.includes("Server running in")
);
const hasExpectedLog = logCalls.some((log) => log.includes('Server running in'));
expect(hasExpectedLog).toBe(true);

console.log = originalLog;
Expand Down
Loading
Loading