mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 01:40:15 +01:00
📬 refactor: Normalize Email Handling in User Methods (#10743)
- Updated the `findUser` method to normalize email fields to lowercase and trimmed whitespace for case-insensitive matching. - Enhanced the `normalizeEmailInCriteria` function to handle email normalization in search criteria, including `` conditions. - Added tests to ensure email normalization works correctly across various scenarios, including case differences and whitespace handling.
This commit is contained in:
parent
d7ce19e15a
commit
d5d362e52b
7 changed files with 847 additions and 4 deletions
|
|
@ -394,6 +394,34 @@ describe('findOpenIDUser', () => {
|
|||
expect(mockFindUser).toHaveBeenCalledWith({ email: 'user@example.com' });
|
||||
});
|
||||
|
||||
it('should pass email to findUser for case-insensitive lookup (findUser handles normalization)', async () => {
|
||||
const mockUser: IUser = {
|
||||
_id: 'user123',
|
||||
provider: 'openid',
|
||||
openidId: 'openid_456',
|
||||
email: 'user@example.com',
|
||||
username: 'testuser',
|
||||
} as IUser;
|
||||
|
||||
mockFindUser
|
||||
.mockResolvedValueOnce(null) // Primary condition fails
|
||||
.mockResolvedValueOnce(mockUser); // Email search succeeds
|
||||
|
||||
const result = await findOpenIDUser({
|
||||
openidId: 'openid_123',
|
||||
findUser: mockFindUser,
|
||||
email: 'User@Example.COM',
|
||||
});
|
||||
|
||||
/** Email is passed as-is; findUser implementation handles normalization */
|
||||
expect(mockFindUser).toHaveBeenNthCalledWith(2, { email: 'User@Example.COM' });
|
||||
expect(result).toEqual({
|
||||
user: mockUser,
|
||||
error: null,
|
||||
migration: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle findUser throwing an error', async () => {
|
||||
mockFindUser.mockRejectedValueOnce(new Error('Database error'));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue