diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 219b507955..a15603cfbe 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -23,7 +23,8 @@ def form_params :allow_welsh_translation, :enable_ccms_submission, :partner_means_assessment, - :linked_applications) + :linked_applications, + :collect_hmrc_data) end def setting 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 ea605eb7b5..20508c4ddc 100644 --- a/app/controllers/providers/confirm_dwp_non_passported_applications_controller.rb +++ b/app/controllers/providers/confirm_dwp_non_passported_applications_controller.rb @@ -70,7 +70,7 @@ def correct_dwp_result? end def hmrc_call_enabled? - Rails.configuration.x.collect_hmrc_data + Setting.collect_hmrc_data? end def make_hmrc_call? diff --git a/app/forms/settings/setting_form.rb b/app/forms/settings/setting_form.rb index fffea2d940..ba9f9c1e67 100644 --- a/app/forms/settings/setting_form.rb +++ b/app/forms/settings/setting_form.rb @@ -7,7 +7,8 @@ class SettingForm < BaseForm :allow_welsh_translation, :enable_ccms_submission, :partner_means_assessment, - :linked_applications + :linked_applications, + :collect_hmrc_data validates :mock_true_layer_data, :manually_review_all_cases, @@ -15,6 +16,7 @@ class SettingForm < BaseForm :enable_ccms_submission, :partner_means_assessment, :linked_applications, + :collect_hmrc_data, presence: true end end diff --git a/app/models/setting.rb b/app/models/setting.rb index 58d4572440..4a0c330e4c 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -31,6 +31,10 @@ def self.linked_applications? setting.linked_applications end + def self.collect_hmrc_data? + setting.collect_hmrc_data + end + def self.setting Setting.first || Setting.create! end diff --git a/app/views/admin/settings/show.html.erb b/app/views/admin/settings/show.html.erb index 1a0a544096..c8a4c7190a 100644 --- a/app/views/admin/settings/show.html.erb +++ b/app/views/admin/settings/show.html.erb @@ -66,6 +66,16 @@ legend: { text: t(".labels.linked_applications") }, ) %> + <%= form.govuk_collection_radio_buttons( + :collect_hmrc_data, + yes_no_options, + :value, + :label, + inline: true, + hint: { text: t(".hints.collect_hmrc_data") }, + legend: { text: t(".labels.collect_hmrc_data") }, + ) %> + <%= form.govuk_submit(t("generic.submit")) %> <% end %> <% end %> diff --git a/app/views/providers/means/full_employment_details/show.html.erb b/app/views/providers/means/full_employment_details/show.html.erb index 6987d18109..fcf88a21d4 100644 --- a/app/views/providers/means/full_employment_details/show.html.erb +++ b/app/views/providers/means/full_employment_details/show.html.erb @@ -1,4 +1,6 @@ -<% suffix = if !@legal_aid_application.applicant.national_insurance_number? +<% suffix = if !Setting.collect_hmrc_data? + :hmrc_data_collection_off + elsif !@legal_aid_application.applicant.national_insurance_number? :no_nino elsif @legal_aid_application.applicant.has_multiple_employments? :multiple_employments diff --git a/config/environments/development.rb b/config/environments/development.rb index 14c04faa1d..dabdb9fbfc 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -66,7 +66,4 @@ config.active_storage.service = :local config.x.application.host_url = "http://#{config.x.application.host}" - - # Switch to determine whether or not o collect HMRC data - config.x.collect_hmrc_data = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index 1973bb81aa..ad0c0b6970 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -97,7 +97,4 @@ # set the id of the Digest Export spreadsheet to use in this environment config.x.digest_export.spreadsheet_id = "1dXnEdiqqP_fOeWzDsbXY83lwwK8pvf8j4jsUqaGnGMs" - - # Switch to determine whether or not o collect HMRC data - config.x.collect_hmrc_data = true end diff --git a/config/environments/test.rb b/config/environments/test.rb index 6ee18bb946..016a7a0daa 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -74,9 +74,6 @@ # set the id of the Digest Export spreadsheet to use in this environment config.x.digest_export.spreadsheet_id = "1dXnEdiqqP_fOeWzDsbXY83lwwK8pvf8j4jsUqaGnGMs" - # Switch to determine whether or not o collect HMRC data - config.x.collect_hmrc_data = true - # This needs adding due to a rails 7.1.1 bug(?!) related to Unsafe threading and AR connection pool issues # see https://github.com/rails/rails/issues/46797 for a good description config.active_job.queue_adapter = :test diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 1da7245138..7daa1bfc94 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -74,6 +74,7 @@ en: enable_evidence_upload: Enable the new evidence upload feature partner_means_assessment: Enable Partner Means Assessment linked_applications: Enable linked applications + collect_hmrc_data: Collect HMRC data hints: mock_true_layer_data: Select Yes and TrueLayer data will be replaced by mock data from %{bank_transaction_filename} manually_review_all_cases: | @@ -84,6 +85,7 @@ en: enable_evidence_upload: Select Yes to enable the new evidence upload feature for solicitors partner_means_assessment: Select Yes to allow Providers to complete the Partner Means Assessment linked_applications: Select Yes to enable the linked applications feature for solicitors + collect_hmrc_data: Select Yes to enable calls to HMRC for employment data update: notice: Settings have been updated submitted_applications_reports: diff --git a/config/locales/en/shared.yml b/config/locales/en/shared.yml index 67024060a0..099f1c6791 100644 --- a/config/locales/en/shared.yml +++ b/config/locales/en/shared.yml @@ -922,9 +922,11 @@ en: page_heading_no_data: HMRC has no record of %{individual}'s employment in the last 3 months page_heading_multiple_employments: HMRC found a record of %{individual}'s employment page_heading_no_nino: We could not check %{individual}'s employment record with HMRC + page_heading_hmrc_data_collection_off: Enter details of your client's employment in the last 3 months info_no_data: You told us %{individual} is employed but HMRC could not confirm this. info_multiple_employments: HMRC says %{individual} had more than one job in the last 3 months. info_no_nino: Because you did not give us %{individual}'s National Insurance number, we could not check this with HMRC. + info_hmrc_data_collection_off: We cannot currently check employment records automatically with HMRC. enter_details_client: "Enter details of your client's employment in the last 3 months, including:" enter_details_partner: "You must give the partner's employment details for the last 3 months, including:" details: diff --git a/db/migrate/20240124161717_add_collect_hmrc_data_to_settings.rb b/db/migrate/20240124161717_add_collect_hmrc_data_to_settings.rb new file mode 100644 index 0000000000..371ed70ad1 --- /dev/null +++ b/db/migrate/20240124161717_add_collect_hmrc_data_to_settings.rb @@ -0,0 +1,5 @@ +class AddCollectHMRCDataToSettings < ActiveRecord::Migration[7.1] + def change + add_column :settings, :collect_hmrc_data, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 0c4a773b8e..66bbb6d671 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_12_05_180352) do +ActiveRecord::Schema[7.1].define(version: 2024_01_24_161717) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -947,6 +947,7 @@ t.boolean "partner_means_assessment", default: false, null: false t.datetime "cfe_compare_run_at" t.boolean "linked_applications", default: false, null: false + t.boolean "collect_hmrc_data", default: false, null: false end create_table "specific_issues", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/features/providers/check_multiple_employment.feature b/features/providers/check_multiple_employment.feature index 621f2c95fa..c1be298b25 100644 --- a/features/providers/check_multiple_employment.feature +++ b/features/providers/check_multiple_employment.feature @@ -2,6 +2,7 @@ Feature: Check multiple employment @javascript @vcr @hmrc_use_dev_mock Scenario: I am able to complete an application for an employed applicant with multiple employers Given I am logged in as a provider + And the feature flag for collect_hmrc_data is enabled And csrf is enabled And an applicant named Ida Paisley has completed his true layer interaction diff --git a/features/providers/check_pending_employment.feature b/features/providers/check_pending_employment.feature index 5e5b11c01d..1b8e22c665 100644 --- a/features/providers/check_pending_employment.feature +++ b/features/providers/check_pending_employment.feature @@ -2,6 +2,7 @@ Feature: Check pending employment @javascript @vcr @hmrc_use_dev_mock Scenario: I am able to complete an application for an employed applicant with pending HMRC request Given I am logged in as a provider + And the feature flag for collect_hmrc_data is enabled And csrf is enabled And an applicant named John Pending has completed his true layer interaction diff --git a/features/providers/employed_journey.feature b/features/providers/employed_journey.feature index 572fca24d7..c2703dfdba 100644 --- a/features/providers/employed_journey.feature +++ b/features/providers/employed_journey.feature @@ -35,6 +35,7 @@ Scenario: Completing the means journey for an employed applicant with HMRC data @javascript Scenario: Completing the means journey for an employed applicant with no HMRC data Given I start the means review journey with no employment income from HMRC + And the feature flag for collect_hmrc_data is enabled Then I should be on the 'client_completed_means' page showing 'Your client has shared their financial information' When I click 'Continue' Then I should be on the 'full_employment_details' page showing "HMRC has no record of your client's employment in the last 3 months" @@ -63,6 +64,7 @@ Scenario: Completing the means journey for an employed applicant with no HMRC da @javascript Scenario: Completing the means journey for an employed applicant with multiple jobs Given I start the means review journey with employment income for multiple jobs from HMRC + And the feature flag for collect_hmrc_data is enabled Then I should be on the 'client_completed_means' page showing 'Your client has shared their financial information' When I click 'Continue' Then I should be on the 'full_employment_details' page showing "HMRC says your client had more than one job in the last 3 months." diff --git a/features/providers/partner_means_assessment/means_check.feature b/features/providers/partner_means_assessment/means_check.feature index 0e06a5286c..d4df19bc58 100644 --- a/features/providers/partner_means_assessment/means_check.feature +++ b/features/providers/partner_means_assessment/means_check.feature @@ -24,6 +24,7 @@ Feature: partner_means_assessment means check @javascript @vcr @hmrc_use_dev_mock Scenario: I am able to navigate to partners means check when doing open banking upload Given the feature flag for partner_means_assessment is enabled + And the feature flag for collect_hmrc_data is enabled And I am logged in as a provider And csrf is enabled And an applicant named Ida Paisley with a partner has completed their true layer interactions diff --git a/helm_deploy/apply-for-legal-aid/templates/_envs.tpl b/helm_deploy/apply-for-legal-aid/templates/_envs.tpl index d26b89e985..788fe5a2cc 100644 --- a/helm_deploy/apply-for-legal-aid/templates/_envs.tpl +++ b/helm_deploy/apply-for-legal-aid/templates/_envs.tpl @@ -391,4 +391,9 @@ env: secretKeyRef: name: {{ template "apply-for-legal-aid.fullname" . }} key: slackAlertWebhook + - name: COLLECT_HMRC_DATA + valueFrom: + secretKeyRef: + name: {{ template "apply-for-legal-aid.fullname" . }} + key: collectHmrcData {{- end }} diff --git a/helm_deploy/apply-for-legal-aid/templates/secret.yaml b/helm_deploy/apply-for-legal-aid/templates/secret.yaml index 88e1b5d16b..bfdea09530 100644 --- a/helm_deploy/apply-for-legal-aid/templates/secret.yaml +++ b/helm_deploy/apply-for-legal-aid/templates/secret.yaml @@ -76,3 +76,4 @@ data: encryptionKeyDerivationSalt: {{ .Values.active_record_encryption.key_derivation_salt | b64enc | quote }} maintenanceMode: {{ .Values.maintenance_mode.enabled | b64enc | quote }} slackAlertWebhook: {{ .Values.slack_webhooks.alert | b64enc | quote }} + collectHmrcData: {{ .Values.collect_hmrc_data.enabled | b64enc | quote }} diff --git a/helm_deploy/apply-for-legal-aid/values-production.yaml b/helm_deploy/apply-for-legal-aid/values-production.yaml index 10e4b6e1b5..802f6c7a82 100644 Binary files a/helm_deploy/apply-for-legal-aid/values-production.yaml and b/helm_deploy/apply-for-legal-aid/values-production.yaml differ diff --git a/helm_deploy/apply-for-legal-aid/values-staging.yaml b/helm_deploy/apply-for-legal-aid/values-staging.yaml index 2aea2884cd..a9ed5ff201 100644 Binary files a/helm_deploy/apply-for-legal-aid/values-staging.yaml and b/helm_deploy/apply-for-legal-aid/values-staging.yaml differ diff --git a/helm_deploy/apply-for-legal-aid/values-uat.yaml b/helm_deploy/apply-for-legal-aid/values-uat.yaml index 4310cb3bc2..8a7538c521 100644 Binary files a/helm_deploy/apply-for-legal-aid/values-uat.yaml and b/helm_deploy/apply-for-legal-aid/values-uat.yaml differ diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 098051a4a6..6dced23180 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -14,6 +14,7 @@ expect(rec.alert_via_sentry?).to be true expect(rec.partner_means_assessment?).to be false expect(rec.linked_applications?).to be false + expect(rec.collect_hmrc_data?).to be false end end @@ -28,6 +29,7 @@ alert_via_sentry: true, partner_means_assessment: true, linked_applications: true, + collect_hmrc_data: true, ) end @@ -41,6 +43,7 @@ expect(rec.alert_via_sentry?).to be true expect(rec.partner_means_assessment?).to be true expect(rec.linked_applications?).to be true + expect(rec.collect_hmrc_data?).to be true end end end @@ -57,6 +60,7 @@ expect(described_class.alert_via_sentry?).to be true expect(described_class.partner_means_assessment?).to be false expect(described_class.linked_applications?).to be false + expect(described_class.collect_hmrc_data?).to be false end end end diff --git a/spec/requests/admin/settings_controller_spec.rb b/spec/requests/admin/settings_controller_spec.rb index 9457e7a2e6..982f3b98cf 100644 --- a/spec/requests/admin/settings_controller_spec.rb +++ b/spec/requests/admin/settings_controller_spec.rb @@ -42,6 +42,7 @@ enable_ccms_submission: "true", partner_means_assessment: "true", linked_applications: "true", + collect_hmrc_data: "true", }, } end @@ -57,6 +58,7 @@ expect(setting.allow_welsh_translation?).to be(true) expect(setting.partner_means_assessment?).to be(true) expect(setting.linked_applications?).to be(true) + expect(setting.collect_hmrc_data?).to be(true) end it "create settings if they do not exist" do 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 36fef53efc..51b957717c 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 @@ -3,6 +3,9 @@ RSpec.describe Providers::ConfirmDWPNonPassportedApplicationsController do let(:application) { create(:legal_aid_application, :with_proceedings, :at_checking_applicant_details, :with_applicant_and_address) } let(:application_id) { application.id } + let(:enable_hmrc_collection) { true } + + before { allow(Setting).to receive(:collect_hmrc_data?).and_return(enable_hmrc_collection) } describe "GET /providers/applications/:legal_aid_application_id/confirm_dwp_non_passported_applications" do subject(:get_request) { get "/providers/applications/#{application_id}/confirm_dwp_non_passported_applications" } @@ -118,9 +121,20 @@ expect(application.reload.state_machine_proxy.type).to eq "NonPassportedStateMachine" end - it "calls the HMRC::CreateResponsesService" do - patch_request - expect(HMRC::CreateResponsesService).to have_received(:call).once + context "and the hmrc toggle is true" do + it "calls the HMRC::CreateResponsesService" do + patch_request + expect(HMRC::CreateResponsesService).to have_received(:call).once + end + end + + context "and the hmrc toggle is false" do + let(:enable_hmrc_collection) { false } + + it "doesn't call the HMRC::CreateResponsesService" do + patch_request + expect(HMRC::CreateResponsesService).not_to have_received(:call) + end end it "successfully deletes any existing dwp override" do diff --git a/spec/requests/providers/means/full_employment_details_controller_spec.rb b/spec/requests/providers/means/full_employment_details_controller_spec.rb index e590844f48..62c359da75 100644 --- a/spec/requests/providers/means/full_employment_details_controller_spec.rb +++ b/spec/requests/providers/means/full_employment_details_controller_spec.rb @@ -5,6 +5,9 @@ let(:applicant) { application.applicant } let(:provider) { application.provider } let(:before_actions) { {} } + let(:enable_hmrc_collection) { true } + + before { allow(Setting).to receive(:collect_hmrc_data?).and_return(enable_hmrc_collection) } describe "GET /providers/applications/:id/means/full_employment_details" do subject(:request) { get providers_legal_aid_application_means_full_employment_details_path(application) } @@ -22,66 +25,94 @@ request end - context "when the no job data is returned" do - let(:before_actions) { create(:hmrc_response, :nil_response, legal_aid_application_id: application.id, owner_id: applicant.id, owner_type: applicant.class) } + context "when HMRC collection is on" do + context "when the no job data is returned" do + let(:before_actions) { create(:hmrc_response, :nil_response, legal_aid_application_id: application.id, owner_id: applicant.id, owner_type: applicant.class) } - it "returns http success" do - expect(response).to have_http_status(:ok) - end + it "returns http success" do + expect(response).to have_http_status(:ok) + end - it "displays the 'no data' message" do - expect(response.body).to include(html_compare("HMRC has no record of your client's employment in the last 3 months")) + it "displays the 'no data' message" do + expect(response.body).to include(html_compare("HMRC has no record of your client's employment in the last 3 months")) + end end - end - context "when the HMRC response is pending" do - let(:before_actions) { create(:hmrc_response, :processing, legal_aid_application_id: application.id, owner_id: applicant.id, owner_type: applicant.class) } + context "when the HMRC response is pending" do + let(:before_actions) { create(:hmrc_response, :processing, legal_aid_application_id: application.id, owner_id: applicant.id, owner_type: applicant.class) } - it "returns http success" do - expect(response).to have_http_status(:ok) - end + it "returns http success" do + expect(response).to have_http_status(:ok) + end + + it "displays the 'no data' message" do + expect(response.body).to include(html_compare("HMRC has no record of your client's employment in the last 3 months")) + end + + describe "Sending a message to Sentry" do + let(:before_actions) do + create(:hmrc_response, :processing, legal_aid_application_id: application.id, owner_id: applicant.id, owner_type: applicant.class) + expect(Sentry).to receive(:capture_message).with(/HMRC response still pending/) + end - it "displays the 'no data' message" do - expect(response.body).to include(html_compare("HMRC has no record of your client's employment in the last 3 months")) + it "sends the message to Sentry and is successful" do + expect(response).to have_http_status(:ok) + end + end end - describe "Sending a message to Sentry" do + context "when the applicant has multiple jobs" do let(:before_actions) do - create(:hmrc_response, :processing, legal_aid_application_id: application.id, owner_id: applicant.id, owner_type: applicant.class) - expect(Sentry).to receive(:capture_message).with(/HMRC response still pending/) + create(:hmrc_response, :multiple_employments_usecase1, legal_aid_application_id: application.id, owner_id: applicant.id, owner_type: applicant.class) + create_list(:employment, 2, legal_aid_application: application, owner_id: applicant.id, owner_type: applicant.class) end - it "sends the message to Sentry and is successful" do + it "returns http success" do expect(response).to have_http_status(:ok) end - end - end - context "when the applicant has multiple jobs" do - let(:before_actions) do - create(:hmrc_response, :multiple_employments_usecase1, legal_aid_application_id: application.id, owner_id: applicant.id, owner_type: applicant.class) - create_list(:employment, 2, legal_aid_application: application, owner_id: applicant.id, owner_type: applicant.class) + it "displays the 'multiple job' message" do + expect(response.body).to include(html_compare("HMRC found a record of your client's employment")) + expect(response.body).to include(html_compare("HMRC says your client had more than one job in the last 3 months.")) + end end - it "returns http success" do - expect(response).to have_http_status(:ok) - end + context "when applicant has no national insurance number" do + let(:application) { create(:legal_aid_application, :with_applicant_no_nino) } + + it "returns http success" do + expect(response).to have_http_status(:ok) + end - it "displays the 'multiple job' message" do - expect(response.body).to include(html_compare("HMRC found a record of your client's employment")) - expect(response.body).to include(html_compare("HMRC says your client had more than one job in the last 3 months.")) + it "displays the correct page content" do + expect(response.body).to include(html_compare("We could not check your client's employment record with HMRC")) + end end end - context "when partner has no national insurance number" do - let(:application) { create(:legal_aid_application, :with_applicant_no_nino) } + context "when HMRC collection is off" do + let(:enable_hmrc_collection) { false } - it "returns http success" do - expect(response).to have_http_status(:ok) + context "and the applicant has a national insurance number" do + it "returns http success" do + expect(response).to have_http_status(:ok) + end + + it "displays the 'no data' message" do + expect(response.body).to include(html_compare("Enter details of your client's employment in the last 3 months")) + end end - it "displays the correct page content" do - expect(response.body).to include(html_compare("We could not check your client's employment record with HMRC")) + context "and applicant has no national insurance number" do + let(:application) { create(:legal_aid_application, :with_applicant_no_nino) } + + it "returns http success" do + expect(response).to have_http_status(:ok) + end + + it "displays the correct page content" do + expect(response.body).to include(html_compare("Enter details of your client's employment in the last 3 months")) + end end end end