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:
parent
d72bc4da04
commit
ee7ed19e4a
@ -30,7 +30,7 @@ describe('AssignmentsService', () => {
|
|||||||
type: SchemeType.PERCENTAGE,
|
type: SchemeType.PERCENTAGE,
|
||||||
rate: 10,
|
rate: 10,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
deletedAt: null,
|
deletedAt: undefined,
|
||||||
...overrides,
|
...overrides,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -40,8 +40,8 @@ describe('AssignmentsService', () => {
|
|||||||
userId: mockTargetUserId,
|
userId: mockTargetUserId,
|
||||||
schemeId: mockSchemeId,
|
schemeId: mockSchemeId,
|
||||||
startsAt: new Date('2026-01-01'),
|
startsAt: new Date('2026-01-01'),
|
||||||
endsAt: null,
|
endsAt: undefined,
|
||||||
customRate: null,
|
customRate: undefined,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
createdBy: mockUserId,
|
createdBy: mockUserId,
|
||||||
@ -425,11 +425,11 @@ describe('AssignmentsService', () => {
|
|||||||
const futureAssignment = {
|
const futureAssignment = {
|
||||||
...createMockAssignment(),
|
...createMockAssignment(),
|
||||||
startsAt: new Date(now.getTime() + 86400000), // tomorrow
|
startsAt: new Date(now.getTime() + 86400000), // tomorrow
|
||||||
endsAt: null,
|
endsAt: undefined,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
assignmentRepo.find.mockResolvedValue([futureAssignment as CommissionAssignmentEntity]);
|
assignmentRepo.find.mockResolvedValue([futureAssignment as any]);
|
||||||
|
|
||||||
const result = await service.findActiveForUser(mockTenantId, mockTargetUserId);
|
const result = await service.findActiveForUser(mockTenantId, mockTargetUserId);
|
||||||
|
|
||||||
@ -457,11 +457,11 @@ describe('AssignmentsService', () => {
|
|||||||
const openEndedAssignment = {
|
const openEndedAssignment = {
|
||||||
...createMockAssignment(),
|
...createMockAssignment(),
|
||||||
startsAt: new Date(now.getTime() - 86400000), // yesterday
|
startsAt: new Date(now.getTime() - 86400000), // yesterday
|
||||||
endsAt: null,
|
endsAt: undefined,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
assignmentRepo.find.mockResolvedValue([openEndedAssignment as CommissionAssignmentEntity]);
|
assignmentRepo.find.mockResolvedValue([openEndedAssignment as any]);
|
||||||
|
|
||||||
const result = await service.findActiveForUser(mockTenantId, mockTargetUserId);
|
const result = await service.findActiveForUser(mockTenantId, mockTargetUserId);
|
||||||
|
|
||||||
@ -509,8 +509,8 @@ describe('AssignmentsService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle null customRate', async () => {
|
it('should handle null customRate', async () => {
|
||||||
const assignmentWithNullRate = { ...createMockAssignment(), customRate: null };
|
const assignmentWithNullRate = { ...createMockAssignment(), customRate: undefined };
|
||||||
assignmentRepo.findOne.mockResolvedValue(assignmentWithNullRate as CommissionAssignmentEntity);
|
assignmentRepo.findOne.mockResolvedValue(assignmentWithNullRate as any);
|
||||||
|
|
||||||
const result = await service.findOne(mockTenantId, mockAssignmentId);
|
const result = await service.findOne(mockTenantId, mockAssignmentId);
|
||||||
|
|
||||||
|
|||||||
@ -41,17 +41,17 @@ describe('EntriesService', () => {
|
|||||||
commissionAmount: 100,
|
commissionAmount: 100,
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
status: EntryStatus.PENDING,
|
status: EntryStatus.PENDING,
|
||||||
periodId: null,
|
periodId: undefined,
|
||||||
paidAt: null,
|
paidAt: undefined,
|
||||||
paymentReference: null,
|
paymentReference: undefined,
|
||||||
notes: null,
|
notes: undefined,
|
||||||
metadata: {},
|
metadata: {},
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
approvedBy: null,
|
approvedBy: undefined,
|
||||||
approvedAt: null,
|
approvedAt: undefined,
|
||||||
scheme: null,
|
scheme: undefined,
|
||||||
period: null,
|
period: undefined,
|
||||||
...overrides,
|
...overrides,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -38,12 +38,12 @@ describe('PeriodsService', () => {
|
|||||||
totalAmount: 0,
|
totalAmount: 0,
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
status: PeriodStatus.OPEN,
|
status: PeriodStatus.OPEN,
|
||||||
closedAt: null,
|
closedAt: undefined,
|
||||||
closedBy: null,
|
closedBy: undefined,
|
||||||
paidAt: null,
|
paidAt: undefined,
|
||||||
paidBy: null,
|
paidBy: undefined,
|
||||||
paymentReference: null,
|
paymentReference: undefined,
|
||||||
paymentNotes: null,
|
paymentNotes: undefined,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
createdBy: mockUserId,
|
createdBy: mockUserId,
|
||||||
...overrides,
|
...overrides,
|
||||||
|
|||||||
@ -28,12 +28,12 @@ describe('SchemesService', () => {
|
|||||||
productIds: [],
|
productIds: [],
|
||||||
categoryIds: [],
|
categoryIds: [],
|
||||||
minAmount: 0,
|
minAmount: 0,
|
||||||
maxAmount: null,
|
maxAmount: undefined,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
createdBy: mockUserId,
|
createdBy: mockUserId,
|
||||||
deletedAt: null,
|
deletedAt: undefined,
|
||||||
...overrides,
|
...overrides,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -101,9 +101,9 @@ describe('SchemesService', () => {
|
|||||||
name: 'Tiered Commission',
|
name: 'Tiered Commission',
|
||||||
type: SchemeType.TIERED,
|
type: SchemeType.TIERED,
|
||||||
tiers: [
|
tiers: [
|
||||||
{ min: 0, max: 1000, rate: 5 },
|
{ from: 0, to: 1000, rate: 5 },
|
||||||
{ min: 1000, max: 5000, rate: 7.5 },
|
{ from: 1000, to: 5000, rate: 7.5 },
|
||||||
{ min: 5000, max: null, rate: 10 },
|
{ from: 5000, to: undefined, rate: 10 },
|
||||||
],
|
],
|
||||||
appliesTo: AppliesTo.ALL,
|
appliesTo: AppliesTo.ALL,
|
||||||
};
|
};
|
||||||
@ -349,8 +349,8 @@ describe('SchemesService', () => {
|
|||||||
it('should update tiers for tiered scheme', async () => {
|
it('should update tiers for tiered scheme', async () => {
|
||||||
const updateDto: UpdateSchemeDto = {
|
const updateDto: UpdateSchemeDto = {
|
||||||
tiers: [
|
tiers: [
|
||||||
{ min: 0, max: 2000, rate: 6 },
|
{ from: 0, to: 2000, rate: 6 },
|
||||||
{ min: 2000, max: null, rate: 12 },
|
{ from: 2000, to: undefined, rate: 12 },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -476,8 +476,8 @@ describe('SchemesService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle null maxAmount correctly', async () => {
|
it('should handle null maxAmount correctly', async () => {
|
||||||
const schemeWithNullMax = { ...createMockScheme(), maxAmount: null };
|
const schemeWithNullMax = { ...createMockScheme(), maxAmount: undefined };
|
||||||
schemeRepo.findOne.mockResolvedValue(schemeWithNullMax as CommissionSchemeEntity);
|
schemeRepo.findOne.mockResolvedValue(schemeWithNullMax as any);
|
||||||
|
|
||||||
const result = await service.findOne(mockTenantId, mockSchemeId);
|
const result = await service.findOne(mockTenantId, mockSchemeId);
|
||||||
|
|
||||||
|
|||||||
@ -817,7 +817,7 @@ describe('ProductsService', () => {
|
|||||||
it('should update a price successfully', async () => {
|
it('should update a price successfully', async () => {
|
||||||
productRepo.count.mockResolvedValue(1);
|
productRepo.count.mockResolvedValue(1);
|
||||||
priceRepo.findOne.mockResolvedValue({ ...mockPrice });
|
priceRepo.findOne.mockResolvedValue({ ...mockPrice });
|
||||||
priceRepo.save.mockResolvedValue({ ...mockPrice, ...updatePriceDto });
|
priceRepo.save.mockResolvedValue({ ...mockPrice, ...updatePriceDto } as PriceEntity);
|
||||||
|
|
||||||
const result = await service.updatePrice(
|
const result = await service.updatePrice(
|
||||||
tenantId,
|
tenantId,
|
||||||
@ -902,7 +902,7 @@ describe('ProductsService', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
productRepo.findOne.mockResolvedValue(productWithCategory);
|
productRepo.findOne.mockResolvedValue(productWithCategory as ProductEntity);
|
||||||
variantRepo.count.mockResolvedValue(0);
|
variantRepo.count.mockResolvedValue(0);
|
||||||
|
|
||||||
const result = await service.findOne(tenantId, 'prod-123');
|
const result = await service.findOne(tenantId, 'prod-123');
|
||||||
|
|||||||
@ -24,15 +24,15 @@ describe('ActivitiesService', () => {
|
|||||||
subject: 'Follow-up call',
|
subject: 'Follow-up call',
|
||||||
description: 'Call to discuss next steps',
|
description: 'Call to discuss next steps',
|
||||||
leadId: mockLeadId,
|
leadId: mockLeadId,
|
||||||
opportunityId: null,
|
opportunityId: undefined,
|
||||||
dueDate: new Date('2026-02-01'),
|
dueDate: new Date('2026-02-01'),
|
||||||
dueTime: '10:00:00',
|
dueTime: '10:00:00',
|
||||||
durationMinutes: 30,
|
durationMinutes: 30,
|
||||||
assignedTo: mockUserId,
|
assignedTo: mockUserId,
|
||||||
createdBy: mockUserId,
|
createdBy: mockUserId,
|
||||||
callDirection: 'outbound',
|
callDirection: 'outbound',
|
||||||
location: null,
|
location: undefined,
|
||||||
meetingUrl: null,
|
meetingUrl: undefined,
|
||||||
attendees: [],
|
attendees: [],
|
||||||
reminderAt: new Date('2026-02-01T09:30:00Z'),
|
reminderAt: new Date('2026-02-01T09:30:00Z'),
|
||||||
reminderSent: false,
|
reminderSent: false,
|
||||||
@ -102,9 +102,9 @@ describe('ActivitiesService', () => {
|
|||||||
attendees: ['john@example.com', 'jane@example.com'],
|
attendees: ['john@example.com', 'jane@example.com'],
|
||||||
};
|
};
|
||||||
|
|
||||||
const activityWithOpportunity = { ...mockActivity, opportunityId: mockOpportunityId, leadId: null };
|
const activityWithOpportunity = { ...mockActivity, opportunityId: mockOpportunityId, leadId: undefined };
|
||||||
activityRepo.create.mockReturnValue(activityWithOpportunity as ActivityEntity);
|
activityRepo.create.mockReturnValue(activityWithOpportunity as any);
|
||||||
activityRepo.save.mockResolvedValue(activityWithOpportunity as ActivityEntity);
|
activityRepo.save.mockResolvedValue(activityWithOpportunity as any);
|
||||||
|
|
||||||
const result = await service.create(mockTenantId, mockUserId, createDto);
|
const result = await service.create(mockTenantId, mockUserId, createDto);
|
||||||
|
|
||||||
@ -345,7 +345,7 @@ describe('ActivitiesService', () => {
|
|||||||
durationMinutes: 45,
|
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.findOne.mockResolvedValue(mockActivity as ActivityEntity);
|
||||||
activityRepo.save.mockResolvedValue(updatedActivity as ActivityEntity);
|
activityRepo.save.mockResolvedValue(updatedActivity as ActivityEntity);
|
||||||
|
|
||||||
|
|||||||
@ -412,7 +412,7 @@ describe('PipelineService', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
stageRepo.find.mockResolvedValue(mockStages as PipelineStageEntity[]);
|
stageRepo.find.mockResolvedValue(mockStages as PipelineStageEntity[]);
|
||||||
stageRepo.save.mockResolvedValue([] as PipelineStageEntity[]);
|
stageRepo.save.mockResolvedValue(mockStages as any);
|
||||||
opportunityRepo.createQueryBuilder.mockReturnValue(mockQueryBuilder as any);
|
opportunityRepo.createQueryBuilder.mockReturnValue(mockQueryBuilder as any);
|
||||||
|
|
||||||
const result = await service.reorder(mockTenantId, reorderDto);
|
const result = await service.reorder(mockTenantId, reorderDto);
|
||||||
@ -436,7 +436,7 @@ describe('PipelineService', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
stageRepo.find.mockResolvedValue(mockStages.slice(0, 2) as PipelineStageEntity[]);
|
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);
|
opportunityRepo.createQueryBuilder.mockReturnValue(mockQueryBuilder as any);
|
||||||
|
|
||||||
await service.reorder(mockTenantId, reorderDto);
|
await service.reorder(mockTenantId, reorderDto);
|
||||||
@ -472,7 +472,7 @@ describe('PipelineService', () => {
|
|||||||
stageRepo.find
|
stageRepo.find
|
||||||
.mockResolvedValueOnce(mockStages.slice(0, 3) as PipelineStageEntity[])
|
.mockResolvedValueOnce(mockStages.slice(0, 3) as PipelineStageEntity[])
|
||||||
.mockResolvedValueOnce(reorderedStages as PipelineStageEntity[]);
|
.mockResolvedValueOnce(reorderedStages as PipelineStageEntity[]);
|
||||||
stageRepo.save.mockResolvedValue([] as PipelineStageEntity[]);
|
stageRepo.save.mockResolvedValue(reorderedStages as any);
|
||||||
opportunityRepo.createQueryBuilder.mockReturnValue(mockQueryBuilder as any);
|
opportunityRepo.createQueryBuilder.mockReturnValue(mockQueryBuilder as any);
|
||||||
|
|
||||||
const result = await service.reorder(mockTenantId, reorderDto);
|
const result = await service.reorder(mockTenantId, reorderDto);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user