Skip to content

Commit

Permalink
Merge pull request #6988 from SalesforceFoundation/feature/240__filte…
Browse files Browse the repository at this point in the history
…r_rd_elevate_nonelevate

[W-10874727] - Elevate NonElevate Filter
  • Loading branch information
nadiasanchez authored Jun 29, 2022
2 parents 45c732c + d7a877d commit 7d49cfd
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 73 deletions.
64 changes: 37 additions & 27 deletions force-app/main/default/classes/RD2_ERecurringDonationsSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
*/
public inherited sharing class RD2_ERecurringDonationsSelector {

private final String ELEVATE_RD = 'Elevate Recurring Donations';
private final String NONELEVATE_RD = 'Non-Elevate Recurring Donations';

@TestVisible
private Id currentContactId {
get {
Expand All @@ -50,35 +53,42 @@ public inherited sharing class RD2_ERecurringDonationsSelector {
* @description Returns the Recurring Donation records related to the Experience Site user.
* @return List<npe03__Recurring_Donation__c>
*/
public List<npe03__Recurring_Donation__c> getRecurringDonations() {
public List<npe03__Recurring_Donation__c> getRecurringDonations(String elevateFilter) {

Id currentContactId = this.currentContactId;
List<npe03__Recurring_Donation__c> recurringDonations = new List<npe03__Recurring_Donation__c>();
if(currentContactId != NULL) {
String queryString = 'SELECT npe03__Amount__c, '
+ 'npe03__Installment_Period__c, '
+ 'InstallmentFrequency__c, '
+ 'Day_of_Month__c, '
+ 'Status__c, '
+ 'CommitmentId__c, '
+ 'PaymentMethod__c, '
+ 'CardLast4__c, '
+ 'CardExpirationYear__c, '
+ 'CardExpirationMonth__c, '
+ 'ACH_Last_4__c, '
+ 'npe03__Last_Payment_Date__c, '
+ 'npe03__Installments__c, '
+ 'RecurringType__c, '
+ 'npe03__Date_Established__c, '
+ 'npe03__Next_Payment_Date__c, '
+ 'Lastmodifieddate '
+ 'FROM npe03__Recurring_Donation__c '
+ 'WHERE npe03__Contact__c = \'' + currentContactId + '\' ';

Id currentContactId = this.currentContactId;
List<npe03__Recurring_Donation__c> recurringDonations = new List<npe03__Recurring_Donation__c>();
if(currentContactId != NULL) {
recurringDonations = [ SELECT npe03__Amount__c,
npe03__Installment_Period__c,
InstallmentFrequency__c,
Day_of_Month__c,
Status__c,
CommitmentId__c,
PaymentMethod__c,
CardLast4__c,
CardExpirationYear__c,
CardExpirationMonth__c,
ACH_Last_4__c,
npe03__Last_Payment_Date__c,
npe03__Installments__c,
npe03__Date_Established__c,
RecurringType__c,
npe03__Next_Payment_Date__c,
Lastmodifieddate
FROM npe03__Recurring_Donation__c
WHERE npe03__Contact__c = :currentContactId
AND RecurringType__c IN (:RD2_Constants.RECURRING_TYPE_OPEN, :RD2_Constants.RECURRING_TYPE_FIXED)
WITH SECURITY_ENFORCED
ORDER BY npe03__Next_Payment_Date__c DESC NULLS LAST];
}
if(elevateFilter == ELEVATE_RD) {
queryString += 'AND CommitmentId__c != NULL ';
} else if (elevateFilter == NONELEVATE_RD) {
queryString += 'AND CommitmentId__c = NULL ';
}

queryString += 'WITH SECURITY_ENFORCED ';
queryString += 'ORDER BY npe03__Next_Payment_Date__c DESC NULLS LAST';

recurringDonations = Database.query(queryString);
}
return recurringDonations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,105 @@
@IsTest
public class RD2_ERecurringDonationsSelector_TEST {

private static final TEST_SObjectGateway.RecurringDonationGateway rdGateway = new TEST_SObjectGateway.RecurringDonationGateway();
private static final TEST_SObjectGateway.RecurringDonationGateway rdGateway = new TEST_SObjectGateway.RecurringDonationGateway();
private static final String ALL_RD = 'All Recurring Donations';
private static final String ELEVATE_RD = 'Elevate Recurring Donations';
private static final String NONELEVATE_RD = 'Non-Elevate Recurring Donations';

/**
* @author Salesforce.org
* @date 2022
* @description Method to test that the results are returned correctly
*/
@IsTest
private static void testGetRecurringDonations() {

RD2_EnablementService_TEST.setRecurringDonations2Enabled();
private static void testGetRecurringDonationsAll() {

RD2_EnablementService_TEST.setRecurringDonations2Enabled();

Contact con = UTIL_UnitTestData_TEST.getContact();
insert con;

npe03__Recurring_Donation__c rDonation01 = TEST_RecurringDonationBuilder.constructEnhancedBuilder()
.withContact(con.Id)
.withAmount(100)
.withDefaultValues()
.withInstallmentPeriodMonthly()
.withDayOfMonth('23')
.withInstallmentFrequency(1)
.build();
insert rDonation01;

Test.startTest();
RD2_ERecurringDonationsSelector selector = new RD2_ERecurringDonationsSelector();
selector.currentContactId = con.Id;
List<npe03__Recurring_Donation__c> result = selector.getRecurringDonations(RD2_ERecurringDonationsSelector_TEST.ALL_RD);
Test.stopTest();

System.assertNotEquals(null, result, 'Recurring Donations should not be null');
}

/**
* @author Salesforce.org
* @date 2022
* @description Method to test that the results are returned correctly
*/
@IsTest
private static void testGetRecurringDonationsElevate() {

RD2_EnablementService_TEST.setRecurringDonations2Enabled();

Contact con = UTIL_UnitTestData_TEST.getContact();
insert con;
Contact con = UTIL_UnitTestData_TEST.getContact();
insert con;

npe03__Recurring_Donation__c rDonation01 = TEST_RecurringDonationBuilder.constructEnhancedBuilder()
.withContact(con.Id)
.withAmount(100)
.withDefaultValues()
.withInstallmentPeriodMonthly()
.withDayOfMonth('23')
.withInstallmentFrequency(1)
.build();
rDonation01.CommitmentId__c = '123';
insert rDonation01;

Test.startTest();
RD2_ERecurringDonationsSelector selector = new RD2_ERecurringDonationsSelector();
selector.currentContactId = con.Id;
List<npe03__Recurring_Donation__c> result = selector.getRecurringDonations(RD2_ERecurringDonationsSelector_TEST.ELEVATE_RD);
Test.stopTest();

System.assertNotEquals(null, result, 'Recurring Donations should not be null');
}

/**
* @author Salesforce.org
* @date 2022
* @description Method to test that the results are returned correctly
*/
@IsTest
private static void testGetRecurringDonationsNonElevate() {

RD2_EnablementService_TEST.setRecurringDonations2Enabled();

Contact con = UTIL_UnitTestData_TEST.getContact();
insert con;

npe03__Recurring_Donation__c rDonation01 = TEST_RecurringDonationBuilder.constructEnhancedBuilder()
.withContact(con.Id)
.withAmount(100)
.withDefaultValues()
.withInstallmentPeriodMonthly()
.withDayOfMonth('23')
.withInstallmentFrequency(1)
.build();
.withContact(con.Id)
.withAmount(100)
.withDefaultValues()
.withInstallmentPeriodMonthly()
.withDayOfMonth('23')
.withInstallmentFrequency(1)
.build();
insert rDonation01;

Test.startTest();
RD2_ERecurringDonationsSelector selector = new RD2_ERecurringDonationsSelector();
selector.currentContactId = con.Id;
List<npe03__Recurring_Donation__c> result = selector.getRecurringDonations();
List<npe03__Recurring_Donation__c> result = selector.getRecurringDonations(RD2_ERecurringDonationsSelector_TEST.NONELEVATE_RD);
Test.stopTest();

System.assertNotEquals(null, result, 'Recurring Donations should not be null');
}
}
}
20 changes: 10 additions & 10 deletions force-app/main/default/classes/RD2_ETableController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ public with sharing class RD2_ETableController {
}

/**
* @description returns a list of processed recurring donations
* @return List<TableView> List of processed recurring donation records
*/
@AuraEnabled
public static List<TableView> retrieveTableView() {
* @description returns a list of processed recurring donations
* @return List<TableView> List of processed recurring donation records
*/
@AuraEnabled(cacheable=true)
public static List<TableView> retrieveTableView(String elevateFilter) {
try {
return controller.getTableViews();
return controller.getTableViews(elevateFilter);
} catch (Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
}

/**
* @description upsert a recurring donations record.
*/
* @description upsert a recurring donations record.
*/
@AuraEnabled
public static void upsertDonation(npe03__Recurring_Donation__c recurringDonation) {
try {
Expand All @@ -129,11 +129,11 @@ public with sharing class RD2_ETableController {
* @description method to return Recurring Donation list.
* @return List<RD2_ETableController.TableView> returns processed Recurring Donations.
*/
private List<RD2_ETableController.TableView> getTableViews() {
private List<RD2_ETableController.TableView> getTableViews(String elevateFilter) {
List<RD2_ETableController.TableView> recurringDonations = new List<RD2_ETableController.TableView>();
if(RD2_EnablementService.isRecurringDonations2Enabled) {
if(controller.hasAccessToRecurringDonation()) {
recurringDonations = controller.getProcessedTableViews(selector.getRecurringDonations());
recurringDonations = controller.getProcessedTableViews(selector.getRecurringDonations(elevateFilter));
} else {
throw new UTIL_Permissions.InsufficientPermissionException(Label.commonInsufficientPermissions);
}
Expand Down
16 changes: 9 additions & 7 deletions force-app/main/default/classes/RD2_ETableController_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
public class RD2_ETableController_TEST {

private static final TEST_SObjectGateway.RecurringDonationGateway rdGateway = new TEST_SObjectGateway.RecurringDonationGateway();

private static final String ALL_RD = 'All Recurring Donations';

/**
* @author Salesforce.org
* @date 2022
Expand All @@ -50,14 +51,14 @@ public class RD2_ETableController_TEST {
RD2_EnablementService_TEST.setRecurringDonations2Enabled();

Contact con = UTIL_UnitTestData_TEST.getContact();
insert con;
insert con;

npe03__Recurring_Donation__c rDonation01 = TEST_RecurringDonationBuilder.constructEnhancedBuilder()
.withContact(con.Id)
.withAmount(100)
.withDefaultValues()
.withInstallmentPeriodMonthly()
.withDayOfMonth('23')
.withDayOfMonth('21')
.withInstallmentFrequency(1)
.build();

Expand All @@ -66,7 +67,7 @@ public class RD2_ETableController_TEST {
.withAmount(100)
.withDefaultValues()
.withInstallmentPeriodYearly()
.withDayOfMonth('23')
.withDayOfMonth('22')
.withInstallmentFrequency(1)
.build();

Expand All @@ -84,8 +85,9 @@ public class RD2_ETableController_TEST {
.withAmount(100)
.withDefaultValues()
.withInstallmentPeriodMonthly()
.withDayOfMonth('23')
.withDayOfMonth('24')
.withInstallmentFrequency(2)
.withStatus(RD2_Constants.STATUS_PAUSED)
.build();

npe03__Recurring_Donation__c rDonation05 = TEST_RecurringDonationBuilder.constructEnhancedBuilder()
Expand All @@ -95,6 +97,7 @@ public class RD2_ETableController_TEST {
.withInstallmentPeriodYearly()
.withDayOfMonth('23')
.withInstallmentFrequency(2)
.withStatus(RD2_Constants.STATUS_CLOSED)
.build();

npe03__Recurring_Donation__c rDonation06 = TEST_RecurringDonationBuilder.constructEnhancedBuilder()
Expand All @@ -111,7 +114,7 @@ public class RD2_ETableController_TEST {
RD2_ETableController.selector = (RD2_ERecurringDonationsSelector) Test.createStub(RD2_ERecurringDonationsSelector.class, mock);

Test.startTest();
List<RD2_ETableController.TableView> result = RD2_ETableController.retrieveTableView();
List<RD2_ETableController.TableView> result = RD2_ETableController.retrieveTableView(RD2_ETableController_TEST.ALL_RD);
Test.stopTest();

System.assertNotEquals(null, result, 'Recurring Donations should not be null');
Expand All @@ -134,6 +137,5 @@ public class RD2_ETableController_TEST {
}
return objectsToReturn;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class RecurringDonationTable extends LightningElement {
lastDonationDate = "";

labels = {

commonAmount,
RDCL_Frequency,
lblStatus,
Expand Down Expand Up @@ -187,8 +188,6 @@ export default class RecurringDonationTable extends LightningElement {
}
}

//************************************* RESIZABLE COLUMNS *************************************/

handlemouseup(e) {
this._tableThColumn = undefined;
this._tableThInnerDiv = undefined;
Expand Down Expand Up @@ -223,7 +222,6 @@ export default class RecurringDonationTable extends LightningElement {
handlemousemove(e) {
if (this._tableThColumn && this._tableThColumn.tagName === "TH") {
this._diffX = e.pageX - this._pageX;

this.template.querySelector("table").style.width =
this.template.querySelector("table") - this._diffX + "px";

Expand Down Expand Up @@ -329,21 +327,13 @@ export default class RecurringDonationTable extends LightningElement {
}

getRecurringDonationFields() {
retrieveTableView().then((data) => {
retrieveTableView({elevateFilter:this.donationTypeFilter}).then((data) => {
if (data) {
this.data = data.map((el) => {
let isElevate = el.recurringDonation.CommitmentId__c ? true : false;
let actions = this.actions
.filter((el) => {
if (el.name !== "updatePaymentMethod" && !isElevate) {
return el;
} else if (isElevate) {
return el;
}
})
.map((a) => {
return { ...a };
});
.filter((elo) => (elo.name !== "updatePaymentMethod" && !isElevate) || (isElevate))
.map((action) => { return { ...action }; });
let nexDonationFormatFirstElement = "";
let nexDonationFormatSecondElement = "";
if (el.nextDonation) {
Expand Down

0 comments on commit 7d49cfd

Please sign in to comment.