Browse Source

feat: update some tests

pull/1958/head
natdeanlewissoftwire 3 years ago
parent
commit
0ab6e716e4
  1. 2
      spec/features/schemes_spec.rb
  2. 24
      spec/helpers/schemes_helper_spec.rb
  3. 6
      spec/requests/locations_controller_spec.rb
  4. 64
      spec/requests/schemes_controller_spec.rb

2
spec/features/schemes_spec.rb

@ -1069,7 +1069,7 @@ RSpec.describe "Schemes scheme Features" do
it "lets me see amended details on the check answers page" do it "lets me see amended details on the check answers page" do
expect(page).to have_content "FooBar" expect(page).to have_content "FooBar"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_link("Change", href: /schemes\/#{scheme.id}\/edit-name/, count: 2) expect(page).to have_link("Change", href: /schemes\/#{scheme.id}\/edit-name/, count: 3)
end end
end end
end end

24
spec/helpers/schemes_helper_spec.rb

@ -128,7 +128,7 @@ RSpec.describe SchemesHelper do
{ name: "Intended length of stay", value: "Permanent" }, { name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" }, { name: "Availability", value: "Active from 1 April 2021" },
] ]
expect(display_scheme_attributes(scheme, support_user)).to eq(attributes) expect(display_scheme_attributes(scheme)).to eq(attributes)
end end
it "returns correct display attributes for a coordinator user" do it "returns correct display attributes for a coordinator user" do
@ -139,6 +139,7 @@ RSpec.describe SchemesHelper do
{ name: "Confidential information", value: "No", edit: true }, { name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" }, { name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" }, { name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true},
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" }, { name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" }, { name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" }, { name: "Has another client group", value: "Yes" },
@ -147,7 +148,7 @@ RSpec.describe SchemesHelper do
{ name: "Intended length of stay", value: "Permanent" }, { name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" }, { name: "Availability", value: "Active from 1 April 2021" },
] ]
expect(display_scheme_attributes(scheme, coordinator_user)).to eq(attributes) expect(display_scheme_attributes(scheme)).to eq(attributes)
end end
end end
@ -173,7 +174,7 @@ RSpec.describe SchemesHelper do
{ name: "Intended length of stay", value: "Permanent" }, { name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" }, { name: "Availability", value: "Active from 1 April 2021" },
] ]
expect(display_scheme_attributes(scheme, support_user)).to eq(attributes) expect(display_scheme_attributes(scheme)).to eq(attributes)
end end
it "returns correct display attributes for a coordinator user" do it "returns correct display attributes for a coordinator user" do
@ -184,6 +185,7 @@ RSpec.describe SchemesHelper do
{ name: "Confidential information", value: "No", edit: true }, { name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" }, { name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" }, { name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true},
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" }, { name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" }, { name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" }, { name: "Has another client group", value: "Yes" },
@ -192,7 +194,7 @@ RSpec.describe SchemesHelper do
{ name: "Intended length of stay", value: "Permanent" }, { name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" }, { name: "Availability", value: "Active from 1 April 2021" },
] ]
expect(display_scheme_attributes(scheme, coordinator_user)).to eq(attributes) expect(display_scheme_attributes(scheme)).to eq(attributes)
end end
context "when the managing organisation is the owning organisation" do context "when the managing organisation is the owning organisation" do
@ -206,7 +208,7 @@ RSpec.describe SchemesHelper do
context "with no deactivations" do context "with no deactivations" do
it "displays current collection start date as availability date if created_at is later than collection start date" do it "displays current collection start date as availability date if created_at is later than collection start date" do
scheme.update!(created_at: Time.zone.local(2022, 4, 16)) scheme.update!(created_at: Time.zone.local(2022, 4, 16))
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021") expect(availability_attribute).to eq("Active from 1 April 2021")
end end
@ -221,7 +223,7 @@ RSpec.describe SchemesHelper do
end end
it "displays the timeline of availability" do it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022\nActive from 28 September 2022") expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022\nActive from 28 September 2022")
end end
@ -235,7 +237,7 @@ RSpec.describe SchemesHelper do
end end
it "displays the timeline of availability" do it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022") expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022")
end end
@ -251,7 +253,7 @@ RSpec.describe SchemesHelper do
end end
it "displays the timeline of availability" do it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 18 June 2022 to 23 September 2022\nDeactivated on 24 September 2022\nActive from 28 September 2022") expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 18 June 2022 to 23 September 2022\nDeactivated on 24 September 2022\nActive from 28 September 2022")
end end
@ -265,7 +267,7 @@ RSpec.describe SchemesHelper do
end end
it "displays the timeline of availability" do it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022") expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022")
end end
@ -282,7 +284,7 @@ RSpec.describe SchemesHelper do
end end
it "displays the timeline of availability" do it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022 to 23 October 2022\nDeactivated on 24 October 2022\nActive from 28 October 2022") expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022 to 23 October 2022\nDeactivated on 24 October 2022\nActive from 28 October 2022")
end end
@ -297,7 +299,7 @@ RSpec.describe SchemesHelper do
end end
it "displays the timeline of availability" do it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022") expect(availability_attribute).to eq("Active from 1 April 2021 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
end end

6
spec/requests/locations_controller_spec.rb

