Skip to content

Commit

Permalink
Test coverage increse
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahladdie committed Jun 5, 2024
0 parents commit 05dd2b3
Show file tree
Hide file tree
Showing 136 changed files with 11,185 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
PORT = ********************************
APP_ENV = ********************************

TEST_DB_HOST = ********************************
TEST_DB_PORT = ********************************
TEST_DB_USER = ********************************
TEST_DB_PASS = ********************************
TEST_DB_NAME = ********************************

DEV_DB_HOST = ********************************
DEV_DB_PORT = ********************************
DEV_DB_USER = ********************************
DEV_DB_PASS = *****************************
DEV_DB_NAME = *******************************

PDN_DB_HOST = ********************************
PDN_DB_PORT = ********************************
PDN_DB_USER = ********************************
PDN_DB_PASS = ********************************
PDN_DB_NAME = *****************************


APP_EMAIL = ********************************
APP_PASSWORD = ********************************
PINDO_API_KEY = ********************************
PINDO_API_URL = ********************************
PINDO_SENDER = ********************************
JWT_SECRET = ********************************
TWO_FA_MINS = ********************************

HOST = *******************
AUTH_EMAIL = *********************
AUTH_PASSWORD = ******************

CLOUDNARY_API_KEY = **************
CLOUDINARY_CLOUD_NAME = **************
CLOUDINARY_API_SECRET = **************
39 changes: 39 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'no-undef': 'off',
'semi': ['warn', 'always'],
'no-multi-spaces': 'warn',
'no-trailing-spaces': 'warn',
'space-before-function-paren': ['warn', 'always'],
'func-style': ['warn', 'declaration', { allowArrowFunctions: true }],
'camelcase': 'warn',
'@typescript-eslint/explicit-function-return-type': [
'warn',
{ allowExpressions: true },
],
'@typescript-eslint/explicit-member-accessibility': [
'off',
{ accessibility: 'explicit' },
],
'no-unused-vars': 'warn',
'no-extra-semi': 'warn',
},
};
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: knights-ecomm-be CI

on: [push, pull_request]

env:
TEST_DB_HOST: ${{secrets.TEST_DB_HOST}}
TEST_DB_PORT: ${{secrets.TEST_DB_PORT}}
TEST_DB_USER: ${{secrets.TEST_DB_USER}}
TEST_DB_PASS: ${{secrets.TEST_DB_PASS}}
TEST_DB_NAME: ${{secrets.TEST_DB_NAME}}
HOST: ${{secrets.HOST}}
AUTH_EMAIL: ${{secrets.AUTH_EMAIL}}
AUTH_PASSWORD: ${{secrets.AUTH_PASSWORD}}
JWT_SECRET: ${{secrets.JWT_SECRET}}
CLOUDNARY_API_KEY: ${{secrets.CLOUDNARY_API_KEY}}
CLOUDINARY_CLOUD_NAME: ${{secrets.CLOUDINARY_CLOUD_NAME}}
CLOUDINARY_API_SECRET: ${{secrets.CLOUDINARY_API_SECRET}}
GOOGLE_CLIENT_ID: ${{secrets.GOOGLE_CLIENT_ID}}
GOOGLE_CLIENT_SECRET: ${{secrets.GOOGLE_CLIENT_SECRET}}


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 }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.vscode
.env
package-lock.json
coverage/
dist
/src/logs
.DS_Store
21 changes: 21 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"printWidth": 120,
"bracketSpacing": true,
"arrowParens": "avoid",
"proseWrap": "always",
"jsxSingleQuote": true,
"quoteProps": "consistent",
"endOfLine": "auto",
"overrides": [
{
"files": "*.js",
"options": {
"printWidth": 80
}
}
]
}
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# E-commerse Backend API

