Skip to content

Commit

Permalink
Merge branch 'feature/256__kondoFixes' of https://github.com/Salesfor…
Browse files Browse the repository at this point in the history
…ceFoundation/NPSP into feature/256__kondoFixes
  • Loading branch information
lparrott committed Jan 14, 2025
2 parents fa3d3d9 + a59953a commit 93a5f4f
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 8 deletions.
14 changes: 12 additions & 2 deletions force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,18 @@ private with sharing class BDI_DataImportCTRL_TEST {
// should have matched
System.assertEquals(null,testDIResultA.FailureInformation__c);
System.assertEquals(BDI_DataImport_API.bdiDryRunValidated,testDIResultA.Status__c);
System.assertNotEquals(null,testDIResultA.Contact1Imported__c);
System.assertEquals(System.label.bdiDryRunMatched,testDIResultA.Contact1ImportStatus__c);
// Contact matching will not return an imported contact if contact name is encrypted
if (sObjectType.Contact.fields.Name.isEncrypted()) {
System.assertEquals(null,testDIResultA.Contact1Imported__c);
} else {
System.assertNotEquals(null,testDIResultA.Contact1Imported__c);
}
// Contact matching status will be 'no match' if contact name is encrypted
if (sObjectType.Contact.fields.Name.isEncrypted()) {
System.assertEquals(System.label.bdiDryRunNoMatch,testDIResultA.Contact1ImportStatus__c);
} else {
System.assertEquals(System.label.bdiDryRunMatched,testDIResultA.Contact1ImportStatus__c);
}
System.assertEquals(null,testDIResultA.DonationImported__c);
System.assertEquals(null,testDIResultA.DonationImportStatus__c);

Expand Down
23 changes: 17 additions & 6 deletions force-app/main/default/classes/BDI_DataImportService_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ private with sharing class BDI_DataImportService_TEST {
accounts.add(acc);
}
insert accounts;

// Store Account IDs for assertion
Set<Id> createdAccountIds = new Set<Id>();
for (Account acc : accounts) {
createdAccountIds.add(acc.Id);
}

// Create Contacts to ensure matching
List<Contact> contacts = new List<Contact>();
Expand All @@ -342,6 +348,11 @@ private with sharing class BDI_DataImportService_TEST {
}
insert contacts;

// Store Contact IDs for assertion
Set<Id> createdContactIds = new Set<Id>();
for (Contact con : contacts) {
createdContactIds.add(con.Id);
}
// Assign created contact IDs to the data import records
for (Integer i = 0; i < 5; i++) {
testDataImportss[i].Contact1Imported__c = contacts[i*2].Id;
Expand Down Expand Up @@ -370,12 +381,12 @@ private with sharing class BDI_DataImportService_TEST {
service.importAccounts();
Test.stopTest();

// Add assertions to verify the Account and Contact records were created/updated as expected
List<Account> accounts1 = [SELECT Id, Name, Phone FROM Account WHERE Name LIKE 'Test Account%'];
System.assert(accounts1.size() > 0, 'Accounts should be created');
List<Contact> contactList = [SELECT Id, FirstName, LastName, Email FROM Contact WHERE LastName LIKE 'LastName%'];
System.assert(contactList.size() > 0, 'Contacts should be created');
// Assertions using IDs
List<Account> fetchedAccounts = [SELECT Id, Name FROM Account WHERE Id IN :createdAccountIds];
System.assertEquals(createdAccountIds.size(), fetchedAccounts.size(), 'Accounts should be created and fetched using Ids');

List<Contact> fetchedContacts = [SELECT Id, FirstName, LastName, Email FROM Contact WHERE Id IN :createdContactIds];
System.assertEquals(createdContactIds.size(), fetchedContacts.size(), 'Contacts should be created and fetched using Ids');
}

// Helpers
Expand Down
84 changes: 84 additions & 0 deletions force-app/main/default/classes/GiftEntryProcessorQueue_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,90 @@ private class GiftEntryProcessorQueue_TEST {
'Should have the correct amount');
}

@isTest
static void shouldCreateRDWhenGiftBatchHasRecurringGiftCsvImport() {
// Arrange
RD2_EnablementService_TEST.setRecurringDonations2Enabled();
Data_Import_Settings__c dataImportSettings = UTIL_CustomSettingsFacade.getDataImportSettings();
dataImportSettings.Field_Mapping_Method__c = BDI_DataImportService.FM_DATA_IMPORT_FIELD_MAPPING;
dataImportSettings.Default_Data_Import_Field_Mapping_Set__c =
BDI_MappingServiceAdvanced.DEFAULT_DATA_IMPORT_FIELD_MAPPING_SET_NAME;
UTIL_CustomSettingsFacade.setDataImportSettings(dataImportSettings);

DataImportBatch__c giftBatch = new DataImportBatch__c();
insert giftBatch;

List<DataImport__c> giftsToInsert = new List<DataImport__c>();
giftsToInsert.add(new DataImport__c(
Recurring_Donation_Installment_Period__c = 'Monthly',
Recurring_Donation_Effective_Date__c = Date.today(),
Recurring_Donation_Recurring_Type__c = 'Open',
Recurring_Donation_Installment_Frequency__c = 1,
Recurring_Donation_Day_of_Month__c = '5',
Recurring_Donation_Amount__c = 33.00,
Donation_Amount__c = 50.00,
Recurring_Donation_Date_Established__c = Date.today(),
Donation_Date__c = Date.today(),
NPSP_Data_Import_Batch__c = giftBatch.Id,
Contact1_Lastname__c = 'Dummy Last Name',
Donation_Donor__c = 'Contact1'
));
insert giftsToInsert;

GiftBatchForQueueable giftBatchForProcessing = new GiftBatchForQueueable(new GiftBatchId(giftBatch.Id), new GiftBatchSelector());
giftBatchForProcessing.chunkGiftsThatCanBeProcessed();
GiftEntryProcessorQueue processorQueue = new GiftEntryProcessorQueue(giftBatchForProcessing);

// Act
Test.startTest();
processorQueue.execute(null);
Test.stopTest();

// Assert
npe03__Recurring_Donation__c[] resultingRDs =
[SELECT Id,
npe03__Amount__c,
npe03__Installment_Period__c,
RecurringType__c,
StartDate__c,
npe03__Date_Established__c,
Day_of_Month__c
FROM npe03__Recurring_Donation__c];

System.assertEquals(1, resultingRDs.size(),
'Should result in one recurring donation record');
System.assertEquals(33.00, resultingRDs[0].npe03__Amount__c,
'Should have the correct amount');
System.assertEquals(Date.today(), resultingRDs[0].npe03__Date_Established__c,
'Should have the correct date established');
System.assertEquals('Monthly', resultingRDs[0].npe03__Installment_Period__c,
'Should have the correct installment period');
System.assertEquals('Open', resultingRDs[0].RecurringType__c,
'Should have the correct recurring type');
System.assertEquals('5', resultingRDs[0].Day_of_Month__c,
'Should have the correct day of month');

Opportunity[] resultingOpportunities =
[SELECT Id,
Amount,
CloseDate,
StageName,
npe03__Recurring_Donation__c
FROM Opportunity ORDER BY CloseDate ASC];
System.assertEquals(2, resultingOpportunities.size(),
'Should result in one opportunity record');
System.assertEquals(resultingRDs[0].Id, resultingOpportunities[0].npe03__Recurring_Donation__c,
'Resulting opportunity should look up to the recurring donation');
System.assertEquals(50.00, resultingOpportunities[0].Amount,
'First Opp should have the correct Amount');
System.assertEquals(Date.today(), resultingOpportunities[0].CloseDate,
'First Opp should have the correct Close Date');
System.assertEquals(33.00, resultingOpportunities[1].Amount,
'Second Opp should have the correct Amount');
System.assertEquals('Pledged', resultingOpportunities[1].StageName,
'Second Opp should have the correct Stage');
}

@IsTest
static void shouldCreate20OpportunitiesAndFail10GiftsIn1Chunk() {
// Arrange
Expand Down

0 comments on commit 93a5f4f

Please sign in to comment.