Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression fixes for 238 Release #6928

Merged
merged 9 commits into from
Apr 15, 2022
21 changes: 20 additions & 1 deletion force-app/main/default/classes/HH_Container_LCTRL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ public with sharing class HH_Container_LCTRL {
// so we avoid deleting a household if that contact was the last one in the hh.
if (isNotEmpty(listHHMerge)) {
mergeHouseholds((Account)hh, listHHMerge);
updateWinnerHouseholdSustainerAfterMerge((Account)hh);
}

List<Contact> contacts = new List<Contact>(listCon);
Expand All @@ -531,7 +532,25 @@ public with sharing class HH_Container_LCTRL {
if (isNotEmpty(listHHMerge)) {
cleanupAddresses(new List<Id>{ (Id) hh.get('Id') });
}
}
}

private static void updateWinnerHouseholdSustainerAfterMerge(Account winnerHousehold) {
DescribeFieldResult sustainerFieldDescribeResult = Account.Sustainer__c.getDescribe();

if (UTIL_Permissions.canRead(sustainerFieldDescribeResult, false)
&& UTIL_Permissions.canUpdate(sustainerFieldDescribeResult, false)
) {
List<Account> winnerWithSustainerChanged = new RD2_SustainerEvaluationService()
.withAccounts(new List<Account>{winnerHousehold})
.getAccountsWithSustainerChanged();

if (winnerWithSustainerChanged.size() != 0) {
RD2_SustainerEvaluationService.setSustainerUpdateEnabled(true);
UTIL_DMLService.updateRecords(winnerWithSustainerChanged);
RD2_SustainerEvaluationService.setSustainerUpdateEnabled(false);
}
}
}

