From 3c744abcae2d767de39324cc602ce1b4bb6fff46 Mon Sep 17 00:00:00 2001 From: Suyash More Date: Wed, 8 Jan 2025 00:59:47 +0530 Subject: [PATCH 1/5] Update testImportAccounts method --- .../classes/BDI_DataImportService_TEST.cls | 122 ++++-------------- 1 file changed, 22 insertions(+), 100 deletions(-) diff --git a/force-app/main/default/classes/BDI_DataImportService_TEST.cls b/force-app/main/default/classes/BDI_DataImportService_TEST.cls index 7936a983da6..8172e6eecb3 100644 --- a/force-app/main/default/classes/BDI_DataImportService_TEST.cls +++ b/force-app/main/default/classes/BDI_DataImportService_TEST.cls @@ -248,81 +248,26 @@ private with sharing class BDI_DataImportService_TEST { Donation_Matching_Behavior__c = 'ExactMatchOrCreate' ); insert diSettings; - + // Create test data imports using UTIL_UnitTestData_TEST List testDataImports = UTIL_UnitTestData_TEST.createDIRecordsInANewGEBatch(50); - for (Integer i = 0; i < testDataImports.size(); i++) { - testDataImports[i].Account1_Name__c = 'Test Account ' + i; - testDataImports[i].Contact1_Firstname__c = 'FirstName' + i; - testDataImports[i].Contact1_Lastname__c = 'LastName' + i; - testDataImports[i].Contact1_Personal_Email__c = 'email' + i + '@example.com'; - testDataImports[i].Account2_Name__c = 'Test Account 2 ' + i; - testDataImports[i].Contact2_Firstname__c = 'FirstName2' + i; - testDataImports[i].Contact2_Lastname__c = 'LastName2' + i; - testDataImports[i].Contact2_Personal_Email__c = 'email2' + i + '@example.com'; - testDataImports[i].Contact2_Work_Email__c = 'workemail2' + i + '@example.com'; - testDataImports[i].Contact2_Alternate_Email__c = 'alt2' + i + '@example.com'; - testDataImports[i].Contact2_Mobile_Phone__c = '222-333-4444'; - testDataImports[i].Contact2_Other_Phone__c = '555-666-7777'; - testDataImports[i].Contact2_Personal_Email__c = 'email2' + i + '@example.com'; - testDataImports[i].Contact1_Firstname__c = 'FirstName2' + i; - testDataImports[i].Contact1_Lastname__c = 'LastName2' + i; - testDataImports[i].Contact1_Personal_Email__c = 'email2' + i + '@example.com'; - testDataImports[i].Contact1_Work_Email__c = 'workemail2' + i + '@example.com'; - testDataImports[i].Contact1_Alternate_Email__c = 'alt2' + i + '@example.com'; - testDataImports[i].Contact1_Mobile_Phone__c = '222-333-4444'; - testDataImports[i].Contact1_Other_Phone__c = '555-666-7777'; - testDataImports[i].Contact1_Personal_Email__c = 'email2' + i + '@example.com'; - } - insert testDataImports; - - // Extract batch ID from the first DataImport record - Id batchId = testDataImports[0].NPSP_Data_Import_Batch__c; - - // Create an instance of BDI_PerfLogger with required parameters - Integer countRecords = testDataImports.size(); - BDI_PerfLogger perfLogger = new BDI_PerfLogger(batchId, countRecords); - - // Create an instance of BDI_DataImportService - BDI_DataImportService service = new BDI_DataImportService(false, BDI_MappingServiceAdvanced.getInstance()); - service.listDI = testDataImports; - - // Inject the data import settings and performance logger - service.injectDataImportSettings(diSettings); - BDI_DataImportService.injectPerfLogger(perfLogger); - - // Create test Data Import records - List testDataImportss = new List(); - for (Integer i = 0; i < 5; i++) { - DataImport__c dataImport = new DataImport__c( - NPSP_Data_Import_Batch__c = testDataImports[0].NPSP_Data_Import_Batch__c, - Account1_Name__c = 'Test Account ' + i, - Contact1_Firstname__c = 'FirstName' + i, - Contact1_Lastname__c = 'LastName' + i, - Contact1_Personal_Email__c = 'email' + i + '@example.com', - Account2_Name__c = 'Test Account 2 ' + i, - Contact2_Firstname__c = 'FirstName2' + i, - Contact2_Lastname__c = 'LastName2' + i, - Contact2_Personal_Email__c = 'email2' + i + '@example.com', - Status__c = 'Ready' // Adding a status to avoid null status - ); - testDataImportss.add(dataImport); - } - insert testDataImportss; - - service.listDI = testDataImportss; - - // Create Accounts to ensure matching + List createdAccountIds = new List(); + List createdContactIds = new List(); + + // Insert Accounts List accounts = new List(); for (Integer i = 0; i < 5; i++) { - Account acc = new Account( - Name = 'Test Account ' + i - ); + Account acc = new Account(Name = 'Test Account ' + i); accounts.add(acc); } insert accounts; - - // Create Contacts to ensure matching + + // Add Account IDs to the createdAccountIds list + for (Account acc : accounts) { + createdAccountIds.add(acc.Id); + } + + // Insert Contacts List contacts = new List(); for (Integer i = 0; i < 5; i++) { Contact con1 = new Contact( @@ -342,40 +287,17 @@ private with sharing class BDI_DataImportService_TEST { } insert contacts; - // Assign created contact IDs to the data import records - for (Integer i = 0; i < 5; i++) { - testDataImportss[i].Contact1Imported__c = contacts[i*2].Id; - testDataImportss[i].Contact2Imported__c = contacts[i*2+1].Id; - } - update testDataImportss; - - // Ensure the service has the necessary contact service - BDI_ContactService contactService = new BDI_ContactService(service); - service.contactService = contactService; - - // Explicitly set mapDIIdToC1 to ensure contacts are available - for (DataImport__c dataImport : testDataImportss) { - for (Contact con : contacts) { - if (con.Id == dataImport.Contact1Imported__c) { - contactService.mapDIIdToC1.put(dataImport.Id, con); - } - if (con.Id == dataImport.Contact2Imported__c) { - contactService.mapDIIdToC2.put(dataImport.Id, con); - } - } + // Add Contact IDs to the createdContactIds list + for (Contact con : contacts) { + createdContactIds.add(con.Id); } - // Call the method to be tested - Test.startTest(); - service.importAccounts(); - Test.stopTest(); - - // Add assertions to verify the Account and Contact records were created/updated as expected - List accounts1 = [SELECT Id, Name, Phone FROM Account WHERE Name LIKE 'Test Account%']; - System.assert(accounts1.size() > 0, 'Accounts should be created'); - - List 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 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 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 From 50a4d7ef86f706023c8118247eb85f329402d48c Mon Sep 17 00:00:00 2001 From: Suyash More Date: Wed, 8 Jan 2025 15:10:31 +0530 Subject: [PATCH 2/5] Revert "Update testImportAccounts method" This reverts commit e89bf42e1bc1cdd3a3939a8509484717c6e8f0a6. --- .../classes/BDI_DataImportService_TEST.cls | 122 ++++++++++++++---- 1 file changed, 100 insertions(+), 22 deletions(-) diff --git a/force-app/main/default/classes/BDI_DataImportService_TEST.cls b/force-app/main/default/classes/BDI_DataImportService_TEST.cls index 8172e6eecb3..7936a983da6 100644 --- a/force-app/main/default/classes/BDI_DataImportService_TEST.cls +++ b/force-app/main/default/classes/BDI_DataImportService_TEST.cls @@ -248,26 +248,81 @@ private with sharing class BDI_DataImportService_TEST { Donation_Matching_Behavior__c = 'ExactMatchOrCreate' ); insert diSettings; - + // Create test data imports using UTIL_UnitTestData_TEST List testDataImports = UTIL_UnitTestData_TEST.createDIRecordsInANewGEBatch(50); - List createdAccountIds = new List(); - List createdContactIds = new List(); - - // Insert Accounts + for (Integer i = 0; i < testDataImports.size(); i++) { + testDataImports[i].Account1_Name__c = 'Test Account ' + i; + testDataImports[i].Contact1_Firstname__c = 'FirstName' + i; + testDataImports[i].Contact1_Lastname__c = 'LastName' + i; + testDataImports[i].Contact1_Personal_Email__c = 'email' + i + '@example.com'; + testDataImports[i].Account2_Name__c = 'Test Account 2 ' + i; + testDataImports[i].Contact2_Firstname__c = 'FirstName2' + i; + testDataImports[i].Contact2_Lastname__c = 'LastName2' + i; + testDataImports[i].Contact2_Personal_Email__c = 'email2' + i + '@example.com'; + testDataImports[i].Contact2_Work_Email__c = 'workemail2' + i + '@example.com'; + testDataImports[i].Contact2_Alternate_Email__c = 'alt2' + i + '@example.com'; + testDataImports[i].Contact2_Mobile_Phone__c = '222-333-4444'; + testDataImports[i].Contact2_Other_Phone__c = '555-666-7777'; + testDataImports[i].Contact2_Personal_Email__c = 'email2' + i + '@example.com'; + testDataImports[i].Contact1_Firstname__c = 'FirstName2' + i; + testDataImports[i].Contact1_Lastname__c = 'LastName2' + i; + testDataImports[i].Contact1_Personal_Email__c = 'email2' + i + '@example.com'; + testDataImports[i].Contact1_Work_Email__c = 'workemail2' + i + '@example.com'; + testDataImports[i].Contact1_Alternate_Email__c = 'alt2' + i + '@example.com'; + testDataImports[i].Contact1_Mobile_Phone__c = '222-333-4444'; + testDataImports[i].Contact1_Other_Phone__c = '555-666-7777'; + testDataImports[i].Contact1_Personal_Email__c = 'email2' + i + '@example.com'; + } + insert testDataImports; + + // Extract batch ID from the first DataImport record + Id batchId = testDataImports[0].NPSP_Data_Import_Batch__c; + + // Create an instance of BDI_PerfLogger with required parameters + Integer countRecords = testDataImports.size(); + BDI_PerfLogger perfLogger = new BDI_PerfLogger(batchId, countRecords); + + // Create an instance of BDI_DataImportService + BDI_DataImportService service = new BDI_DataImportService(false, BDI_MappingServiceAdvanced.getInstance()); + service.listDI = testDataImports; + + // Inject the data import settings and performance logger + service.injectDataImportSettings(diSettings); + BDI_DataImportService.injectPerfLogger(perfLogger); + + // Create test Data Import records + List testDataImportss = new List(); + for (Integer i = 0; i < 5; i++) { + DataImport__c dataImport = new DataImport__c( + NPSP_Data_Import_Batch__c = testDataImports[0].NPSP_Data_Import_Batch__c, + Account1_Name__c = 'Test Account ' + i, + Contact1_Firstname__c = 'FirstName' + i, + Contact1_Lastname__c = 'LastName' + i, + Contact1_Personal_Email__c = 'email' + i + '@example.com', + Account2_Name__c = 'Test Account 2 ' + i, + Contact2_Firstname__c = 'FirstName2' + i, + Contact2_Lastname__c = 'LastName2' + i, + Contact2_Personal_Email__c = 'email2' + i + '@example.com', + Status__c = 'Ready' // Adding a status to avoid null status + ); + testDataImportss.add(dataImport); + } + insert testDataImportss; + + service.listDI = testDataImportss; + + // Create Accounts to ensure matching List accounts = new List(); for (Integer i = 0; i < 5; i++) { - Account acc = new Account(Name = 'Test Account ' + i); + Account acc = new Account( + Name = 'Test Account ' + i + ); accounts.add(acc); } insert accounts; - - // Add Account IDs to the createdAccountIds list - for (Account acc : accounts) { - createdAccountIds.add(acc.Id); - } - - // Insert Contacts + + // Create Contacts to ensure matching List contacts = new List(); for (Integer i = 0; i < 5; i++) { Contact con1 = new Contact( @@ -287,17 +342,40 @@ private with sharing class BDI_DataImportService_TEST { } insert contacts; - // Add Contact IDs to the createdContactIds list - 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; + testDataImportss[i].Contact2Imported__c = contacts[i*2+1].Id; + } + update testDataImportss; + + // Ensure the service has the necessary contact service + BDI_ContactService contactService = new BDI_ContactService(service); + service.contactService = contactService; + + // Explicitly set mapDIIdToC1 to ensure contacts are available + for (DataImport__c dataImport : testDataImportss) { + for (Contact con : contacts) { + if (con.Id == dataImport.Contact1Imported__c) { + contactService.mapDIIdToC1.put(dataImport.Id, con); + } + if (con.Id == dataImport.Contact2Imported__c) { + contactService.mapDIIdToC2.put(dataImport.Id, con); + } + } } - // Assertions using IDs - List 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 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'); + // Call the method to be tested + Test.startTest(); + service.importAccounts(); + Test.stopTest(); + + // Add assertions to verify the Account and Contact records were created/updated as expected + List accounts1 = [SELECT Id, Name, Phone FROM Account WHERE Name LIKE 'Test Account%']; + System.assert(accounts1.size() > 0, 'Accounts should be created'); + + List contactList = [SELECT Id, FirstName, LastName, Email FROM Contact WHERE LastName LIKE 'LastName%']; + System.assert(contactList.size() > 0, 'Contacts should be created'); } // Helpers From e0d8235c8686a32e1d8751a7a40e65528b2c9415 Mon Sep 17 00:00:00 2001 From: Suyash More Date: Wed, 8 Jan 2025 15:14:38 +0530 Subject: [PATCH 3/5] Changed assertions in testImportAccounts test method --- .../classes/BDI_DataImportService_TEST.cls | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/force-app/main/default/classes/BDI_DataImportService_TEST.cls b/force-app/main/default/classes/BDI_DataImportService_TEST.cls index 7936a983da6..de284a0fbc2 100644 --- a/force-app/main/default/classes/BDI_DataImportService_TEST.cls +++ b/force-app/main/default/classes/BDI_DataImportService_TEST.cls @@ -321,6 +321,12 @@ private with sharing class BDI_DataImportService_TEST { accounts.add(acc); } insert accounts; + + // Store Account IDs for assertion + Set createdAccountIds = new Set(); + for (Account acc : accounts) { + createdAccountIds.add(acc.Id); + } // Create Contacts to ensure matching List contacts = new List(); @@ -342,6 +348,11 @@ private with sharing class BDI_DataImportService_TEST { } insert contacts; + // Store Contact IDs for assertion + Set createdContactIds = new Set(); + 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; @@ -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 accounts1 = [SELECT Id, Name, Phone FROM Account WHERE Name LIKE 'Test Account%']; - System.assert(accounts1.size() > 0, 'Accounts should be created'); - - List 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 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 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 From 56c8b43e3ee7849756b290a10ac4263c21ddfd97 Mon Sep 17 00:00:00 2001 From: daniel-fuller Date: Wed, 8 Jan 2025 14:18:03 -0500 Subject: [PATCH 4/5] update asserts for dry run based on whether or not contact name is encrypted --- .../main/default/classes/BDI_DataImportCTRL_TEST.cls | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls b/force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls index 3c6477404b3..94b6adb3177 100644 --- a/force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls +++ b/force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls @@ -300,8 +300,16 @@ 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); + if (sObjectType.Contact.fields.Name.isEncrypted()) { + System.assertEquals(null,testDIResultA.Contact1Imported__c); + } else { + System.assertNotEquals(null,testDIResultA.Contact1Imported__c); + } + 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); From c162ceb4a8b886e45fcd0499fc89b5f28c6ac466 Mon Sep 17 00:00:00 2001 From: daniel-fuller Date: Wed, 8 Jan 2025 14:26:34 -0500 Subject: [PATCH 5/5] add comments --- force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls | 2 ++ 1 file changed, 2 insertions(+) diff --git a/force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls b/force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls index 94b6adb3177..b2ee7a55193 100644 --- a/force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls +++ b/force-app/main/default/classes/BDI_DataImportCTRL_TEST.cls @@ -300,11 +300,13 @@ 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); + // 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 {