Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
increasing test coverage

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

adding documentation and tests

writing tests

test coverage

ft<discount-coupon> adding discount coupon feature

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

adding documentation and tests

writing tests

Feat-Buyer-coupon-discount-management

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

adding documentation and tests

writing tests

implementing stripe payment system

implementing stripe payment system

test coverage

feat(docker): implement Docker for project

- Include Docker file to build image for project and containerize the project
- Configure Docker compose for easy setup

Implement buyer able to leave feedback on products

ft<discount-coupon> adding discount coupon feature

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

adding documentation and tests

writing tests

Feat-Buyer-coupon-discount-management

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

implementing order tracking and order managment issue

adding documentation and tests

writing tests

implementing stripe payment system

implementing stripe payment system

Implement buyer able to leave feedback on products

Implement buyer able to leave feedback on products
  • Loading branch information
UwicyezaG authored and Ndevu12 committed Jun 2, 2024
1 parent 66c5d2c commit a216bf8
Show file tree
Hide file tree
Showing 90 changed files with 3,598 additions and 1,087 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
npm-debug.log
Dockerfile
docker-compose.yml
.dockerignore
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ env:
CLOUDINARY_API_SECRET: ${{secrets.CLOUDINARY_API_SECRET}}
GOOGLE_CLIENT_ID: ${{secrets.GOOGLE_CLIENT_ID}}
GOOGLE_CLIENT_SECRET: ${{secrets.GOOGLE_CLIENT_SECRET}}


STRIPE_SECRET_KEY: ${{secrets.STRIPE_SECRET_KEYT}}

jobs:
build-lint-test-coverage:
runs-on: ubuntu-latest
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine

WORKDIR /app

COPY package.json .

RUN npm install

COPY . .

EXPOSE $PORT

