Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolk 2282 #2132

Merged
merged 11 commits into from
Nov 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,26 @@ public without sharing class HOT_ServiceAppointmentHandler extends MyTriggers {
serviceResourceByServiceAppointmentSchedTimeChanged,
serviceResources
);
HOT_WageClaimService.updateWageClaims(newServiceAppointmentsSchedTimeChanged, wageClaims, false);

HOT_WageClaim__c[] claimsWithNoConflicts = new List<HOT_WageClaim__c>();
HOT_WageClaim__c[] claimsWithConflicts = new List<HOT_WageClaim__c>();

for (HOT_WageClaim__c wc : wageClaims) {
Boolean isConflict = false;
for (ServiceAppointment sa : newServiceAppointmentsSchedTimeChanged.values()) {
if (sa.SchedStartTime < wc.EndTime__c && sa.SchedEndTime > wc.StartTime__c) {
isConflict = true;
}
}
if (isConflict) {
claimsWithConflicts.add(wc);
} else {
claimsWithNoConflicts.add(wc);
}
}

HOT_DatabaseOperations.insertRecords(claimsWithNoConflicts);
HOT_WageClaimService.updateWageClaims(newServiceAppointmentsSchedTimeChanged, claimsWithConflicts, false);
HOT_WageClaimService.updateWageClaimsFuture(serviceResourceByServiceAppointmentSchedTimeChanged.keySet());
}

Expand Down
47 changes: 47 additions & 0 deletions force-app/main/wageClaim/classes/HOT_CreateWageClaimTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,51 @@ private class HOT_CreateWageClaimTest {
Test.stopTest();
System.assertEquals(1, wageClaims.size(), 'Wrongly created Wage Claims');
}

private static Integer testTimeChange(Integer startOffsetInMinutes, Integer endOffsetInMinutes) {
ServiceAppointment serviceAppointment = [SELECT Id, SchedStartTime, SchedEndTime FROM ServiceAppointment];
Test.startTest();
serviceAppointment.SchedStartTime = serviceAppointment.SchedStartTime.addMinutes(startOffsetInMinutes);
serviceAppointment.SchedEndTime = serviceAppointment.SchedEndTime.addMinutes(endOffsetInMinutes);
update serviceAppointment;
Test.stopTest();

List<HOT_WageClaim__c> wageClaims = [
SELECT Id, StartTime__c, EndTime__c, Status__c
FROM HOT_WageClaim__c
LIMIT 5
];

return wageClaims.size();
}

@isTest
static void createWageClaimTest_timeChangesLower() {
Integer wageClaimCount = testTimechange(-10, -10);
System.assertEquals(1, wageClaimCount, 'Did not create Wage Claim as expected');
}

@isTest
static void createWageClaimTest_timeChangesCovered() {
Integer wageClaimCount = testTimeChange(-10, 10);
System.assertEquals(0, wageClaimCount, 'Created Wage Claim when new timespan covers the old timespan of SA');
}

@isTest
static void createWageClaimTest_timeChangesUpper() {
Integer wageClaimCount = testTimeChange(10, 10);
System.assertEquals(1, wageClaimCount, 'Did not create Wage Claim as expected');
}

@isTest
static void createWageClaimTest_timeChangesExactlyAfter() {
Integer wageClaimCount = testTimeChange(120, 120);
System.assertEquals(1, wageClaimCount, 'Did not create Wage Claim as expected');
}

@isTest
static void createWageClaimTest_timeChangesAfter() {
Integer wageClaimCount = testTimeChange(400, 400);
System.assertEquals(1, wageClaimCount, 'Did not create Wage Claim as expected');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ private class HOT_UpdateWageClaimTest {

List<HOT_WageClaim__c> wageClaimsAfter = [SELECT Id, Status__c FROM HOT_WageClaim__c];
System.assertEquals(1, wageClaimsBefore.size(), 'Not correct number of Wage Claims');
System.assertEquals(1, wageClaimsAfter.size(), 'Not correct number of Wage Claims');
System.assertEquals(2, wageClaimsAfter.size(), 'Not correct number of Wage Claims');
System.assertEquals('Open', wageClaimsBefore[0].Status__c, 'Should be Open before time is changed');
System.assertEquals('Covered', wageClaimsAfter[0].Status__c, 'Should be Covered after time is changed');
}
Expand Down
Loading