-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Password Reset Feature (#100)
Co-authored-by: Anjula Shanaka <[email protected]>
- Loading branch information
1 parent
627e646
commit c22e10c
Showing
10 changed files
with
460 additions
and
6 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
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ app.use( | |
credentials: true | ||
}) | ||
) | ||
|
||
app.get('/', (req, res) => { | ||
res.send('ScholarX Backend') | ||
}) | ||
|
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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import { registerUser, loginUser } from './auth.service' | ||
import { | ||
registerUser, | ||
loginUser, | ||
resetPassword, | ||
generateResetToken | ||
} from './auth.service' | ||
import { dataSource } from '../configs/dbConfig' | ||
|
||
jest.mock('bcrypt', () => ({ | ||
|
@@ -159,3 +164,28 @@ describe('loginUser', () => { | |
expect(result.user).toBeUndefined() | ||
}) | ||
}) | ||
|
||
describe('Auth Service', () => { | ||
const validEmail = '[email protected]' | ||
const invalidEmail = '[email protected]' | ||
const newPassword = 'newpassword123' | ||
|
||
const token = generateResetToken(validEmail) | ||
|
||
it('should generate a password reset token', async () => { | ||
expect(token).toBeDefined() | ||
}) | ||
|
||
it('should not generate a password reset token for invalid email', async () => { | ||
const result = await generateResetToken(invalidEmail) | ||
|
||
expect(result.statusCode).toBe(500) | ||
}) | ||
|
||
it('should return error when parameters are missing', async () => { | ||
const result = await resetPassword('', newPassword) | ||
|
||
expect(result.statusCode).toBe(400) | ||
expect(result.message).toBe('Missing parameters') | ||
}) | ||
}) |
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
Oops, something went wrong.