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

fixed code smells #606

Merged
merged 4 commits into from
May 4, 2024
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
9 changes: 8 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ jobs:
- name: Build
run: npm run build --if-present
- name: Test
run: npm run test
run: npm run test
- name: Test & publish code coverage
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TOKEN }}
with:
coverageCommand: npm run test
debug: true
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# [Node-Typescript-Boilerplate](https://blog.santoshshinde.com/skeleton-for-node-js-apps-written-in-typescript-444fa1695b30) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=santoshshinde2012_node-boilerplate&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=santoshshinde2012_node-boilerplate)![Github action workflow status](https://github.com/santoshshinde2012/node-boilerplate/actions/workflows/node.js.yml/badge.svg?branch=master)![CodeQL Analysis](https://github.com/santoshshinde2012/node-boilerplate/actions/workflows/codeql-analysis.yml/badge.svg?branch=master)![njsscan Analysis](https://github.com/santoshshinde2012/node-boilerplate/actions/workflows/njsscan.yml/badge.svg?branch=master)
# [Node-Typescript-Boilerplate](https://blog.santoshshinde.com/skeleton-for-node-js-apps-written-in-typescript-444fa1695b30) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=santoshshinde2012_node-boilerplate&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=santoshshinde2012_node-boilerplate)![Github action workflow status](https://github.com/santoshshinde2012/node-boilerplate/actions/workflows/node.js.yml/badge.svg?branch=master)![CodeQL Analysis](https://github.com/santoshshinde2012/node-boilerplate/actions/workflows/codeql-analysis.yml/badge.svg?branch=master)![njsscan Analysis](https://github.com/santoshshinde2012/node-boilerplate/actions/workflows/njsscan.yml/badge.svg?branch=master)![Maintainability](https://api.codeclimate.com/v1/badges/0e53f5d93de102b39641/maintainability)![Test Coverage](https://api.codeclimate.com/v1/badges/0e53f5d93de102b39641/test_coverage)

Skeleton for Node.js applications written in TypeScript


