feat: add unit tests for tenant, guarantor, lease card, dashboard, session, theme, and workspace services

This commit is contained in:
nessar committed 2026-08-17 14:18:15 +02:00
1 parent 74a77f2d2b
commit 181410e28f
8 files changed
+514 -2

No files matched your search

@@ -0,0 +1,39 @@
import { HttpClient } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs';
import { vi } from 'vitest';
import { SessionService } from './session.service';
describe('SessionService', () => {
const http = { get: vi.fn() };
beforeEach(() => {
vi.clearAllMocks();
TestBed.configureTestingModule({ providers: [SessionService, { provide: HttpClient, useValue: http }] });
});
it('stores an authenticated user and applies its defaults', () => {
const service = TestBed.inject(SessionService);
http.get.mockReturnValueOnce(of({ authenticated: true, username: 'Camille', email: 'camille@example.com' }));
service.refresh();
expect(service.username()).toBe('Camille');
expect(service.email()).toBe('camille@example.com');
http.get.mockReturnValueOnce(of({ authenticated: true }));
service.refresh();
expect(service.username()).toBe('User');
expect(service.email()).toBe('');
});
it('clears the session for an anonymous or failed request', () => {
const service = TestBed.inject(SessionService);
http.get.mockReturnValueOnce(of({ authenticated: false }));
service.refresh();
expect(service.isLoggedIn()).toBe(false);
http.get.mockReturnValueOnce(throwError(() => new Error('offline')));
service.refresh();
expect(http.get).toHaveBeenCalledWith('/api/user');
expect(service.username()).toBe('');
});
});