-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
…inting
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: knights-ecomm-be CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build-lint-test-coverage: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run ESLint and Prettier | ||
run: npm run lint | ||
|
||
- name: Build project | ||
run: npm run build --if-present | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
||
- name: Upload coverage report to Coveralls | ||
uses: coverallsapp/[email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ package-lock.json | |
coverage/ | ||
dist | ||
/src/logs | ||
.DS_Store | ||
.DS_Store | ||
ormconfig.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
export default { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
testMatch: ["**/**/*.test.ts"], | ||
verbose: true, | ||
forceExit: true, | ||
clearMocks: true, | ||
resetMocks: true, | ||
restoreMocks: true, | ||
collectCoverageFrom: [ | ||
"src/**/*.{ts,tsx}", // Include all JavaScript/JSX files in the src directory | ||
], | ||
coveragePathIgnorePatterns: [ | ||
"/node_modules/", // Exclude the node_modules directory | ||
"/__tests__/", // Exclude the tests directory | ||
], | ||
}; | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/**/*.test.ts'], | ||
verbose: true, | ||
forceExit: true, | ||
clearMocks: true, | ||
resetMocks: true, | ||
restoreMocks: true, | ||
collectCoverageFrom: [ | ||
'src/**/*.{ts,tsx}', // Include all JavaScript/JSX files in the src directory | ||
], | ||
coveragePathIgnorePatterns: [ | ||
'/node_modules/', // Exclude the node_modules directory | ||
'/__tests__/', // Exclude the tests directory | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import request from 'supertest'; | ||
import {app, server} from '../index'; // update this with the path to your app file | ||
import { app, server } from '../index'; // update this with the path to your app file | ||
|
||
import { createConnection, getConnection, getConnectionOptions } from 'typeorm'; | ||
|
||
beforeAll(async () => { | ||
// Connect to the test database | ||
const connectionOptions = await getConnectionOptions(); | ||
await createConnection({ ...connectionOptions, name: 'testConnection' }); | ||
}); | ||
afterAll(async () => { | ||
await getConnection('testConnection').close(); | ||
server.close(); | ||
}); | ||
|
||
describe('GET /', () => { | ||
afterAll(done => { | ||
server.close(done); | ||
}); | ||
// afterAll(done => { | ||
// server.close(done); | ||
// }); | ||
|
||
it('responds with "Knights Ecommerce API"', done => { | ||
request(app) | ||
.get('/') | ||
.expect(200, 'Knights Ecommerce API', done); | ||
request(app).get('/').expect(200, 'Knights Ecommerce API', done); | ||
}); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// export all controllers | ||
function myFunction () { | ||
function myFunction (): void { | ||
console.log('Hello'); | ||
} | ||
myFunction(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
import { Request, Response } from 'express'; | ||
|
||
class CustomError extends Error { | ||
statusCode: number; | ||
status: string; | ||
statusCode: number; | ||
status: string; | ||
|
||
constructor (message: string, statusCode: number) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
constructor (message: string, statusCode: number) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
|
||
const errorHandler = ( | ||
err: CustomError, | ||
req: Request, | ||
res: Response, | ||
|
||
) => { | ||
err.statusCode = err.statusCode || 500; | ||
err.status = err.status || 'error'; | ||
res.status(err.statusCode).json({ | ||
status: err.statusCode, | ||
message: err.message | ||
}); | ||
console.error(err.stack); | ||
const errorHandler = (err: CustomError, req: Request, res: Response) => { | ||
Check warning on line 15 in src/middlewares/errorHandler.ts GitHub Actions / build-lint-test-coverage
Check warning on line 15 in src/middlewares/errorHandler.ts GitHub Actions / build-lint-test-coverage
Check warning on line 15 in src/middlewares/errorHandler.ts GitHub Actions / build-lint-test-coverage
|
||
err.statusCode = err.statusCode || 500; | ||
err.status = err.status || 'error'; | ||
res.status(err.statusCode).json({ | ||
status: err.statusCode, | ||
message: err.message, | ||
}); | ||
console.error(err.stack); | ||
}; | ||
|
||
export { CustomError, errorHandler }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import { OrmConfig } from "../configs/db_config"; | ||
import { createConnection } from "typeorm"; | ||
|
||
const dbConnection = async () => { | ||
Check warning on line 3 in src/startups/dbConnection.ts GitHub Actions / build-lint-test-coverage
|
||
await OrmConfig.initialize() | ||
.then(() => { | ||
console.log("[db]: Database connected successfully"); | ||
}) | ||
.catch((error) => { | ||
console.log("[db]: Database connection failed"); | ||
console.log(error); | ||
}); | ||
try { | ||
const connection = await createConnection(); | ||
Check warning on line 5 in src/startups/dbConnection.ts GitHub Actions / build-lint-test-coverage
Check warning on line 5 in src/startups/dbConnection.ts GitHub Actions / build-lint-test-coverage
Check warning on line 5 in src/startups/dbConnection.ts GitHub Actions / build-lint-test-coverage
|
||
console.log('Connected to the database'); | ||
// Start your application logic here | ||
} catch (error) { | ||
console.error('Error connecting to the database:', error); | ||
} | ||
}; | ||
|
||
export { dbConnection }; |