From 0bba6c86a6a78415e8f6fad161d78e40856ab743 Mon Sep 17 00:00:00 2001 From: JG Date: Wed, 13 Jul 2022 14:58:59 +0100 Subject: [PATCH] tests for validations --- spec/requests/schemes_controller_spec.rb | 102 ++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 974a5859a..f97930014 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -372,7 +372,42 @@ RSpec.describe SchemesController, type: :request do expect(Scheme.last.id_to_display).to match(/S*/) end - context "missing required scheme params" do + context "when support services provider is selected" do + let(:params) do + { scheme: { service_name: "testy", + sensitive: "1", + scheme_type: "Foyer", + registered_under_care_act: "No", + support_services_provider: "Another registered housing provider" } } + end + + it "creates a new scheme for user organisation with valid params and renders correct page" do + expect { post "/schemes", params: }.to change(Scheme, :count).by(1) + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Which organisation provides the support services used by this scheme?") + end + + it "creates a new scheme for user organisation with valid params" do + post "/schemes", params: params + + expect(Scheme.last.owning_organisation_id).to eq(user.organisation_id) + expect(Scheme.last.service_name).to eq("testy") + expect(Scheme.last.scheme_type).to eq("Foyer") + expect(Scheme.last.sensitive).to eq("Yes") + expect(Scheme.last.registered_under_care_act).to eq("No") + expect(Scheme.last.id).not_to eq(nil) + expect(Scheme.last.has_other_client_group).to eq(nil) + expect(Scheme.last.primary_client_group).to eq(nil) + expect(Scheme.last.secondary_client_group).to eq(nil) + expect(Scheme.last.support_type).to eq(nil) + expect(Scheme.last.intended_stay).to eq(nil) + expect(Scheme.last.id_to_display).to match(/S*/) + end + + end + + context "when missing required scheme params" do let(:params) do { scheme: { service_name: "", scheme_type: "", @@ -433,6 +468,41 @@ RSpec.describe SchemesController, type: :request do expect(Scheme.last.id_to_display).to match(/S*/) end + context "when support services provider is selected" do + let(:params) do + { scheme: { service_name: "testy", + sensitive: "1", + scheme_type: "Foyer", + registered_under_care_act: "No", + owning_organisation_id: organisation.id, + support_services_provider: "Another registered housing provider" } } + end + + it "creates a new scheme for user organisation with valid params and renders correct page" do + expect { post "/schemes", params: }.to change(Scheme, :count).by(1) + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Which organisation provides the support services used by this scheme?") + end + + it "creates a new scheme for user organisation with valid params" do + post "/schemes", params: params + expect(Scheme.last.owning_organisation_id).to eq(organisation.id,) + expect(Scheme.last.service_name).to eq("testy") + expect(Scheme.last.scheme_type).to eq("Foyer") + expect(Scheme.last.sensitive).to eq("Yes") + expect(Scheme.last.registered_under_care_act).to eq("No") + expect(Scheme.last.id).not_to eq(nil) + expect(Scheme.last.has_other_client_group).to eq(nil) + expect(Scheme.last.primary_client_group).to eq(nil) + expect(Scheme.last.secondary_client_group).to eq(nil) + expect(Scheme.last.support_type).to eq(nil) + expect(Scheme.last.intended_stay).to eq(nil) + expect(Scheme.last.id_to_display).to match(/S*/) + end + + end + context "missing required scheme params" do let(:params) do { scheme: { service_name: "", @@ -496,6 +566,36 @@ RSpec.describe SchemesController, type: :request do patch "/schemes/#{scheme_to_update.id}", params: end + context "when updating support services provider" do + let(:params) { { scheme: { managing_organisation_id: organisation.id, page: "support-services-provider" } } } + + it "renders primary client group after successful update" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("What client group is this scheme intended for?") + end + + it "updates a scheme with valid params" do + follow_redirect! + expect(scheme_to_update.reload.managing_organisation_id).to eq(organisation.id) + end + + context "when updating from check answers page" do + let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group", check_answers: "true" } } } + + it "renders check answers page after successful update" do + follow_redirect! + expect(response).to have_http_status(:ok) + expect(page).to have_content("Check your changes before creating this scheme") + end + + it "updates a scheme with valid params" do + follow_redirect! + expect(scheme_to_update.reload.primary_client_group).to eq("Homeless families with support needs") + end + end + end + context "when updating primary client group" do let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group" } } }