|
|
|
|
@ -724,62 +724,159 @@ RSpec.describe SchemesController, type: :request do
|
|
|
|
|
|
|
|
|
|
context "when signed in as a data coordinator" do |
|
|
|
|
let(:user) { create(:user, :data_coordinator) } |
|
|
|
|
let(:params) do |
|
|
|
|
{ scheme: { service_name: " testy ", |
|
|
|
|
sensitive: "1", |
|
|
|
|
scheme_type: "Foyer", |
|
|
|
|
registered_under_care_act: "No", |
|
|
|
|
arrangement_type: "D" } } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
sign_in user |
|
|
|
|
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("What client group is this scheme intended for?") |
|
|
|
|
end |
|
|
|
|
context "when making a scheme in the user's organisation" do |
|
|
|
|
let!(:params) do |
|
|
|
|
{ scheme: { service_name: " testy ", |
|
|
|
|
sensitive: "1", |
|
|
|
|
scheme_type: "Foyer", |
|
|
|
|
registered_under_care_act: "No", |
|
|
|
|
owning_organisation_id: user.organisation.id, |
|
|
|
|
arrangement_type: "D" } } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "creates a new scheme for user organisation with valid params" do |
|
|
|
|
post "/schemes", params: params |
|
|
|
|
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("What client group is this scheme intended for?") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
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*/) |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
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: user.organisation.id, |
|
|
|
|
arrangement_type: "R" } } |
|
|
|
|
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(" What client group is this scheme intended for?") |
|
|
|
|
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 required params are missing" do |
|
|
|
|
let(:params) do |
|
|
|
|
{ scheme: { service_name: "", |
|
|
|
|
scheme_type: "", |
|
|
|
|
registered_under_care_act: "", |
|
|
|
|
arrangement_type: "" } } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "renders the same page with error message" do |
|
|
|
|
post "/schemes", params: params |
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity) |
|
|
|
|
expect(page).to have_content("Create a new supported housing scheme") |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid")) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when there are no stock owners" do |
|
|
|
|
let(:params) do |
|
|
|
|
{ scheme: { service_name: " testy ", |
|
|
|
|
sensitive: "1", |
|
|
|
|
scheme_type: "Foyer", |
|
|
|
|
registered_under_care_act: "No", |
|
|
|
|
arrangement_type: "D" } } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
user.organisation.stock_owners.destroy_all |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "infers the user's organisation" do |
|
|
|
|
post "/schemes", params: params |
|
|
|
|
expect(Scheme.last.owning_organisation_id).to eq(user.organisation_id) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the organisation id param is included" do |
|
|
|
|
let(:organisation) { create(:organisation) } |
|
|
|
|
let(:params) { { scheme: { owning_organisation: organisation } } } |
|
|
|
|
|
|
|
|
|
it "sets the owning organisation correctly" do |
|
|
|
|
post "/schemes", params: params |
|
|
|
|
expect(Scheme.last.owning_organisation_id).to eq(user.organisation_id) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when support services provider is selected" do |
|
|
|
|
context "when making a scheme in a parent organisation of the user's organisation" do |
|
|
|
|
let(:parent_organisation) { create(:organisation) } |
|
|
|
|
let!(:parent_schemes) { create_list(:scheme, 5, owning_organisation: parent_organisation) } |
|
|
|
|
let(:params) do |
|
|
|
|
{ scheme: { service_name: "testy", |
|
|
|
|
{ scheme: { service_name: " testy ", |
|
|
|
|
sensitive: "1", |
|
|
|
|
scheme_type: "Foyer", |
|
|
|
|
registered_under_care_act: "No", |
|
|
|
|
arrangement_type: "R" } } |
|
|
|
|
owning_organisation_id: user.organisation.stock_owners.first.id, |
|
|
|
|
arrangement_type: "D" } } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
create(:organisation_relationship, parent_organisation:, child_organisation: user.organisation) |
|
|
|
|
parent_schemes.each do |scheme| |
|
|
|
|
create(:location, scheme:) |
|
|
|
|
end |
|
|
|
|
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(" What client group is this scheme intended for?") |
|
|
|
|
expect(page).to have_content("What client group is this scheme intended for?") |
|
|
|
|
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.owning_organisation_id).to eq(user.organisation.stock_owners.first.id) |
|
|
|
|
expect(Scheme.last.service_name).to eq("testy") |
|
|
|
|
expect(Scheme.last.scheme_type).to eq("Foyer") |
|
|
|
|
expect(Scheme.last.sensitive).to eq("Yes") |
|
|
|
|
@ -792,34 +889,71 @@ RSpec.describe SchemesController, type: :request do
|
|
|
|
|
expect(Scheme.last.intended_stay).to eq(nil) |
|
|
|
|
expect(Scheme.last.id_to_display).to match(/S*/) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when required params are missing" do |
|
|
|
|
let(:params) do |
|
|
|
|
{ scheme: { service_name: "", |
|
|
|
|
scheme_type: "", |
|
|
|
|
registered_under_care_act: "", |
|
|
|
|
arrangement_type: "" } } |
|
|
|
|
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: user.organisation.stock_owners.first.id, |
|
|
|
|
arrangement_type: "R" } } |
|
|
|
|
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(" What client group is this scheme intended for?") |
|
|
|
|
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.stock_owners.first.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 |
|
|
|
|
|
|
|
|
|
it "renders the same page with error message" do |
|
|
|
|
post "/schemes", params: params |
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity) |
|
|
|
|
expect(page).to have_content("Create a new supported housing scheme") |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid")) |
|
|
|
|
context "when required params are missing" do |
|
|
|
|
let(:params) do |
|
|
|
|
{ scheme: { service_name: "", |
|
|
|
|
scheme_type: "", |
|
|
|
|
registered_under_care_act: "", |
|
|
|
|
arrangement_type: "", |
|
|
|
|
owning_organisation_id: ""} } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "renders the same page with error message" do |
|
|
|
|
post "/schemes", params: params |
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity) |
|
|
|
|
expect(page).to have_content("Create a new supported housing scheme") |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.invalid")) |
|
|
|
|
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid")) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the organisation id param is included" do |
|
|
|
|
let(:organisation) { create(:organisation) } |
|
|
|
|
let(:params) { { scheme: { owning_organisation: organisation } } } |
|
|
|
|
context "when the organisation id param is included" do |
|
|
|
|
let(:organisation) { create(:organisation) } |
|
|
|
|
let(:params) { { scheme: { owning_organisation: organisation } } } |
|
|
|
|
|
|
|
|
|
it "sets the owning organisation correctly" do |
|
|
|
|
post "/schemes", params: params |
|
|
|
|
expect(Scheme.last.owning_organisation_id).to eq(user.organisation_id) |
|
|
|
|
it "sets the owning organisation correctly" do |
|
|
|
|
post "/schemes", params: params |
|
|
|
|
expect(Scheme.last.owning_organisation_id).to eq(user.organisation.stock_owners.first.id) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|