refactor(core): Decouple user events from internal hooks (no-changelog) (#10292)

This commit is contained in:
Iván Ovejero
2024-08-05 12:07:42 +02:00
committed by GitHub
parent 88086a41ff
commit c0f3693e8a
15 changed files with 260 additions and 181 deletions

View File

@@ -13,6 +13,7 @@ import { InternalHooks } from '@/InternalHooks';
import { License } from '@/License';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { UserRepository } from '@/databases/repositories/user.repository';
import { EventService } from '@/events/event.service';
import { badPasswords } from '@test/testData';
import { mockInstance } from '@test/mocking';
@@ -20,7 +21,8 @@ const browserId = 'test-browser-id';
describe('MeController', () => {
const externalHooks = mockInstance(ExternalHooks);
const internalHooks = mockInstance(InternalHooks);
mockInstance(InternalHooks);
const eventService = mockInstance(EventService);
const userService = mockInstance(UserService);
const userRepository = mockInstance(UserRepository);
mockInstance(License).isWithinUsersLimit.mockReturnValue(true);
@@ -202,9 +204,9 @@ describe('MeController', () => {
req.user.password,
]);
expect(internalHooks.onUserUpdate).toHaveBeenCalledWith({
expect(eventService.emit).toHaveBeenCalledWith('user-updated', {
user: req.user,
fields_changed: ['password'],
fieldsChanged: ['password'],
});
});
});