- HERENCIA-SIMCO.md actualizado con directivas v3.7 y v3.8 - Actualizaciones de configuracion Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
103 lines
4.3 KiB
JavaScript
103 lines
4.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const testing_1 = require("@nestjs/testing");
|
|
const common_1 = require("@nestjs/common");
|
|
const users_controller_1 = require("../users.controller");
|
|
const users_service_1 = require("../users.service");
|
|
const invitation_service_1 = require("../services/invitation.service");
|
|
describe('UsersController', () => {
|
|
let controller;
|
|
let service;
|
|
let invitationService;
|
|
const mockUser = {
|
|
id: 'user-123',
|
|
tenant_id: 'tenant-123',
|
|
email: 'test@example.com',
|
|
first_name: 'John',
|
|
last_name: 'Doe',
|
|
status: 'active',
|
|
};
|
|
const mockRequestUser = {
|
|
id: 'user-123',
|
|
sub: 'user-123',
|
|
tenant_id: 'tenant-123',
|
|
email: 'test@example.com',
|
|
role: 'admin',
|
|
};
|
|
beforeEach(async () => {
|
|
const module = await testing_1.Test.createTestingModule({
|
|
controllers: [users_controller_1.UsersController],
|
|
providers: [
|
|
{
|
|
provide: users_service_1.UsersService,
|
|
useValue: {
|
|
findAllByTenant: jest.fn(),
|
|
findOne: jest.fn(),
|
|
update: jest.fn(),
|
|
},
|
|
},
|
|
{
|
|
provide: invitation_service_1.InvitationService,
|
|
useValue: {
|
|
invite: jest.fn(),
|
|
findAllByTenant: jest.fn(),
|
|
resend: jest.fn(),
|
|
cancel: jest.fn(),
|
|
},
|
|
},
|
|
],
|
|
}).compile();
|
|
controller = module.get(users_controller_1.UsersController);
|
|
service = module.get(users_service_1.UsersService);
|
|
invitationService = module.get(invitation_service_1.InvitationService);
|
|
});
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
describe('findAll', () => {
|
|
it('should return paginated users', async () => {
|
|
const result = {
|
|
data: [mockUser],
|
|
total: 1,
|
|
page: 1,
|
|
limit: 10,
|
|
};
|
|
service.findAllByTenant.mockResolvedValue(result);
|
|
const response = await controller.findAll(mockRequestUser, 1, 10);
|
|
expect(response).toEqual(result);
|
|
expect(service.findAllByTenant).toHaveBeenCalledWith('tenant-123', 1, 10);
|
|
});
|
|
it('should use default pagination values', async () => {
|
|
service.findAllByTenant.mockResolvedValue({ data: [], total: 0, page: 1, limit: 10 });
|
|
await controller.findAll(mockRequestUser);
|
|
expect(service.findAllByTenant).toHaveBeenCalledWith('tenant-123', 1, 10);
|
|
});
|
|
});
|
|
describe('findOne', () => {
|
|
it('should return a user by id', async () => {
|
|
service.findOne.mockResolvedValue(mockUser);
|
|
const result = await controller.findOne('user-123', mockRequestUser);
|
|
expect(result).toEqual(mockUser);
|
|
expect(service.findOne).toHaveBeenCalledWith('user-123', 'tenant-123');
|
|
});
|
|
it('should propagate NotFoundException', async () => {
|
|
service.findOne.mockRejectedValue(new common_1.NotFoundException('Usuario no encontrado'));
|
|
await expect(controller.findOne('non-existent', mockRequestUser)).rejects.toThrow(common_1.NotFoundException);
|
|
});
|
|
});
|
|
describe('update', () => {
|
|
it('should update a user', async () => {
|
|
const updateDto = { first_name: 'Jane' };
|
|
const updatedUser = { ...mockUser, first_name: 'Jane' };
|
|
service.update.mockResolvedValue(updatedUser);
|
|
const result = await controller.update('user-123', updateDto, mockRequestUser);
|
|
expect(result).toEqual(updatedUser);
|
|
expect(service.update).toHaveBeenCalledWith('user-123', updateDto, 'tenant-123');
|
|
});
|
|
it('should propagate NotFoundException', async () => {
|
|
service.update.mockRejectedValue(new common_1.NotFoundException('Usuario no encontrado'));
|
|
await expect(controller.update('non-existent', {}, mockRequestUser)).rejects.toThrow(common_1.NotFoundException);
|
|
});
|
|
});
|
|
});
|
|
//# sourceMappingURL=users.controller.spec.js.map
|