test(users): update unit tests for GDPR consent and export functionality

This commit is contained in:
Mathis HERRIOT 2025-05-17 00:12:23 +02:00
parent ea6684b7fa
commit 818a92f18c
No known key found for this signature in database
GPG Key ID: E7EB4A211D8D4907

View File

@ -212,24 +212,27 @@ describe('UsersService', () => {
describe('updateGdprConsent', () => {
it('should update GDPR consent timestamp', async () => {
const id = 'user1';
// Mock the update method
jest.spyOn(service, 'update').mockResolvedValueOnce(mockUser);
const result = await service.updateGdprConsent(id);
expect(service.update).toHaveBeenCalledWith(id, { gdprTimestamp: expect.any(Date) });
expect(result).toEqual(mockUser);
expect(result).toEqual({
...mockUser,
gdprConsentDate: mockUser.gdprTimestamp
});
});
});
describe('exportUserData', () => {
it('should export user data', async () => {
const id = 'user1';
// Mock the findById method
jest.spyOn(service, 'findById').mockResolvedValueOnce(mockUser);
// Mock the database query for projects
mockDb.select.mockImplementationOnce(() => mockDbOperations);
mockDbOperations.from.mockImplementationOnce(() => mockDbOperations);
@ -244,7 +247,9 @@ describe('UsersService', () => {
expect(result).toEqual({
user: mockUser,
projects: [mockProject],
groups: [],
persons: []
});
});
});
});
});