-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5346a98
commit cbeeb31
Showing
41 changed files
with
1,360 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
npm-debug.log | ||
Dockerfile | ||
docker-compose.yml | ||
.dockerignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
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()); | ||
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()); | ||
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()); | ||
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()); | ||
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()); | ||
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()); | ||
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()); | ||
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()); | ||
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()); | ||
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(); | ||
}); | ||
}); |
Oops, something went wrong.