Browse Source

tests for location validations

juris_katrina_test
JG 3 years ago
parent
commit
a8196edd0b
  1. 2
      config/locales/en.yml
  2. 37
      spec/requests/locations_controller_spec.rb
  3. 64
      spec/requests/schemes_controller_spec.rb

2
config/locales/en.yml

@ -65,8 +65,6 @@ en:
invalid: "Select who provides the support services used by this scheme"
location:
attributes:
wheelchair_adaptation:
blank: "Select if majority of units in this location built or adapted to wheelchair-user standards"
units:
blank: "Enter total number of units at this location"
type_of_unit:

37
spec/requests/locations_controller_spec.rb

@ -189,11 +189,13 @@ RSpec.describe LocationsController, type: :request do
end
context "when required param are missing" do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } }
let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } }
it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.postcode"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank"))
end
end
end
@ -295,6 +297,17 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.wheelchair_adaptation).to eq("No")
end
end
context "when required param are missing" do
let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } }
it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.postcode"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank"))
end
end
end
end
@ -507,6 +520,17 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.wheelchair_adaptation).to eq("No")
end
end
context "when required param are missing" do
let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } }
it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.postcode"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank"))
end
end
end
context "when signed in as a support user" do
@ -616,6 +640,17 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.wheelchair_adaptation).to eq("No")
end
end
context "when required param are missing" do
let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } }
it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.postcode"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank"))
end
end
end
end

64
spec/requests/schemes_controller_spec.rb

@ -404,7 +404,6 @@ 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 missing required scheme params" do
@ -413,7 +412,7 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "",
registered_under_care_act: "",
support_services_provider: "" } }
end
end
it "renders the same page with error message" do
post "/schemes", params: params
@ -487,7 +486,7 @@ RSpec.describe SchemesController, type: :request do
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.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")
@ -500,10 +499,9 @@ 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 "missing required scheme params" do
context "when missing required scheme params" do
let(:params) do
{ scheme: { service_name: "",
scheme_type: "",
@ -567,19 +565,21 @@ RSpec.describe SchemesController, type: :request do
end
context "when params are missing" do
let(:params) do { scheme: {
service_name: "",
managing_organisation_id: "",
owning_organisation_id: "",
primary_client_group: "",
secondary_client_group: "",
scheme_type: "",
registered_under_care_act: "",
support_type: "",
intended_stay: "",
support_services_provider: "",
has_other_client_group: "",
page: "details" } }
let(:params) do
{ scheme: {
service_name: "",
managing_organisation_id: "",
owning_organisation_id: "",
primary_client_group: "",
secondary_client_group: "",
scheme_type: "",
registered_under_care_act: "",
support_type: "",
intended_stay: "",
support_services_provider: "",
has_other_client_group: "",
page: "details",
} }
end
it "renders primary client group after successful update" do
@ -856,19 +856,21 @@ RSpec.describe SchemesController, type: :request do
end
context "when params are missing" do
let(:params) do { scheme: {
service_name: "",
managing_organisation_id: "",
owning_organisation_id: "",
primary_client_group: "",
secondary_client_group: "",
scheme_type: "",
registered_under_care_act: "",
support_type: "",
intended_stay: "",
support_services_provider: "",
has_other_client_group: "",
page: "details" } }
let(:params) do
{ scheme: {
service_name: "",
managing_organisation_id: "",
owning_organisation_id: "",
primary_client_group: "",
secondary_client_group: "",
scheme_type: "",
registered_under_care_act: "",
support_type: "",
intended_stay: "",
support_services_provider: "",
has_other_client_group: "",
page: "details",
} }
end
it "renders primary client group after successful update" do

Loading…
Cancel
Save