CMD ["npm", "run", "dev"]
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ logger.debug('This is a debug message');
npm test
```

### Setting up docker and using it

- Download and install docker
```
https://www.docker.com/products/docker-desktop/
```
- Download Subsystem for Linux for none linux users
- Set environment varibles like database host to postgresdb

- Building the image, you must navigate to the project directory in the terminal, then run
```
docker-compose up --build
```
- Stoping docker-compose container, run
```
docker-compose down
```

## Authors

- [Maxime Mizero](https://github.com/maxCastro1)
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

services:
postgresdb:
image: postgres
environment:
POSTGRES_USER: $DEV_DB_USER
POSTGRES_PASSWORD: $DEV_DB_PASS
POSTGRES_DB: $DEV_DB_NAME
volumes:
- knights-data:/var/lib/postgresql/data

node-app:
build: .
volumes:
- .:/app
- /app/node_modules
image: knights-app:1.0
env_file:
- ./.env
ports:
- $PORT:$PORT
depends_on:
- postgresdb

volumes:
knights-data:
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
"passport-google-oauth20": "^2.0.0",
"pg": "^8.11.5",
"reflect-metadata": "^0.2.2",
"socket.io": "^4.7.5",
"source-map-support": "^0.5.21",
"stripe": "^15.8.0",
"superagent": "^9.0.1",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0",
Expand Down Expand Up @@ -78,6 +80,7 @@
"@types/nodemailer": "^6.4.15",
"@types/passport-google-oauth20": "^2.0.16",
"@types/reflect-metadata": "^0.1.0",
"@types/socket.io": "^3.0.2",
"@types/supertest": "^6.0.2",
"@types/uuid": "^9.0.8",
"@types/winston": "^2.4.4",
Expand Down
154 changes: 154 additions & 0 deletions src/__test__/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import request from 'supertest';
import express, { Request, Response } from 'express';
import {
userVerificationService,
userRegistrationService,
userLoginService,
userEnableTwoFactorAuth,
userDisableTwoFactorAuth,
userValidateOTP,
userResendOtpService,
logoutService,
} from '../services';
import { userPasswordResetService } from '../services/userServices/userPasswordResetService';
import { sendPasswordResetLinkService } from '../services/userServices/sendResetPasswordLinkService';
import { activateUserService } from '../services/updateUserStatus/activateUserService';
import { deactivateUserService } from '../services/updateUserStatus/deactivateUserService';
import { userProfileUpdateServices } from '../services/userServices/userProfileUpdateServices';
import { activateUser, disable2FA, disactivateUser, enable2FA, login, logout, resendOTP, sampleAPI, sendPasswordResetLink, userPasswordReset, userProfileUpdate, userRegistration, userVerification, verifyOTP } from '../controllers';

// Mock the services
jest.mock('../services', () => ({
userVerificationService: jest.fn(),
userRegistrationService: jest.fn(),
userLoginService: jest.fn(),
userEnableTwoFactorAuth: jest.fn(),
userDisableTwoFactorAuth: jest.fn(),
userValidateOTP: jest.fn(),
userResendOtpService: jest.fn(),
logoutService: jest.fn(),
}));

jest.mock('../services/userServices/userPasswordResetService', () => ({
userPasswordResetService: jest.fn(),
}));

jest.mock('../services/userServices/sendResetPasswordLinkService', () => ({
sendPasswordResetLinkService: jest.fn(),
}));

jest.mock('../services/updateUserStatus/activateUserService', () => ({
activateUserService: jest.fn(),
}));

jest.mock('../services/updateUserStatus/deactivateUserService', () => ({
deactivateUserService: jest.fn(),
}));

jest.mock('../services/userServices/userProfileUpdateServices', () => ({
userProfileUpdateServices: jest.fn(),
}));

const app = express();
app.use(express.json());

app.post('/register', userRegistration);
app.post('/verify', userVerification);
app.post('/login', login);
app.post('/enable-2fa', enable2FA);
app.post('/disable-2fa', disable2FA);
app.post('/verify-otp', verifyOTP);
app.post('/resend-otp', resendOTP);
app.get('/sample', sampleAPI);
app.post('/reset-password', userPasswordReset);
app.post('/send-reset-link', sendPasswordResetLink);
app.post('/activate', activateUser);
app.post('/deactivate', disactivateUser);
app.post('/logout', logout);
app.put('/update-profile', userProfileUpdate);

describe('User Controller', () => {
it('should call userRegistrationService on /register', async () => {
(userRegistrationService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(201).send());

Check warning on line 72 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/register').send({});
expect(userRegistrationService).toHaveBeenCalled();
});

it('should call userVerificationService on /verify', async () => {
(userVerificationService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 78 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/verify').send({});
expect(userVerificationService).toHaveBeenCalled();
});

it('should call userLoginService on /login', async () => {
(userLoginService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 84 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/login').send({});
expect(userLoginService).toHaveBeenCalled();
});

it('should call userEnableTwoFactorAuth on /enable-2fa', async () => {
(userEnableTwoFactorAuth as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 90 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/enable-2fa').send({});
expect(userEnableTwoFactorAuth).toHaveBeenCalled();
});

it('should call userDisableTwoFactorAuth on /disable-2fa', async () => {
(userDisableTwoFactorAuth as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 96 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/disable-2fa').send({});
expect(userDisableTwoFactorAuth).toHaveBeenCalled();
});

it('should call userValidateOTP on /verify-otp', async () => {
(userValidateOTP as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 102 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/verify-otp').send({});
expect(userValidateOTP).toHaveBeenCalled();
});

it('should call userResendOtpService on /resend-otp', async () => {
(userResendOtpService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 108 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/resend-otp').send({});
expect(userResendOtpService).toHaveBeenCalled();
});

it('should return 200 on /sample', async () => {
const response = await request(app).get('/sample');
expect(response.status).toBe(200);
expect(response.body).toEqual({ message: 'Token is valid' });
});

it('should call userPasswordResetService on /reset-password', async () => {
(userPasswordResetService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 120 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/reset-password').send({});
expect(userPasswordResetService).toHaveBeenCalled();
});

it('should call sendPasswordResetLinkService on /send-reset-link', async () => {
(sendPasswordResetLinkService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 126 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/send-reset-link').send({});
expect(sendPasswordResetLinkService).toHaveBeenCalled();
});

it('should call activateUserService on /activate', async () => {
(activateUserService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());

Check warning on line 132 in src/__test__/auth.test.ts

View workflow job for this annotation

GitHub Actions / build-lint-test-coverage

'req' is defined but never used. Allowed unused args must match /^_/u
await request(app).post('/activate').send({});
expect(activateUserService).toHaveBeenCalled();
});

it('should call deactivateUserService on /deactivate', async () => {
(deactivateUserService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());
await request(app).post('/deactivate').send({});
expect(deactivateUserService).toHaveBeenCalled();
});

it('should call logoutService on /logout', async () => {
(logoutService as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());
await request(app).post('/logout').send({});
expect(logoutService).toHaveBeenCalled();
});

it('should call userProfileUpdateServices on /update-profile', async () => {
(userProfileUpdateServices as jest.Mock).mockImplementationOnce((req: Request, res: Response) => res.status(200).send());
await request(app).put('/update-profile').send({});
expect(userProfileUpdateServices).toHaveBeenCalled();
});
});
Loading

0 comments on commit a216bf8

Please sign in to comment.