mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-09 17:31:19 +00:00
🛂 fix: Normalize Verification Flow Error Responses (#13558)
* fix: normalize verification flow responses * fix: keep verification responses consistent
This commit is contained in:
parent
75bbefb1c8
commit
8c71dbcb32
4 changed files with 184 additions and 14 deletions
|
|
@ -388,7 +388,7 @@ const verifyEmailController = async (req, res) => {
|
|||
try {
|
||||
const verifyEmailService = await verifyEmail(req);
|
||||
if (verifyEmailService instanceof Error) {
|
||||
return res.status(400).json(verifyEmailService);
|
||||
return res.status(400).json({ message: verifyEmailService.message });
|
||||
} else {
|
||||
return res.status(200).json(verifyEmailService);
|
||||
}
|
||||
|
|
@ -402,9 +402,9 @@ const resendVerificationController = async (req, res) => {
|
|||
try {
|
||||
const result = await resendVerificationEmail(req);
|
||||
if (result instanceof Error) {
|
||||
return res.status(400).json(result);
|
||||
return res.status(400).json({ message: result.message });
|
||||
} else {
|
||||
return res.status(200).json(result);
|
||||
return res.status(result.status ?? 200).json({ message: result.message });
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('[verifyEmailController]', e);
|
||||
|
|
|
|||
|
|
@ -108,9 +108,49 @@ afterEach(async () => {
|
|||
}
|
||||
});
|
||||
|
||||
const { deleteUserController, getUserController } = require('./UserController');
|
||||
const {
|
||||
deleteUserController,
|
||||
getUserController,
|
||||
resendVerificationController,
|
||||
verifyEmailController,
|
||||
} = require('./UserController');
|
||||
const { Group } = require('~/db/models');
|
||||
const { deleteConvos } = require('~/models');
|
||||
const { verifyEmail, resendVerificationEmail } = require('~/server/services/AuthService');
|
||||
|
||||
describe('verifyEmailController', () => {
|
||||
const mockRes = {
|
||||
status: jest.fn().mockReturnThis(),
|
||||
json: jest.fn().mockReturnThis(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('returns the generic verification error message from service failures', async () => {
|
||||
verifyEmail.mockResolvedValue(new Error('Invalid or expired email verification token'));
|
||||
|
||||
await verifyEmailController(
|
||||
{ body: { email: 'user%40example.com', token: 'not-the-token' } },
|
||||
mockRes,
|
||||
);
|
||||
|
||||
expect(mockRes.status).toHaveBeenCalledWith(400);
|
||||
expect(mockRes.json).toHaveBeenCalledWith({
|
||||
message: 'Invalid or expired email verification token',
|
||||
});
|
||||
});
|
||||
|
||||
it('uses the service status for resend verification responses', async () => {
|
||||
resendVerificationEmail.mockResolvedValue({ status: 500, message: 'Something went wrong.' });
|
||||
|
||||
await resendVerificationController({ body: { email: 'user@example.com' } }, mockRes);
|
||||
|
||||
expect(mockRes.status).toHaveBeenCalledWith(500);
|
||||
expect(mockRes.json).toHaveBeenCalledWith({ message: 'Something went wrong.' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('getUserController', () => {
|
||||
const mockRes = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue