initial
This commit is contained in:
35
apps/frontend/src/app/core/auth.service.spec.ts
Normal file
35
apps/frontend/src/app/core/auth.service.spec.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user