From c4c73cf90c8332a9593c840ba7180142fefef790 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Tue, 16 Jan 2024 10:17:58 -0600 Subject: [PATCH] Include day of month when updating the start month --- src/common/models/recurringGift.model.js | 10 ++++++++- src/common/models/recurringGift.model.spec.js | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/common/models/recurringGift.model.js b/src/common/models/recurringGift.model.js index bffbe92cf..8c5cd77bb 100644 --- a/src/common/models/recurringGift.model.js +++ b/src/common/models/recurringGift.model.js @@ -201,7 +201,15 @@ export default class RecurringGiftModel { } get toObject () { - return this.gift + if (this.gift['updated-start-month'] === '') { + return this.gift + } + + // When the start month changes the server needs the recurring day of month even if it didn't change + return { + ...this.gift, + 'updated-recurring-day-of-month': this.gift['updated-recurring-day-of-month'] || this.parentDonation['recurring-day-of-month'] + } } clone () { diff --git a/src/common/models/recurringGift.model.spec.js b/src/common/models/recurringGift.model.spec.js index 20a2aa913..6104b0039 100644 --- a/src/common/models/recurringGift.model.spec.js +++ b/src/common/models/recurringGift.model.spec.js @@ -564,6 +564,27 @@ describe('recurringGift model', () => { it('should return the object to send to the api', () => { expect(giftModel.toObject).toEqual(giftModel.gift) }) + + it('should include the recurring day of month when the month changes', () => { + giftModel.startMonth = '6' + expect(giftModel.toObject).toEqual({ + ...giftModel.gift, + 'updated-recurring-day-of-month': '15', + 'updated-start-month': '06', + 'updated-start-year': '2015', + }) + }) + + it('should not override the modified recurring day of month when the month changes', () => { + giftModel.transactionDay = '20' + giftModel.startMonth = '6' + expect(giftModel.toObject).toEqual({ + ...giftModel.gift, + 'updated-recurring-day-of-month': '20', + 'updated-start-month': '06', + 'updated-start-year': '2015', + }) + }) }) describe('clone', () => {