[![knights-ecomm-be CI](https://github.com/atlp-rwanda/knights-ecomm-be/actions/workflows/ci.yml/badge.svg)](https://github.com/atlp-rwanda/knights-ecomm-be/actions/workflows/ci.yml)
  
[![Coverage Status](https://coveralls.io/repos/github/atlp-rwanda/knights-ecomm-be/badge.svg?branch=develop)](https://coveralls.io/github/atlp-rwanda/knights-ecomm-be?branch=develop)
  
[![Version](https://img.shields.io/badge/version-1.0.0-blue)](https://github.com/your-username/your-repo-name/releases/tag/v1.0.0)

## Description

This repository contains an E-commerce APIs, serving as backend for an E-commerce frontend application, It powers the
functionalities for the frontend, such as storing, retrieving, deleting data and much more.

## Documentation

[List of endpoints exposed by the service](https://knights-ecomm-be-lcdh.onrender.com/api/v1/docs/)

## Setup

- to use loggers in program use below functions

```bash
logger.error('This is an error message');
logger.warn('This is a warning message');
logger.info('This is an informational message');
logger.debug('This is a debug message');

```

### Technologies used

- Languages:
- TypeScript
- Package manager:
- npm
- Stack to use:
- Node.js
- Express.js
- PostgresSQL
- Testing:
- Jest
- Supertest
- API Documentation
- Swagger Documentation

### Getting Started

- Clone this project on your local machine
```
git clone https://github.com/atlp-rwanda/knights-ecomm-be.git
```
- Navigate to project directory
```
cd knights-ecomm-be
```
- Install dependencies
```
npm install
```

### Run The Service

- Run the application
```
npm run dev
```

## Testing

- Run tests
```
npm test
```

## Authors

- [Maxime Mizero](https://github.com/maxCastro1)
- [Elie Kuradusenge](https://github.com/elijahladdie)
- [Byishimo Teto Joseph](https://github.com/MC-Knight)
- [Iragena Aime Divin](https://github.com/aimedivin)
- [Gloria Niyonkuru Sinseswa](https://github.com/GSinseswa721)
- [Grace Uwicyeza](https://github.com/UwicyezaG)
- [Jean Paul Elisa Ndevu](https://github.com/Ndevu12)
- [Gisa Mugisha Caleb Pacifique](https://github.com/Calebgisa72)
19 changes: 19 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/**/*.test.ts'],
verbose: true,
forceExit: true,
clearMocks: true,
testTimeout: 30000,
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
],
};
29 changes: 29 additions & 0 deletions migrations/1714595134552-UserMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateUserMigration1614495123940 implements MigrationInterface {
public async up (queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE "user" (
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"firstName" character varying NOT NULL,
"lastName" character varying NOT NULL,
"email" character varying NOT NULL,
"password" character varying NOT NULL,
"gender" character varying NOT NULL,
"phoneNumber" character varying NOT NULL,
"photoUrl" character varying,
"verified" boolean NOT NULL,
"status" character varying NOT NULL CHECK (status IN ('active', 'suspended')),
"userType" character varying NOT NULL DEFAULT 'Buyer' CHECK (userType IN ('Admin', 'Buyer', 'Vendor')),
"createdAt" TIMESTAMP NOT NULL DEFAULT now(),
"updatedAt" TIMESTAMP NOT NULL DEFAULT now(),
CONSTRAINT "UQ_e12875dfb3b1d92d7d7c5377e22" UNIQUE ("email"),
CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id")
)
`);
}

public async down (queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "user"`);
}
}
39 changes: 39 additions & 0 deletions ormconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const devConfig = {
type: 'postgres',
host: process.env.DEV_DB_HOST,
port: process.env.DEV_DB_PORT,
username: process.env.DEV_DB_USER,
password: process.env.DEV_DB_PASS,
database: process.env.DEV_DB_NAME,
synchronize: true,
logging: false,
entities: ['src/entities/**/*.ts'],
migrations: ['src/migrations/**/*.ts'],
subscribers: ['src/subscribers/**/*.ts'],
cli: {
entitiesDir: 'src/entities',
migrationsDir: 'src/migrations',
subscribersDir: 'src/subscribers',
},
};

const testConfig = {
type: 'postgres',
host: process.env.TEST_DB_HOST,
port: process.env.TEST_DB_PORT,
username: process.env.TEST_DB_USER,
password: process.env.TEST_DB_PASS,
database: process.env.TEST_DB_NAME,
synchronize: true,
logging: false,
entities: ['src/entities/**/*.ts'],
migrations: ['src/migrations/**/*.ts'],
subscribers: ['src/subscribers/**/*.ts'],
cli: {
entitiesDir: 'src/entities',
migrationsDir: 'src/migrations',
subscribersDir: 'src/subscribers',
},
};

module.exports = process.env.NODE_ENV === 'test' ? testConfig : devConfig;
Loading

0 comments on commit 05dd2b3

Please sign in to comment.