- Redesign the Identity module with a richer domain model. - Extend the User entity to support username, Authentik integration, activity tracking, and storage information. - Add Role and Permission domain models with many-to-many relationships. - Implement RBAC foundation using UserRole, RolePermission, and UserPermission mappings. - Add user storage quota and usage fields with default values. - Introduce Authentik identifiers and synchronization metadata. - Refactor user domain logic for role and permission management. - Update Prisma schema to support the new identity architecture. - Improve JWT authentication and permission guard integration. - Update repositories, handlers, controllers, mappers, DTOs, and Swagger configuration. - Refresh environment configuration and project dependencies.
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { UserService } from '../../src/modules/identity/application/services/user.service';
|
|
import { PrismaService } from '../../src/shared/prisma.service';
|
|
import { IUser } from '../../src/modules/identity/domain/repositories/user.interface';
|
|
|
|
describe('UserService', () => {
|
|
let service: UserService;
|
|
let prisma: Partial<PrismaService>;
|
|
let userRepo: Partial<IUser>;
|
|
|
|
beforeEach(async () => {
|
|
prisma = {
|
|
user: {
|
|
update: jest.fn().mockResolvedValue(null),
|
|
findMany: jest.fn().mockResolvedValue([]),
|
|
},
|
|
} as any;
|
|
|
|
userRepo = {
|
|
create: jest.fn().mockImplementation(async (user) => {
|
|
return { ...user, id: 'user-1' };
|
|
}),
|
|
getById: jest.fn().mockResolvedValue({ id: 'user-1', username: 'u', email: 'e' }),
|
|
existByEmail: jest.fn().mockResolvedValue(false),
|
|
} as any;
|
|
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [
|
|
UserService,
|
|
{ provide: PrismaService, useValue: prisma },
|
|
{ provide: IUser, useValue: userRepo },
|
|
],
|
|
}).compile();
|
|
|
|
service = module.get<UserService>(UserService);
|
|
});
|
|
|
|
it('createUser - provisioning disabled', async () => {
|
|
await expect(service.createUser({ username: 'u', email: 'e' })).rejects.toThrow();
|
|
});
|
|
});
|