/*******************************************************************************************************
* @description Checks if the Account list is not empty
Expand Down
52 changes: 51 additions & 1 deletion force-app/main/default/classes/HH_Container_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,56 @@ private class HH_Container_TEST {

}

@IsTest
private static void shouldUpdateHouseholdSustainerAfterMergingContacts() {
//skip the test if Advancement is installed
if(ADV_PackageInfo_SVC.useAdv()) return;
RD2_EnablementService_TEST.setRecurringDonations2Enabled();

List<Account> householdAccounts = buildAccounts(2);
insert householdAccounts;

List<Contact> contacts = buildContacts(householdAccounts, 1);
insert contacts;

insert new List<npe03__Recurring_Donation__c> {
TEST_RecurringDonationBuilder.constructEnhancedBuilder()
.withDefaultValues()
.withStatusClosed()
.withContact(contacts[0].Id)
.withAmount(1)
.build(),

TEST_RecurringDonationBuilder.constructEnhancedBuilder()
.withDefaultValues()
.withStatusActive()
.withContact(contacts[1].Id)
.withAmount(1)
.build()
};

householdAccounts[0] = (Account) HH_Container_LCTRL.getHousehold(householdAccounts[0].Id);

for (Contact contact : contacts) {
contact.AccountId = householdAccounts[0].Id;
}

Test.startTest();
HH_Container_LCTRL.saveHouseholdPage(householdAccounts[0], contacts, new List<Contact>(), new List<Account>{householdAccounts[1]});
Test.stopTest();

List<npe03__Recurring_Donation__c> rds = [SELECT npe03__Organization__c, npe03__Contact__c FROM npe03__Recurring_Donation__c];
List<Account> accounts = getAccounts();

for (npe03__Recurring_Donation__c rd : rds) {
System.assertEquals(householdAccounts[0].Id, rd.npe03__Organization__c,
'All Recurring Donations should be reparent to the winning household if the old household is merged');
}

System.assertEquals(RD2_SustainerEvaluationService.SustainerType.Active.name(), accounts[0].Sustainer__c,
'The winning household Account should be mark as Active Sustainer when there is an Active RD attached to it.');
}

// Helpers
////////////

Expand Down Expand Up @@ -906,7 +956,7 @@ private class HH_Container_TEST {
private static Account[] getAccounts() {
return [
SELECT Name, BillingStreet, BillingCity,
BillingState, BillingPostalCode, BillingCountry
BillingState, BillingPostalCode, BillingCountry, Sustainer__c
FROM Account
];
}
Expand Down
11 changes: 7 additions & 4 deletions force-app/main/default/classes/PS_ProductMetadata.cls
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ public inherited sharing class PS_ProductMetadata {
return this.origin?.type != null;
}

public Map<String, Object> mergeWithExistingMetadata(Map<String, Object> existingMetadata) {
public Map<String, Object> mergeWithExistingMetadata(final Map<String, Object> existingMetadata) {
Map<String, Object> updatedMetadata = this.toUntypedMap();
Map<String, Object> mergedMetadata = new Map<String, Object>();

for(String key : updatedMetadata.keySet()) {
existingMetadata.put(key, updatedMetadata.get(key));
if (existingMetadata != null) {
mergedMetadata.putAll(existingMetadata);
}

return existingMetadata;
mergedMetadata.putAll(updatedMetadata);

return mergedMetadata;
}

public Map<String, Object> toUntypedMap() {
Expand Down
20 changes: 17 additions & 3 deletions force-app/main/default/classes/PS_ProductMetadata_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private with sharing class PS_ProductMetadata_TEST {
*/
@isTest
private static void shouldCreateUntypedMap() {
String campaignId = '701R00000027JNdIAA';
String campaignId = UTIL_UnitTestData_TEST.mockId(Campaign.SObjectType);
String originType = PS_Request.OriginType.CRM.name();

PS_ProductMetadata productMetadata = new PS_ProductMetadata()
Expand Down Expand Up @@ -75,7 +75,7 @@ private with sharing class PS_ProductMetadata_TEST {

@IsTest
static void productMetadataShouldPreserveOrigin() {
String newCampaignId = '701R00000027JNdIAA';
String newCampaignId = UTIL_UnitTestData_TEST.mockId(Campaign.SObjectType);
String serializedProductMetadata = '{"origin":{"type":"CRM"},"campaign":{"id":"701R00000027JNdIAM"}}';
Map<String, Object> untypedMetadata = (Map<String, Object>) JSON.deserializeUntyped(serializedProductMetadata);

Expand All @@ -90,7 +90,7 @@ private with sharing class PS_ProductMetadata_TEST {

@IsTest
static void productMetadataShouldPreserveAny() {
String newCampaignId = '701R00000027JNdIAA';
String newCampaignId = UTIL_UnitTestData_TEST.mockId(Campaign.SObjectType);
String serializedProductMetadata = '{"origin":{"type":"CRM"},"campaign":{"id":"701R00000027JNdIAM"},"consent":{"message":"Some message","optin":true}}';
Map<String, Object> untypedMetadata = (Map<String, Object>) JSON.deserializeUntyped(serializedProductMetadata);

Expand All @@ -111,6 +111,20 @@ private with sharing class PS_ProductMetadata_TEST {
System.assertEquals(true, optin);
}

@IsTest
static void productMetadataShouldMergeWhenExistingMetadataIsNull() {
String newCampaignId = UTIL_UnitTestData_TEST.mockId(Campaign.SObjectType);
PS_ProductMetadata productMetadata = new PS_ProductMetadata().withCampaign(newCampaignId);

Test.startTest();
Map<String, Object> updatedUntypedMetadata = productMetadata.mergeWithExistingMetadata(null);
Test.stopTest();

PS_ProductMetadata updatedMetadata = parseUntypedMetadata(updatedUntypedMetadata);

System.assertEquals(newCampaignId, updatedMetadata.campaign.id);
}

/**
* @param untypedProductMetadata Parse origin and campaign out of productMetadata Map<String, Object>
*
Expand Down
2 changes: 2 additions & 0 deletions force-app/main/default/classes/RD2_SaveRequest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public with sharing class RD2_SaveRequest {
@AuraEnabled public String cardLastFour {get; set;}
@AuraEnabled public String cardExpirationMonth {get; set;}
@AuraEnabled public String cardExpirationYear {get; set;}
@AuraEnabled public String changeType {get; set;}
@AuraEnabled public Map<String, Object> customFieldValues {get; set;}

public npe03__Recurring_Donation__c toRecord() {
Expand Down Expand Up @@ -89,6 +90,7 @@ public with sharing class RD2_SaveRequest {
rd.CardExpirationYear__c = cardExpirationYear;
rd.CardLast4__c = cardLastFour;
rd.ACH_Last_4__c = achLastFour;
rd.ChangeType__c = changeType;

if (customFieldValues != null) {
for (String fieldApiName : customFieldValues.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ describe("c-rd2-entry-form", () => {
cardExpirationYear: null,
cardLastFour: null,
campaignId: null,
changeType: "",
commitmentId: null,
currencyIsoCode: null,
dayOfMonth: "15",
Expand Down Expand Up @@ -368,6 +369,7 @@ describe("c-rd2-entry-form", () => {
cardExpirationMonth: null,
cardExpirationYear: null,
cardLastFour: null,
changeType: "",
campaignId: null,
commitmentId: "ffd252d6-7ffc-46a0-994f-00f7582263d2",
currencyIsoCode: null,
Expand Down Expand Up @@ -687,6 +689,7 @@ describe("c-rd2-entry-form", () => {
cardExpirationYear: null,
cardLastFour: null,
campaignId: null,
changeType: "",
commitmentId: "ffd252d6-7ffc-46a0-994f-00f7582263d2",
currencyIsoCode: null,
dayOfMonth: "6",
Expand Down Expand Up @@ -764,6 +767,7 @@ describe("c-rd2-entry-form", () => {
cardExpirationMonth: "05",
cardExpirationYear: "2023",
cardLastFour: "1111",
changeType: "",
campaignId: null,
commitmentId: "ffd252d6-7ffc-46a0-994f-00f7582263d2",
currencyIsoCode: null,
Expand Down Expand Up @@ -849,14 +853,14 @@ describe("c-rd2-entry-form", () => {
it("open donation, when form loads, change type picklist is empty", async () => {
const changeTypePicklist = controller.changeTypePicklist();
expect(changeTypePicklist).toBeTruthy();
expect(changeTypePicklist.value).toBe("");
expect(changeTypePicklist.getValue()).toBe("");
});

it("open donation, when amount increased, sets change type to upgrade", async () => {
controller.amount().changeValue(5);
await flushPromises();
const changeTypePicklist = controller.changeTypePicklist();
expect(changeTypePicklist.value).toBe("Upgrade");
expect(changeTypePicklist.getValue()).toBe("Upgrade");
});

it("open donation, when frequency changed from monthly to weekly, sets change type to upgrade", async () => {
Expand All @@ -865,26 +869,68 @@ describe("c-rd2-entry-form", () => {
controller.installmentPeriod().changeValue("Weekly");
await flushPromises();
const changeTypePicklist = controller.changeTypePicklist();
expect(changeTypePicklist.value).toBe("Upgrade");
expect(changeTypePicklist.getValue()).toBe("Upgrade");
});

it("open donation, when amount decreased, sets change type to downgrade", async () => {
controller.amount().changeValue(0.25);
await flushPromises();
const changeTypePicklist = controller.changeTypePicklist();
expect(changeTypePicklist.value).toBe("Downgrade");
expect(changeTypePicklist.getValue()).toBe("Downgrade");
});

it("open donation, when amount changed and recurring type changed to fixed, blanks change type picklist", async () => {
controller.amount().changeValue(5);
await flushPromises();

const changeTypePicklist = controller.changeTypePicklist();
expect(changeTypePicklist.value).toBe("Upgrade");
expect(changeTypePicklist.getValue()).toBe("Upgrade");
controller.recurringType().changeValue("Fixed");
await flushPromises();

expect(changeTypePicklist.value).toBe("");
expect(changeTypePicklist.getValue()).toBe("");
});

it("open donation, persists manual change to change type picklist", async () => {
controller.amount().changeValue(5);
await flushPromises();

const changeTypePicklist = controller.changeTypePicklist();
expect(changeTypePicklist.getValue()).toBe("Upgrade");

changeTypePicklist.changeValue("Downgrade");
controller.dayOfMonth().changeValue(3);
await flushPromises();

controller.saveButton().click();
expect(saveRecurringDonation).toHaveBeenCalled();
const saveRequest = {
achLastFour: null,
accountId: "00163000010jyT6AAI",
cardExpirationMonth: null,
cardExpirationYear: null,
cardLastFour: null,
changeType: "Downgrade",
campaignId: null,
commitmentId: null,
currencyIsoCode: null,
customFieldValues: {},
dayOfMonth: 3,
paymentToken: null,
recordId: "a09S000000HAfRHIA1",
recordName: "",
recurringFrequency: 1,
recurringType: "Open",
recurringStatus: "Active",
startDate: "2021-04-29",
donationValue: 5,
contactId: "001fakeContactId",
dateEstablished: "2021-04-29",
recurringPeriod: "Monthly",
plannedInstallments: null,
statusReason: null,
};
expect(saveRecurringDonation).toHaveBeenCalledWith({ saveRequest });
});
});

Expand Down Expand Up @@ -930,15 +976,15 @@ describe("c-rd2-entry-form", () => {
await flushPromises();
const changeTypePicklist = controller.changeTypePicklist();

expect(changeTypePicklist.value).toBe("Upgrade");
expect(changeTypePicklist.getValue()).toBe("Upgrade");
});

it("fixed donation, when number of planned installments decreased, sets change type to downgrade", async () => {
controller.plannedInstallments().changeValue(6);
await flushPromises();
const changeTypePicklist = controller.changeTypePicklist();

expect(changeTypePicklist.value).toBe("Downgrade");
expect(changeTypePicklist.getValue()).toBe("Downgrade");
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ export class RD2FormController {
}

changeTypePicklist() {
return this.element.shadowRoot.querySelector('lightning-input-field[data-id="changeType"]');
const field = this.element.shadowRoot.querySelector('lightning-input-field[data-id="changeType"]');
return new RD2FormField(field);
}

errorPageLevelMessage() {
Expand Down
2 changes: 1 addition & 1 deletion force-app/main/default/lwc/rd2EntryForm/rd2EntryForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export default class rd2EntryForm extends LightningElement {
handleChangeTypeChange(event) {
this.perform({
type: ACTIONS.SET_CHANGE_TYPE,
payload: event.detail,
payload: event.detail.value,
});
}

Expand Down
12 changes: 11 additions & 1 deletion force-app/main/default/lwc/rd2Service/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SET_CONTACT_DETAILS,
SET_CURRENCY,
SET_ACCOUNT_DETAILS,
SET_CHANGE_TYPE,
SET_DAY_OF_MONTH,
SET_DONATION_AMOUNT,
SET_DONOR_TYPE,
Expand Down Expand Up @@ -146,7 +147,7 @@ const getChangeType = (state) => {
return CHANGE_TYPE_UPGRADE;
}

return "";
return state.changeType;
};

const isAdvancedPeriod = (state) => {
Expand Down Expand Up @@ -260,6 +261,13 @@ const setAccountDetails = (state, { accountName, lastName }) => {
};
};

const setChangeType = (state, changeType) => {
return {
...state,
changeType,
};
};

const setDonationAmount = (state, donationValue) => {
const newState = { ...state, donationValue };
return {
Expand Down Expand Up @@ -446,6 +454,8 @@ export const nextState = (state = DEFAULT_INITIAL_STATE, action = {}) => {
return setCurrency(state, action.payload);
case SET_ACCOUNT_DETAILS:
return setAccountDetails(state, action.payload);
case SET_CHANGE_TYPE:
return setChangeType(state, action.payload);
case SET_DAY_OF_MONTH:
return setDayOfMonth(state, action.payload);
case SET_DONATION_AMOUNT:
Expand Down
Loading