fix(core): Fix user telemetry bugs (#10293)

This commit is contained in:
Iván Ovejero
2024-08-05 13:24:26 +02:00
committed by GitHub
parent 7fb3f62a36
commit 42a0b594d6
4 changed files with 64 additions and 3 deletions

View File

@@ -46,6 +46,7 @@ describe('MeController', () => {
it('should update the user in the DB, and issue a new cookie', async () => {
const user = mock<User>({
id: '123',
email: 'valid@email.com',
password: 'password',
authIdentities: [],
role: 'global:owner',
@@ -53,6 +54,7 @@ describe('MeController', () => {
const reqBody = { email: 'valid@email.com', firstName: 'John', lastName: 'Potato' };
const req = mock<MeRequest.UserUpdate>({ user, body: reqBody, browserId });
const res = mock<Response>();
userRepository.findOneByOrFail.mockResolvedValue(user);
userRepository.findOneOrFail.mockResolvedValue(user);
jest.spyOn(jwt, 'sign').mockImplementation(() => 'signed-token');
userService.toPublic.mockResolvedValue({} as unknown as PublicUser);
@@ -66,7 +68,10 @@ describe('MeController', () => {
]);
expect(userService.update).toHaveBeenCalled();
expect(eventService.emit).toHaveBeenCalledWith('user-updated', {
user,
fieldsChanged: ['firstName', 'lastName'], // email did not change
});
expect(res.cookie).toHaveBeenCalledWith(
AUTH_COOKIE_NAME,
'signed-token',