diff --git a/app/controllers/providers/confirm_dwp_non_passported_applications_controller.rb b/app/controllers/providers/confirm_dwp_non_passported_applications_controller.rb index 7dd384cbb5..ea605eb7b5 100644 --- a/app/controllers/providers/confirm_dwp_non_passported_applications_controller.rb +++ b/app/controllers/providers/confirm_dwp_non_passported_applications_controller.rb @@ -14,6 +14,7 @@ def update @form = Providers::ConfirmDWPNonPassportedApplicationsForm.new(form_params) if @form.valid? + remove_dwp_override if correct_dwp_result? update_joint_benefit_response update_application_state HMRC::CreateResponsesService.call(legal_aid_application) if make_hmrc_call? @@ -25,6 +26,10 @@ def update private + def remove_dwp_override + legal_aid_application.dwp_override&.destroy! + end + def partner @partner = legal_aid_application.partner end diff --git a/spec/requests/providers/confirm_dwp_non_passported_applications_controller_spec.rb b/spec/requests/providers/confirm_dwp_non_passported_applications_controller_spec.rb index 722a78c6e9..f178a9e451 100644 --- a/spec/requests/providers/confirm_dwp_non_passported_applications_controller_spec.rb +++ b/spec/requests/providers/confirm_dwp_non_passported_applications_controller_spec.rb @@ -122,6 +122,12 @@ patch_request expect(HMRC::CreateResponsesService).to have_received(:call).once end + + it "successfully deletes any existing dwp override" do + create(:dwp_override, legal_aid_application: application) + patch_request + expect(application.reload.dwp_override).to be_nil + end end context "and the solicitor wants to override the results with a non joint benefit" do