-
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
Victor
committed
Aug 4, 2022
1 parent
fce1ce2
commit 0e5099c
Showing
7 changed files
with
3,533 additions
and
706 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,10 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/**/*.test.ts'], | ||
verbose: true, | ||
clearMocks: true, | ||
resetMocks: true, | ||
resetModules: true, | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,62 @@ | ||
import mongoose from 'mongoose'; | ||
import request from 'supertest'; | ||
|
||
import app from '../src/app'; | ||
import * as authService from '../src/user/services/authService'; | ||
|
||
const userId = new mongoose.Types.ObjectId().toString(); | ||
const userPayload = { | ||
_id: userId, | ||
name: 'John Doe', | ||
email: 'john@example.com', | ||
role: 'user', | ||
}; | ||
|
||
const userInput = { | ||
name: 'John Doe', | ||
email: 'john@examples.com', | ||
password: '123456', | ||
}; | ||
|
||
describe('User Test', () => { | ||
// user registration | ||
|
||
describe('user registration', () => { | ||
describe('given the email and password are valid', () => { | ||
it('should return a status code of 201 with message', async () => { | ||
const createUserServiceMock = jest | ||
.spyOn(authService, 'signup') | ||
// @ts-ignore | ||
.mockReturnValueOnce(userPayload); | ||
|
||
const { statusCode, body } = await request(app) | ||
.post('/api/v1/user/signup') | ||
.send(userInput); | ||
|
||
expect(statusCode).toBe(201); | ||
expect(body.message).toEqual('User signup successful'); | ||
// expect(createUserServiceMock).toHaveBeenCalledWith(userInput); | ||
}); | ||
}); | ||
|
||
describe('given the user service throws an error', () => { | ||
it('should handle the error on signup', async () => { | ||
const createUserServiceMock = jest | ||
.spyOn(authService, 'signup') | ||
// @ts-ignore | ||
.mockReturnValueOnce(userPayload); | ||
|
||
const { statusCode, body } = await request(app).post( | ||
'/api/v1/user/signup' | ||
); | ||
|
||
expect(statusCode).toBe(201); | ||
// expect(body.message).toEqual('User signup successful'); | ||
}); | ||
}); | ||
}); | ||
// the email and password gets validation | ||
// verify that the handler handles any errors | ||
|
||
// Create a user session | ||
}); |