feat(#22): manage landlord profile from OIDC

This commit is contained in:
nessar committed 2026-08-17 14:18:15 +02:00
1 parent f02e8a9ba5
commit ecacab0b9f
16 files changed
+661 -3

No files matched your search

@@ -0,0 +1,101 @@
import { signal } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { HttpErrorResponse } from '@angular/common/http';
import { of, throwError } from 'rxjs';
import { vi } from 'vitest';
import { LandlordProfileService } from '../../services/landlord-profile.service';
import { SessionService } from '../../services/session.service';
import { ThemeService } from '../../services/theme.service';
import { SettingsPage } from './settings-page';
describe('SettingsPage', () => {
const profile = {
getProfile: vi.fn(),
updateProfile: vi.fn(),
};
const session = {
username: signal('Camille Martin'),
email: signal('camille@example.com'),
};
const theme = {
preference: signal('system'),
setPreference: vi.fn(),
};
beforeEach(() => {
vi.clearAllMocks();
profile.getProfile.mockReturnValue(
of({
firstName: 'Camille',
lastName: 'Martin',
email: 'camille@example.com',
phone: '+33600000000',
address: '1 rue de Paris',
}),
);
TestBed.configureTestingModule({
providers: [
{ provide: LandlordProfileService, useValue: profile },
{ provide: SessionService, useValue: session },
{ provide: ThemeService, useValue: theme },
],
});
});
it('prefills the landlord profile from the connected account', async () => {
const fixture = TestBed.createComponent(SettingsPage);
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('input[name=firstName]').value).toBe('Camille');
expect(fixture.nativeElement.querySelector('input[name=email]').value).toBe(
'camille@example.com',
);
expect(fixture.nativeElement.querySelector('input[name=address]').value).toBe('1 rue de Paris');
});
it('shows a useful error instead of saving an incomplete profile', () => {
const fixture = TestBed.createComponent(SettingsPage);
fixture.detectChanges();
const component = fixture.componentInstance;
component.phone.set('');
component.save();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toContain(
'Veuillez renseigner tous les champs obligatoires.',
);
expect(profile.updateProfile).not.toHaveBeenCalled();
});
it('keeps the entered values and explains a rejected profile save', async () => {
profile.updateProfile.mockReturnValue(
throwError(
() =>
new HttpErrorResponse({
error: { message: 'Cette adresse e-mail est déjà utilisée.' },
status: 409,
}),
),
);
const fixture = TestBed.createComponent(SettingsPage);
fixture.detectChanges();
const component = fixture.componentInstance;
component.email.set('alex@example.com');
component.save();
fixture.detectChanges();
await fixture.whenStable();
expect(profile.updateProfile).toHaveBeenCalledWith({
firstName: 'Camille',
lastName: 'Martin',
email: 'alex@example.com',
phone: '+33600000000',
address: '1 rue de Paris',
});
expect(fixture.nativeElement.textContent).toContain('Cette adresse e-mail est déjà utilisée.');
expect(fixture.nativeElement.querySelector('input[name=email]').value).toBe('alex@example.com');
});
});