diff --git a/force-app/main/default/classes/RD2_ERecurringDonationsSelector.cls b/force-app/main/default/classes/RD2_ERecurringDonationsSelector.cls index acff7677a6..db46e46f32 100644 --- a/force-app/main/default/classes/RD2_ERecurringDonationsSelector.cls +++ b/force-app/main/default/classes/RD2_ERecurringDonationsSelector.cls @@ -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 { @@ -50,35 +53,42 @@ public inherited sharing class RD2_ERecurringDonationsSelector { * @description Returns the Recurring Donation records related to the Experience Site user. * @return List */ - public List getRecurringDonations() { + public List getRecurringDonations(String elevateFilter) { + + Id currentContactId = this.currentContactId; + List recurringDonations = new List(); + 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 recurringDonations = new List(); - 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; } } \ No newline at end of file diff --git a/force-app/main/default/classes/RD2_ERecurringDonationsSelector_TEST.cls b/force-app/main/default/classes/RD2_ERecurringDonationsSelector_TEST.cls index d615199b1c..abd767772c 100644 --- a/force-app/main/default/classes/RD2_ERecurringDonationsSelector_TEST.cls +++ b/force-app/main/default/classes/RD2_ERecurringDonationsSelector_TEST.cls @@ -37,7 +37,10 @@ @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 @@ -45,29 +48,94 @@ public class RD2_ERecurringDonationsSelector_TEST { * @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 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 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 result = selector.getRecurringDonations(); + List result = selector.getRecurringDonations(RD2_ERecurringDonationsSelector_TEST.NONELEVATE_RD); Test.stopTest(); System.assertNotEquals(null, result, 'Recurring Donations should not be null'); } -} +} \ No newline at end of file diff --git a/force-app/main/default/classes/RD2_ETableController.cls b/force-app/main/default/classes/RD2_ETableController.cls index a2cad17afc..fc8cb8b3af 100644 --- a/force-app/main/default/classes/RD2_ETableController.cls +++ b/force-app/main/default/classes/RD2_ETableController.cls @@ -95,21 +95,21 @@ public with sharing class RD2_ETableController { } /** - * @description returns a list of processed recurring donations - * @return List List of processed recurring donation records - */ - @AuraEnabled - public static List retrieveTableView() { + * @description returns a list of processed recurring donations + * @return List List of processed recurring donation records + */ + @AuraEnabled(cacheable=true) + public static List 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 { @@ -129,11 +129,11 @@ public with sharing class RD2_ETableController { * @description method to return Recurring Donation list. * @return List returns processed Recurring Donations. */ - private List getTableViews() { + private List getTableViews(String elevateFilter) { List recurringDonations = new List(); 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); } diff --git a/force-app/main/default/classes/RD2_ETableController_TEST.cls b/force-app/main/default/classes/RD2_ETableController_TEST.cls index 5bb9e90d88..bfb09f3b3e 100644 --- a/force-app/main/default/classes/RD2_ETableController_TEST.cls +++ b/force-app/main/default/classes/RD2_ETableController_TEST.cls @@ -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 @@ -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(); @@ -66,7 +67,7 @@ public class RD2_ETableController_TEST { .withAmount(100) .withDefaultValues() .withInstallmentPeriodYearly() - .withDayOfMonth('23') + .withDayOfMonth('22') .withInstallmentFrequency(1) .build(); @@ -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() @@ -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() @@ -111,7 +114,7 @@ public class RD2_ETableController_TEST { RD2_ETableController.selector = (RD2_ERecurringDonationsSelector) Test.createStub(RD2_ERecurringDonationsSelector.class, mock); Test.startTest(); - List result = RD2_ETableController.retrieveTableView(); + List result = RD2_ETableController.retrieveTableView(RD2_ETableController_TEST.ALL_RD); Test.stopTest(); System.assertNotEquals(null, result, 'Recurring Donations should not be null'); @@ -134,6 +137,5 @@ public class RD2_ETableController_TEST { } return objectsToReturn; } - } } diff --git a/force-app/main/default/lwc/rd2RecurringDonation/rd2RecurringDonation.js b/force-app/main/default/lwc/rd2RecurringDonation/rd2RecurringDonation.js index 2fc4da86a1..55ecad1249 100644 --- a/force-app/main/default/lwc/rd2RecurringDonation/rd2RecurringDonation.js +++ b/force-app/main/default/lwc/rd2RecurringDonation/rd2RecurringDonation.js @@ -62,6 +62,7 @@ export default class RecurringDonationTable extends LightningElement { lastDonationDate = ""; labels = { + commonAmount, RDCL_Frequency, lblStatus, @@ -187,8 +188,6 @@ export default class RecurringDonationTable extends LightningElement { } } - //************************************* RESIZABLE COLUMNS *************************************/ - handlemouseup(e) { this._tableThColumn = undefined; this._tableThInnerDiv = undefined; @@ -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"; @@ -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) {