@ -179,7 +179,7 @@ RSpec.describe LocationsController, type: :request do
get "/schemes/#{scheme.id}/locations" get "/schemes/#{scheme.id}/locations"
end end
context "when coordinator attempts to see scheme belonging to a different organisation" do context "when coordinator attempts to see scheme belonging to a different (and not their parent) organisation" do
let(:another_scheme) { create(:scheme) } let(:another_scheme) { create(:scheme) }
before do before do
@ -302,8 +302,8 @@ RSpec.describe LocationsController, type: :request do
end end
end end
it "does not allow adding new locations" do it "does allow adding new locations" do
expect(page).not_to have_button("Add a location") expect(page).to have_button("Add a location")
end end
end end
end end

64
spec/requests/schemes_controller_spec.rb

@ -457,7 +457,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(specific_scheme.intended_stay) expect(page).to have_content(specific_scheme.intended_stay)
end end
context "when coordinator attempts to see scheme belonging to a different organisation" do context "when coordinator attempts to see scheme belonging to a different (and not their parent) organisation" do
let!(:specific_scheme) { create(:scheme) } let!(:specific_scheme) { create(:scheme) }
it "returns 401" do it "returns 401" do
@ -474,7 +474,6 @@ RSpec.describe SchemesController, type: :request do
end end
context "when looking at scheme details" do context "when looking at scheme details" do
let(:user) { create(:user, :data_coordinator) }
let!(:scheme) { create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { create(:scheme, owning_organisation: user.organisation) }
let(:add_deactivations) { scheme.scheme_deactivation_periods << scheme_deactivation_period } let(:add_deactivations) { scheme.scheme_deactivation_periods << scheme_deactivation_period }
@ -535,21 +534,68 @@ RSpec.describe SchemesController, type: :request do
context "when coordinator attempts to see scheme belonging to a parent organisation" do context "when coordinator attempts to see scheme belonging to a parent organisation" do
let(:parent_organisation) { create(:organisation) } let(:parent_organisation) { create(:organisation) }
let!(:specific_scheme) { create(:scheme, owning_organisation: parent_organisation) } let!(:specific_scheme) { create(:scheme, owning_organisation: parent_organisation) }
let(:add_deactivations) { specific_scheme.scheme_deactivation_periods << scheme_deactivation_period }
before do before do
create(:location, scheme: specific_scheme) create(:location, scheme: specific_scheme)
create(:organisation_relationship, parent_organisation:, child_organisation: user.organisation) create(:organisation_relationship, parent_organisation:, child_organisation: user.organisation)
Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user
add_deactivations
specific_scheme.save!
get "/schemes/#{specific_scheme.id}" get "/schemes/#{specific_scheme.id}"
end end
after do
Timecop.unfreeze
end
context "with active scheme" do
let(:add_deactivations) {}
it "shows the scheme" do it "shows the scheme" do
expect(page).to have_content(specific_scheme.id_to_display) expect(page).to have_content(specific_scheme.id_to_display)
end end
it "does not allow editing the scheme" do it "allows editing" do
expect(page).not_to have_link("Change") expect(page).to have_link("Change")
expect(page).not_to have_content("Reactivate this scheme") end
expect(page).not_to have_content("Deactivate this scheme")
it "renders deactivate this scheme" do
expect(response).to have_http_status(:ok)
expect(page).to have_link("Deactivate this scheme", href: "/schemes/#{specific_scheme.id}/new-deactivation")
end
end
context "with deactivated scheme" do
let(:scheme_deactivation_period) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9), scheme: specific_scheme) }
it "renders reactivate this scheme" do
expect(response).to have_http_status(:ok)
expect(page).to have_link("Reactivate this scheme", href: "/schemes/#{specific_scheme.id}/new-reactivation")
end
end
context "with scheme that's deactivating soon" do
let(:scheme_deactivation_period) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12), scheme: specific_scheme) }
it "does not render toggle scheme link" do
expect(response).to have_http_status(:ok)
expect(page).not_to have_link("Reactivate this scheme")
expect(page).not_to have_link("Deactivate this scheme")
end
end
context "with scheme that's deactivating in more than 6 months" do
let(:scheme_deactivation_period) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2023, 5, 12), scheme: specific_scheme) }
it "does not render toggle scheme link" do
expect(response).to have_http_status(:ok)
expect(page).not_to have_link("Reactivate this scheme")
expect(page).to have_link("Deactivate this scheme")
expect(response.body).not_to include("<strong class=\"govuk-tag govuk-tag--yellow\">Deactivating soon</strong>")
expect(response.body).to include("<strong class=\"govuk-tag govuk-tag--green\">Active</strong>")
end
end end
end end
@ -1813,7 +1859,7 @@ RSpec.describe SchemesController, type: :request do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}") expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name) expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 2 assert_select "a", text: /Change/, count: 3
end end
end end
end end
@ -1958,7 +2004,7 @@ RSpec.describe SchemesController, type: :request do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}") expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name) expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 2 assert_select "a", text: /Change/, count: 3
end end
end end
end end
@ -2016,7 +2062,7 @@ RSpec.describe SchemesController, type: :request do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Scheme details") expect(page).to have_content("Scheme details")
expect(page).to have_content("This scheme contains confidential information") expect(page).to have_content("This scheme contains confidential information")
expect(page).not_to have_content("Which organisation owns the housing stock for this scheme?") expect(page).to have_content("Which organisation owns the housing stock for this scheme?")
end end
context "when attempting to access secondary-client-group scheme page for another organisation" do context "when attempting to access secondary-client-group scheme page for another organisation" do

Loading…
Cancel
Save