-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add replace options (hardcoded, value from dictionary) (#11)
* Add new fields to flexipage * Add replace dictionary for firstname, lastname, fullname * Fix error on MaskSObjectUtils.executeBatch method * Remove WIP mention on Launch Batch LWC * Add demo data to md * Clarify sobjects description * fix typo * Increase coverage and init dictionary only if needed Co-authored-by: Thomas Prouvot <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,228 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ public class MaskSObjectBatchTest { | |
private static String PHONE = '0606060606'; | ||
private static String LASTNAME = 'Doe'; | ||
private static String ASSISTANTNAME = 'Jane DOE'; | ||
private static String TESTLABEL = 'TEST'; | ||
private static String EMAIL = '[email protected]'; | ||
|
||
/** | ||
|
@@ -14,21 +15,31 @@ public class MaskSObjectBatchTest { | |
public static void createTestData(){ | ||
List<MaskSObject__c> sobjMask = new List<MaskSObject__c>{ | ||
new MaskSObject__c(Sequence__c = 1, APIName__c = 'Account'), | ||
new MaskSObject__c(Sequence__c = 2, APIName__c = 'Contact', WhereClause__c = 'AssistantName != null') | ||
new MaskSObject__c(Sequence__c = 2, APIName__c = 'Contact', WhereClause__c = 'AssistantName != null', BatchSize__c = 1600) | ||
}; | ||
insert sobjMask; | ||
|
||
List<MaskSObjectField__c> fieldMask = new List<MaskSObjectField__c>{ | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(0).Id, APIName__c = 'Name', Action__c = MaskSObjectConstants.ACTION_OBFUSCATE), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(0).Id, APIName__c = 'Phone', Action__c = MaskSObjectConstants.ACTION_OBFUSCATE), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(1).Id, APIName__c = 'LastName', Action__c = MaskSObjectConstants.ACTION_OBFUSCATE), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(1).Id, APIName__c = 'AssistantName', Action__c = MaskSObjectConstants.ACTION_ERASE), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(1).Id, APIName__c = 'Email', Action__c = MaskSObjectConstants.ACTION_RANDOMIZE) | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(0).Id, APIName__c = 'Name', | ||
Action__c = MaskSObjectConstants.ACTION_OBFUSCATE), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(0).Id, APIName__c = 'Phone', | ||
Action__c = MaskSObjectConstants.ACTION_OBFUSCATE), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(1).Id, APIName__c = 'FirstName', | ||
Action__c = MaskSObjectConstants.ACTION_REPLACE, ActionType__c = MaskSObjectConstants.ACTION_TYPE_DICT_FIRST), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(1).Id, APIName__c = 'LastName', | ||
Action__c = MaskSObjectConstants.ACTION_REPLACE, ActionType__c = MaskSObjectConstants.ACTION_TYPE_DICT_LAST), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(1).Id, APIName__c = 'AssistantName', | ||
Action__c = MaskSObjectConstants.ACTION_REPLACE, ActionType__c = MaskSObjectConstants.ACTION_TYPE_HARDCODED, | ||
Value__c = TESTLABEL), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(1).Id, APIName__c = 'HomePhone', | ||
Action__c = MaskSObjectConstants.ACTION_ERASE), | ||
new MaskSObjectField__c(MaskSObject__c = sobjMask.get(1).Id, APIName__c = 'Email', | ||
Action__c = MaskSObjectConstants.ACTION_RANDOMIZE) | ||
}; | ||
insert fieldMask; | ||
|
||
insert new Account(Name = NAME, Phone = PHONE); | ||
insert new Contact(FirstName = 'John', LastName = LASTNAME, AssistantName = ASSISTANTNAME, Email = EMAIL); | ||
insert new Contact(FirstName = 'John', LastName = LASTNAME, AssistantName = ASSISTANTNAME, Email = EMAIL, HomePhone = '0606060606'); | ||
} | ||
|
||
@isTest | ||
|
@@ -43,28 +54,29 @@ public class MaskSObjectBatchTest { | |
System.assertNotEquals(NAME, acc.Name, 'The account name should be masked'); | ||
System.assertNotEquals(PHONE, acc.Phone, 'The account phone should be masked'); | ||
|
||
Contact cont = [SELECT Id, LastName, AssistantName, Email FROM Contact LIMIT 1]; | ||
Contact cont = [SELECT Id, FirstName, LastName, AssistantName, Email, HomePhone FROM Contact LIMIT 1]; | ||
System.assertNotEquals(LASTNAME, cont.FirstName, 'The contact firstname should be masked'); | ||
System.assertNotEquals(LASTNAME, cont.LastName, 'The contact lastname should be masked'); | ||
System.assertNotEquals(ASSISTANTNAME, cont.AssistantName, 'The contact AssistantName should be masked'); | ||
System.assertEquals(TESTLABEL, cont.AssistantName, 'The contact AssistantName should be replaced by ' + TESTLABEL); | ||
System.assertNotEquals(EMAIL, cont.Email, 'The contact Email should be masked'); | ||
System.assertEquals(null, cont.HomePhone, 'The contact HomePhone should be erased'); | ||
} | ||
|
||
@isTest | ||
static void maskSobjectNameTest(){ | ||
createTestData(); | ||
|
||
Test.startTest(); | ||
Database.executeBatch(new MaskSObjectBatch('Contact')); | ||
MaskSObjectUtils.executeBatch('Contact'); | ||
Test.stopTest(); | ||
|
||
Contact cont = [SELECT Id, LastName, AssistantName, Email FROM Contact LIMIT 1]; | ||
System.assertNotEquals(LASTNAME, cont.LastName, 'The contact lastname should be masked'); | ||
System.assertNotEquals(ASSISTANTNAME, cont.AssistantName, 'The contact AssistantName should be masked'); | ||
System.assertEquals(TESTLABEL, cont.AssistantName, 'The contact AssistantName should be replaced by ' + TESTLABEL); | ||
System.assertNotEquals(EMAIL, cont.Email, 'The contact Email should be masked'); | ||
|
||
Account acc = [SELECT Id, Name, Phone FROM Account LIMIT 1]; | ||
System.assertEquals(NAME, acc.Name, 'The account name should not be masked'); | ||
System.assertEquals(PHONE, acc.Phone, 'The account phone should not be masked'); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
force-app/main/default/classes/MaskSObjectDictionaryModel.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public with sharing class MaskSObjectDictionaryModel { | ||
|
||
public String firstName; | ||
public String lastName; | ||
public String phone; | ||
public String email; | ||
public String streetNumber; | ||
public String street; | ||
public String city; | ||
public String country; | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/MaskSObjectDictionaryModel.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>55.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.