Skip to content

Comments

Cancellation journey page 3 functionality#2309

Merged
gkoos merged 19 commits intodevelopfrom
feature/iwtf-4775-cancel-on-user-request-gk
Feb 19, 2026
Merged

Cancellation journey page 3 functionality#2309
gkoos merged 19 commits intodevelopfrom
feature/iwtf-4775-cancel-on-user-request-gk

Conversation

@gkoos
Copy link
Contributor

@gkoos gkoos commented Feb 16, 2026

irisfaraway and others added 17 commits December 29, 2025 15:28
https://eaflood.atlassian.net/browse/IWTF-4775

When the user confirms that they would like to cancel, the recurring payment should be cancelled in the CRM using the existing cancellation functionality.
https://eaflood.atlassian.net/browse/IWTF-4775

When the user confirms that they would like to cancel, the recurring payment should be cancelled in the CRM using the existing cancellation functionality.

This is PR 2 of 2 to enable that.

This second PR updates the cancellation journey so that the Sales API is called to cancel an agreement when the user confirms they want to do so. It depends on #2276
…-request' into feature/iwtf-4775-cancel-on-user-request-gk
…-request-part-2' into feature/iwtf-4775-cancel-on-user-request-gk
@gkoos gkoos requested review from Copilot and jaucourt February 16, 2026 11:53
@gkoos gkoos requested review from irisfaraway and removed request for Copilot February 16, 2026 11:54
Copilot AI review requested due to automatic review settings February 16, 2026 14:54
@gkoos gkoos review requested due to automatic review settings February 16, 2026 14:56
Copilot AI review requested due to automatic review settings February 18, 2026 12:45
@sonarqubecloud
Copy link

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the sales API recurring payment cancellation behaviour to support the cancellation journey (page 3), by changing how cancelledDate is set based on the cancellation reason.

Changes:

  • Update cancelRecurringPayment to skip setting cancelledDate when reason is "User Cancelled".
  • Update unit tests to reflect the new conditional cancelledDate behaviour.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/sales-api-service/src/services/recurring-payments.service.js Changes cancellation logic to conditionally set cancelledDate based on reason.
packages/sales-api-service/src/services/tests/recurring-payments.service.spec.js Updates/extends tests to validate the new conditional cancelledDate behaviour.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +173 to +178
const isUserCancelled = reason === 'User Cancelled'

if (!isUserCancelled) {
data.cancelledDate = new Date().toISOString().split('T')[0]
}

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancelRecurringPayment no longer sets cancelledDate when the reason is User Cancelled. Because the Dynamics query for “due recurring payments” filters on defra_cancelleddate eq null, leaving cancelledDate as null/undefined means this record can still be treated as active and picked up for future payment runs even though it has a cancellation reason set. To ensure cancellations actually take effect, set cancelledDate for all cancellation reasons (or update the downstream selection logic to also exclude records based on cancelledReason/status).

Suggested change
const isUserCancelled = reason === 'User Cancelled'
if (!isUserCancelled) {
data.cancelledDate = new Date().toISOString().split('T')[0]
}
data.cancelledDate = new Date().toISOString().split('T')[0]

Copilot uses AI. Check for mistakes.
Comment on lines +945 to +975
it('should not set cancelledDate when reason is User Cancelled', async () => {
retrieveGlobalOptionSets.mockReturnValueOnce({
cached: jest.fn().mockResolvedValue({
defra_cancelledreasons: {
options: {
910400003: {
id: 910400003,
label: 'User Cancelled',
description: 'User Cancelled'
}
}
}
})
})

const cancelledReason = { description: 'User Cancelled', id: 910400003, label: 'User Cancelled' }

const recurringPayment = { ...getMockRecurringPayment(), cancelledDate: null }
findById.mockReturnValueOnce(recurringPayment)

getGlobalOptionSetValue.mockReturnValueOnce(cancelledReason)

await cancelRecurringPayment('id', 'User Cancelled')

expect(persist).toHaveBeenCalledWith([
expect.objectContaining({
...recurringPayment,
cancelledReason,
cancelledDate: null
})
])
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test asserts that cancelledDate remains null for the User Cancelled reason. Given the current Dynamics selection logic for due recurring payments relies on cancelledDate being set (it filters for cancelleddate eq null to find active records), this expectation would allow user-cancelled records to continue being processed. Once the service logic is corrected, update this test to assert the intended cancellation behaviour (e.g. cancelledDate is set, or the record is otherwise excluded from due processing).

Copilot uses AI. Check for mistakes.
@gkoos gkoos requested a review from jaucourt February 18, 2026 12:48
Copy link
Collaborator

@jaucourt jaucourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let Iris check this too

@gkoos gkoos merged commit 931bf6f into develop Feb 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants