fix(tests): Align mock objects with entity type definitions

- Changed null to undefined for optional fields in mock objects
- Fixed TierDto field names (from/to instead of min/max)
- Fixed type casts using 'as any' for mocks with undefined values
- Resolved all TypeScript build errors in test files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Adrian Flores Cortes 2026-01-30 16:04:31 -06:00
parent d72bc4da04
commit ee7ed19e4a
7 changed files with 44 additions and 44 deletions

View File

@ -30,7 +30,7 @@ describe('AssignmentsService', () => {
type: SchemeType.PERCENTAGE,
rate: 10,
isActive: true,
deletedAt: null,
deletedAt: undefined,
...overrides,
});
@ -40,8 +40,8 @@ describe('AssignmentsService', () => {
userId: mockTargetUserId,
schemeId: mockSchemeId,
startsAt: new Date('2026-01-01'),
endsAt: null,
customRate: null,
endsAt: undefined,
customRate: undefined,
isActive: true,
createdAt: new Date(),
createdBy: mockUserId,
@ -425,11 +425,11 @@ describe('AssignmentsService', () => {
const futureAssignment = {
...createMockAssignment(),
startsAt: new Date(now.getTime() + 86400000), // tomorrow
endsAt: null,
endsAt: undefined,
isActive: true,
};
assignmentRepo.find.mockResolvedValue([futureAssignment as CommissionAssignmentEntity]);
assignmentRepo.find.mockResolvedValue([futureAssignment as any]);
const result = await service.findActiveForUser(mockTenantId, mockTargetUserId);
@ -457,11 +457,11 @@ describe('AssignmentsService', () => {
const openEndedAssignment = {
...createMockAssignment(),
startsAt: new Date(now.getTime() - 86400000), // yesterday
endsAt: null,
endsAt: undefined,
isActive: true,
};
assignmentRepo.find.mockResolvedValue([openEndedAssignment as CommissionAssignmentEntity]);
assignmentRepo.find.mockResolvedValue([openEndedAssignment as any]);
const result = await service.findActiveForUser(mockTenantId, mockTargetUserId);
@ -509,8 +509,8 @@ describe('AssignmentsService', () => {
});
it('should handle null customRate', async () => {
const assignmentWithNullRate = { ...createMockAssignment(), customRate: null };
assignmentRepo.findOne.mockResolvedValue(assignmentWithNullRate as CommissionAssignmentEntity);
const assignmentWithNullRate = { ...createMockAssignment(), customRate: undefined };
assignmentRepo.findOne.mockResolvedValue(assignmentWithNullRate as any);
const result = await service.findOne(mockTenantId, mockAssignmentId);

View File

@ -41,17 +41,17 @@ describe('EntriesService', () => {
commissionAmount: 100,
currency: 'USD',
status: EntryStatus.PENDING,
periodId: null,
paidAt: null,
paymentReference: null,
notes: null,
periodId: undefined,
paidAt: undefined,
paymentReference: undefined,
notes: undefined,
metadata: {},
createdAt: new Date(),
updatedAt: new Date(),
approvedBy: null,
approvedAt: null,
scheme: null,
period: null,
approvedBy: undefined,
approvedAt: undefined,
scheme: undefined,
period: undefined,
...overrides,
});

View File

@ -38,12 +38,12 @@ describe('PeriodsService', () => {
totalAmount: 0,
currency: 'USD',
status: PeriodStatus.OPEN,
closedAt: null,
closedBy: null,
paidAt: null,
paidBy: null,
paymentReference: null,
paymentNotes: null,
closedAt: undefined,
closedBy: undefined,
paidAt: undefined,
paidBy: undefined,
paymentReference: undefined,
paymentNotes: undefined,
createdAt: new Date(),
createdBy: mockUserId,
...overrides,

View File

@ -28,12 +28,12 @@ describe('SchemesService', () => {
productIds: [],
categoryIds: [],
minAmount: 0,
maxAmount: null,
maxAmount: undefined,
isActive: true,
createdAt: new Date(),
updatedAt: new Date(),
createdBy: mockUserId,
deletedAt: null,
deletedAt: undefined,
...overrides,
});
@ -101,9 +101,9 @@ describe('SchemesService', () => {
name: 'Tiered Commission',
type: SchemeType.TIERED,
tiers: [
{ min: 0, max: 1000, rate: 5 },
{ min: 1000, max: 5000, rate: 7.5 },
{ min: 5000, max: null, rate: 10 },
{ from: 0, to: 1000, rate: 5 },
{ from: 1000, to: 5000, rate: 7.5 },
{ from: 5000, to: undefined, rate: 10 },
],
appliesTo: AppliesTo.ALL,
};
@ -349,8 +349,8 @@ describe('SchemesService', () => {
it('should update tiers for tiered scheme', async () => {
const updateDto: UpdateSchemeDto = {
tiers: [
{ min: 0, max: 2000, rate: 6 },
{ min: 2000, max: null, rate: 12 },
{ from: 0, to: 2000, rate: 6 },
{ from: 2000, to: undefined, rate: 12 },
],
};
@ -476,8 +476,8 @@ describe('SchemesService', () => {
});
it('should handle null maxAmount correctly', async () => {
const schemeWithNullMax = { ...createMockScheme(), maxAmount: null };
schemeRepo.findOne.mockResolvedValue(schemeWithNullMax as CommissionSchemeEntity);
const schemeWithNullMax = { ...createMockScheme(), maxAmount: undefined };
schemeRepo.findOne.mockResolvedValue(schemeWithNullMax as any);
const result = await service.findOne(mockTenantId, mockSchemeId);

View File

@ -817,7 +817,7 @@ describe('ProductsService', () => {
it('should update a price successfully', async () => {
productRepo.count.mockResolvedValue(1);
priceRepo.findOne.mockResolvedValue({ ...mockPrice });
priceRepo.save.mockResolvedValue({ ...mockPrice, ...updatePriceDto });
priceRepo.save.mockResolvedValue({ ...mockPrice, ...updatePriceDto } as PriceEntity);
const result = await service.updatePrice(
tenantId,
@ -902,7 +902,7 @@ describe('ProductsService', () => {
},
};
productRepo.findOne.mockResolvedValue(productWithCategory);
productRepo.findOne.mockResolvedValue(productWithCategory as ProductEntity);
variantRepo.count.mockResolvedValue(0);
const result = await service.findOne(tenantId, 'prod-123');

View File

@ -24,15 +24,15 @@ describe('ActivitiesService', () => {
subject: 'Follow-up call',
description: 'Call to discuss next steps',
leadId: mockLeadId,
opportunityId: null,
opportunityId: undefined,
dueDate: new Date('2026-02-01'),
dueTime: '10:00:00',
durationMinutes: 30,
assignedTo: mockUserId,
createdBy: mockUserId,
callDirection: 'outbound',
location: null,
meetingUrl: null,
location: undefined,
meetingUrl: undefined,
attendees: [],
reminderAt: new Date('2026-02-01T09:30:00Z'),
reminderSent: false,
@ -102,9 +102,9 @@ describe('ActivitiesService', () => {
attendees: ['john@example.com', 'jane@example.com'],
};
const activityWithOpportunity = { ...mockActivity, opportunityId: mockOpportunityId, leadId: null };
activityRepo.create.mockReturnValue(activityWithOpportunity as ActivityEntity);
activityRepo.save.mockResolvedValue(activityWithOpportunity as ActivityEntity);
const activityWithOpportunity = { ...mockActivity, opportunityId: mockOpportunityId, leadId: undefined };
activityRepo.create.mockReturnValue(activityWithOpportunity as any);
activityRepo.save.mockResolvedValue(activityWithOpportunity as any);
const result = await service.create(mockTenantId, mockUserId, createDto);
@ -345,7 +345,7 @@ describe('ActivitiesService', () => {
durationMinutes: 45,
};
const updatedActivity = { ...mockActivity, ...updateDto };
const updatedActivity = { ...mockActivity, subject: updateDto.subject, dueDate: new Date(updateDto.dueDate), durationMinutes: updateDto.durationMinutes };
activityRepo.findOne.mockResolvedValue(mockActivity as ActivityEntity);
activityRepo.save.mockResolvedValue(updatedActivity as ActivityEntity);

View File

@ -412,7 +412,7 @@ describe('PipelineService', () => {
};
stageRepo.find.mockResolvedValue(mockStages as PipelineStageEntity[]);
stageRepo.save.mockResolvedValue([] as PipelineStageEntity[]);
stageRepo.save.mockResolvedValue(mockStages as any);
opportunityRepo.createQueryBuilder.mockReturnValue(mockQueryBuilder as any);
const result = await service.reorder(mockTenantId, reorderDto);
@ -436,7 +436,7 @@ describe('PipelineService', () => {
};
stageRepo.find.mockResolvedValue(mockStages.slice(0, 2) as PipelineStageEntity[]);
stageRepo.save.mockResolvedValue([] as PipelineStageEntity[]);
stageRepo.save.mockResolvedValue(mockStages.slice(0, 2) as any);
opportunityRepo.createQueryBuilder.mockReturnValue(mockQueryBuilder as any);
await service.reorder(mockTenantId, reorderDto);
@ -472,7 +472,7 @@ describe('PipelineService', () => {
stageRepo.find
.mockResolvedValueOnce(mockStages.slice(0, 3) as PipelineStageEntity[])
.mockResolvedValueOnce(reorderedStages as PipelineStageEntity[]);
stageRepo.save.mockResolvedValue([] as PipelineStageEntity[]);
stageRepo.save.mockResolvedValue(reorderedStages as any);
opportunityRepo.createQueryBuilder.mockReturnValue(mockQueryBuilder as any);
const result = await service.reorder(mockTenantId, reorderDto);