diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index bed593844..2d232e929 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -13,6 +13,12 @@ FactoryBot.define do tenant_code { "BZ737" } property_postcode { "NW1 7TY" } end + trait :soft_validations_triggered do + status { 1 } + person_1_economic_status { "Full-time - 30 hours or more" } + net_income { 750 } + net_income_frequency { "Weekly" } + end created_at { Time.zone.now } updated_at { Time.zone.now } end diff --git a/spec/requests/soft_validations_controller_spec.rb b/spec/requests/soft_validations_controller_spec.rb new file mode 100644 index 000000000..90bd51407 --- /dev/null +++ b/spec/requests/soft_validations_controller_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +RSpec.describe SoftValidationsController, type: :request do + let(:params) { { case_log_id: case_log.id } } + let(:url) { "/case_logs/#{case_log.id}/net_income/soft_validations" } + + before do + get url, params: {} + end + + describe "GET #show" do + context "Soft validation overide required" do + let(:case_log) { FactoryBot.create(:case_log, :soft_validations_triggered) } + + it "returns a success response" do + expect(response).to be_successful + end + + it "returns a json with the soft validation fields" do + json_response = JSON.parse(response.body) + expect(json_response["show"]).to eq(true) + expect(json_response["label"]).to match(/Are you sure this is correct?/) + end + end + + context "Soft validation overide not required" do + let(:case_log) { FactoryBot.create(:case_log, :in_progress) } + + it "returns a success response" do + expect(response).to be_successful + end + + it "returns a json with the soft validation fields" do + json_response = JSON.parse(response.body) + expect(json_response["show"]).to eq(false) + end + end + end +end