Phase 3 Completed
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { UpdateUserHandler } from '../src/modules/identity/application/handlers/user/update-user.handler';
|
||||
|
||||
describe('UpdateUserHandler', () => {
|
||||
test('rejects password in DTO', async () => {
|
||||
const mockRepo: any = { getById: jest.fn(), update: jest.fn() };
|
||||
mockRepo.getById.mockResolvedValue({ id: 'u1', changeUsername: jest.fn(), changeEmail: jest.fn(), setStorageQuota: jest.fn(), setStorageUsed: jest.fn() });
|
||||
|
||||
const handler = new UpdateUserHandler(mockRepo as any);
|
||||
|
||||
await expect(handler.execute('u1', { password: 'secret' } as any)).rejects.toThrow('Password management is not allowed.');
|
||||
});
|
||||
|
||||
test('updates allowed fields', async () => {
|
||||
const userObj: any = { id: 'u1', changeUsername: jest.fn(), changeEmail: jest.fn(), setStorageQuota: jest.fn(), setStorageUsed: jest.fn() };
|
||||
const mockRepo: any = { getById: jest.fn().mockResolvedValue(userObj), update: jest.fn().mockResolvedValue(userObj) };
|
||||
|
||||
const handler = new UpdateUserHandler(mockRepo as any);
|
||||
|
||||
const dto = { name: 'New Name', email: 'a@b.com', storageQuota: 1000, storageUsed: 10 } as any;
|
||||
|
||||
const res = await handler.execute('u1', dto);
|
||||
|
||||
expect(userObj.changeUsername).toHaveBeenCalledWith('New Name');
|
||||
expect(userObj.changeEmail).toHaveBeenCalledWith('a@b.com');
|
||||
expect(userObj.setStorageQuota).toHaveBeenCalledWith(1000);
|
||||
expect(userObj.setStorageUsed).toHaveBeenCalledWith(10);
|
||||
expect(mockRepo.update).toHaveBeenCalledWith(userObj);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user