Files
boilerplate/apps/frontend/src/app/core/auth.service.spec.ts
Bastian Wagner 543e8273a7 initial
2026-07-16 09:49:22 +02:00

36 lines
953 B
TypeScript

import { TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { ApiClientService, type UserDto } from '@boilerplate/api-client';
import { AuthService } from './auth.service';
const user: UserDto = {
id: 'u1',
name: 'Ada',
email: 'ada@example.test',
active: true,
lastLoginAt: null,
settings: { tablePageSize: 20, sidebarExpanded: true },
roles: [
{
id: 'r1',
name: 'user',
protected: true,
permissions: [{ id: 'items.read', description: 'items.read' }],
},
],
};
describe('AuthService', () => {
it('derives permissions from roles for navigation decisions', () => {
TestBed.configureTestingModule({
providers: [{ provide: ApiClientService, useValue: { me: () => of(user) } }],
});
const service = TestBed.inject(AuthService);
service.loadMe();
expect(service.has('items.read')).toBe(true);
expect(service.has('users.manage')).toBe(false);
});
});