Expand Down Expand Up @@ -28,6 +29,9 @@ Try it!! I am happy to hear your feedback or any kind of new features.
- [snyk.io](https://app.snyk.io/org/santoshshinde2012/project/c040efe4-a06a-451d-9b01-be0be90ee42c)
- [CodeQL](https://codeql.github.com/)
- [njsscan](https://opensecurity.in/#engineering) is a static application testing (SAST) tool that can find insecure code patterns in your node.js applications
- [Codeclimate](https://codeclimate.com/)
- <a href="https://codeclimate.com/github/santoshshinde2012/node-boilerplate/maintainability"><img src="https://api.codeclimate.com/v1/badges/0e53f5d93de102b39641/maintainability" /></a>
- <a href="https://codeclimate.com/github/santoshshinde2012/node-boilerplate/test_coverage"><img src="https://api.codeclimate.com/v1/badges/0e53f5d93de102b39641/test_coverage" /></a>

- Documentation Standards
- Swagger Documentation Support
Expand All @@ -38,6 +42,8 @@ Try it!! I am happy to hear your feedback or any kind of new features.
- Integrated eslint, prettier and husky
- Added Unit Test cases and Intgration Test Cases
- 80% + Code Coverage

- Codeclimate Integration with Github action workflow

- Prodcution Ready Setup
- Follwed Production Ready Best Practices: Security
Expand Down
26 changes: 13 additions & 13 deletions test-report.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<testExecutions version="1">
<file path="/Users/santosh/Documents/workspace/github/node-boilerplate/tests/unit-tests/lib/crypto.spec.ts">
<testCase name="Crypto Lib (Encryption/Decryption) Testing for text" duration="10"/>
<testCase name="Crypto Lib (Encryption/Decryption) Testing for text" duration="5"/>
<testCase name="Crypto Lib (Encryption/Decryption) Testing for array" duration="2"/>
<testCase name="Crypto Lib (Encryption/Decryption) Testing for object" duration="2"/>
</file>
<file path="/Users/santosh/Documents/workspace/github/node-boilerplate/tests/unit-tests/middleware/error-handler.spec.ts">
<testCase name="ErrorHandler middleware with 0 status code" duration="6"/>
<testCase name="ErrorHandler middleware with 200 status code" duration="1"/>
<testCase name="ErrorHandler middleware with 0 status code" duration="10"/>
<testCase name="ErrorHandler middleware with 200 status code" duration="1"/>
<testCase name="ErrorHandler middleware with 200 status code" duration="0"/>
<testCase name="ErrorHandler middleware with 200 status code and updated env variables" duration="2"/>
</file>
<file path="/Users/santosh/Documents/workspace/github/node-boilerplate/tests/unit-tests/components/SystemStatusController.spec.ts">
<testCase name="System Status Controller test getError method" duration="2"/>
<testCase name="System Status Controller test getSystemInfo method" duration="4"/>
<testCase name="System Status Controller test getSystemInfo method with updated env variables" duration="2"/>
<testCase name="System Status Controller test getSystemInfo method with exception" duration="0"/>
<testCase name="System Status Controller test getServerTime method" duration="1"/>
<testCase name="System Status Controller test getSystemInfo method with updated env variables" duration="3"/>
<testCase name="System Status Controller test getSystemInfo method with exception" duration="1"/>
<testCase name="System Status Controller test getServerTime method" duration="0"/>
<testCase name="System Status Controller test getServerTime method with exception" duration="0"/>
<testCase name="System Status Controller test getResourceUsage method" duration="1"/>
<testCase name="System Status Controller test getResourceUsage method" duration="0"/>
<testCase name="System Status Controller test getResourceUsage method with exception" duration="0"/>
<testCase name="System Status Controller test getProcessInfo method" duration="0"/>
<testCase name="System Status Controller test getProcessInfo method" duration="1"/>
<testCase name="System Status Controller test getProcessInfo method with exception" duration="0"/>
</file>
<file path="/Users/santosh/Documents/workspace/github/node-boilerplate/tests/integration-tests/app.integration.spec.ts">
<testCase name="status integration tests can get default route success" duration="15"/>
<testCase name="status integration tests can get default web route success" duration="2"/>
</file>
<file path="/Users/santosh/Documents/workspace/github/node-boilerplate/tests/integration-tests/status.integration.spec.ts">
<testCase name="status integration tests can get server time" duration="15"/>
<testCase name="status integration tests can get server time" duration="16"/>
<testCase name="status integration tests can get server system info" duration="5"/>
<testCase name="status integration tests can get server system usage" duration="3"/>
<testCase name="status integration tests can get server system process info" duration="2"/>
<testCase name="status integration tests should get the error" duration="7"/>
</file>
<file path="/Users/santosh/Documents/workspace/github/node-boilerplate/tests/integration-tests/app.integration.spec.ts">
<testCase name="status integration tests can get default route success" duration="15"/>
<testCase name="status integration tests can get default web route success" duration="2"/>
</file>
</testExecutions>
2 changes: 1 addition & 1 deletion tests/helpers/Integration-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import logger from '../../src/lib/logger';

export default class IntegrationHelpers {

public static appInstance: express.Application;
private static appInstance: express.Application;

public static async getApp(): Promise<express.Application> {
if (this.appInstance) {
Expand Down
17 changes: 11 additions & 6 deletions tests/integration-tests/app.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
StatusCodes,
} from 'http-status-codes';
import IntegrationHelpers from '../helpers/Integration-helpers';
import { log } from 'console';

describe('status integration tests', () => {
let app: express.Application;
Expand All @@ -15,18 +16,22 @@ describe('status integration tests', () => {


it('can get default route success', async () => {
await request(app)
const response = await request(app)
.get('/')
.set('Accept', 'application/json')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(StatusCodes.OK);
.expect('Content-Type', 'application/json; charset=utf-8');

const { status } = response;
expect(status).toBe(StatusCodes.OK);
});

it('can get default web route success', async () => {
await request(app)
const response = await request(app)
.get('/web')
.set('Accept', 'application/json')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(StatusCodes.OK);
.expect('Content-Type', 'application/json; charset=utf-8');

const { status } = response;
expect(status).toBe(StatusCodes.OK);
});
});
43 changes: 25 additions & 18 deletions tests/integration-tests/status.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,58 @@ import IntegrationHelpers from '../helpers/Integration-helpers';
describe('status integration tests', () => {
let app: express.Application;
const contentType: string = process.env.APPLY_ENCRYPTION && process.env.SECRET_KEY ? 'text/html; charset=utf-8' : 'application/json; charset=utf-8';
let basePath : string = '/v1/system';
let basePath: string = '/v1/system';

beforeAll(async() => {
beforeAll(async () => {
app = await IntegrationHelpers.getApp();
});


it('can get server time', async () => {
await request(app)
const response = await request(app)
.get(`${basePath}/time`)
.set('Accept', 'application/json')
.expect('Content-Type', contentType)
.expect(StatusCodes.OK);
.expect('Content-Type', contentType);

const { status } = response;
expect(status).toBe(StatusCodes.OK);
});

it('can get server system info', async () => {
await request(app)
const response = await request(app)
.get(`${basePath}/info`)
.set('Accept', 'application/json')
.expect('Content-Type', contentType)
.expect(StatusCodes.OK);
.expect('Content-Type', contentType);

const { status } = response;
expect(status).toBe(StatusCodes.OK);
});

it('can get server system usage', async () => {
await request(app)
const response = await request(app)
.get(`${basePath}/usage`)
.set('Accept', 'application/json')
.expect('Content-Type', contentType)
.expect(StatusCodes.OK);
.expect('Content-Type', contentType);

const { status } = response;
expect(status).toBe(StatusCodes.OK);
});

it('can get server system process info', async () => {
await request(app)
const response = await request(app)
.get(`${basePath}/process`)
.set('Accept', 'application/json')
.expect('Content-Type', contentType)
.expect(StatusCodes.OK);
.expect('Content-Type', contentType);
const { status } = response;
expect(status).toBe(StatusCodes.OK);
});

it('should get the error', async () => {
await request(app)
const response = await request(app)
.get(`${basePath}/error`)
.set('Accept', 'application/json')
.expect('Content-Type', contentType)
.expect(StatusCodes.BAD_REQUEST);
.expect('Content-Type', contentType);
const { status } = response;
expect(status).toBe(StatusCodes.BAD_REQUEST);
});

});