Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
GSinseswa721 committed Jun 3, 2024
1 parent 5346a98 commit cbeeb31
Show file tree
Hide file tree
Showing 41 changed files with 1,360 additions and 141 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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ env:
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:
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"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
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 cbeeb31

Please sign in to comment.