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

Test coverage increase #104

Closed
wants to merge 19 commits into from
Closed
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
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ env:
GOOGLE_CLIENT_ID: ${{secrets.GOOGLE_CLIENT_ID}}
GOOGLE_CLIENT_SECRET: ${{secrets.GOOGLE_CLIENT_SECRET}}

TEST_USER_EMAIL: ${{secrets.TEST_USER_EMAIL}}
TEST_USER_PASS: ${{secrets.TEST_USER_PASS}}
TEST_VENDOR_EMAIL: ${{secrets.TEST_VENDOR_EMAIL}}
TEST_VENDOR1_EMAIL: ${{secrets.TEST_VENDOR1_EMAIL}}
TEST_BUYER_EMAIL: ${{secrets.TEST_BUYER_EMAIL}}
TEST_SAMPLE_BUYER_EMAIL: ${{secrets.TEST_SAMPLE_BUYER_EMAIL}}
TEST_VENDOR2_EMAIL: ${{secrets.TEST_VENDOR2_EMAIL}}

STRIPE_SECRET_KEY: ${{secrets.STRIPE_SECRET_KEYT}}

jobs:
Expand Down Expand Up @@ -48,4 +56,4 @@ jobs:
- name: Upload coverage report to Coveralls
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ package-lock.json
coverage/
dist
/src/logs
.DS_Store
.DS_Store

src/controllers/notificationControllers.ts
src/entities/Notification.ts
src/entities/NotificationItem.ts
src/routes/NoficationRoutes.ts
src/services/notificationServices/deleteNotification.ts
src/services/notificationServices/getNotifications.ts
src/services/notificationServices/updateNotification.ts
src/utils/getNotifications.ts
src/utils/sendNotification.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"mailgen": "^2.0.28",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"node-nlp": "^4.27.0",
"node-nlp": "^3.10.2",
"nodemailer": "^6.9.13",
"nodemon": "^3.1.0",
"passport": "^0.7.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

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

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

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

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

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

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

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

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

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

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