Browse Source

tests: add tests to org_controller and remove redundant housing_providers controller

CLDC-1661-new-page-for-housing-providers
natdeanlewissoftwire 2 years ago
parent
commit
b8ce2fc5ad
  1. 28
      app/controllers/housing_providers_controller.rb
  2. 6
      app/controllers/organisations_controller.rb
  3. 96
      spec/requests/organisations_controller_spec.rb

28
app/controllers/housing_providers_controller.rb

@ -1,28 +0,0 @@
class HousingProvidersController < ApplicationController
include Pagy::Backend
include Modules::SearchFilter
def index
housing_providers =
Organisation.joins(:child_organisation_relationships)
.where(organisation_relationships: {
child_organisation_id: current_user.organisation_id,
relationship_type: OrganisationRelationship.relationship_types[:owning],
})
.order(:name)
respond_to do |format|
format.html do
@pagy, @housing_providers = pagy(filtered_collection(housing_providers, search_term))
@searched = search_term.presence
@total_count = housing_providers.size
render "housing_providers/index"
end
end
end
private
def search_term
params["search"]
end
end

6
app/controllers/organisations_controller.rb

@ -149,7 +149,11 @@ class OrganisationsController < ApplicationController
@pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers)
@searched = search_term.presence
@total_count = housing_providers.size
render "housing_providers", layout: "application"
if current_user.support?
render "housing_providers", layout: "application"
else
render "housing_providers/index"
end
end
end
end

96
spec/requests/organisations_controller_spec.rb

@ -284,6 +284,54 @@ RSpec.describe OrganisationsController, type: :request do
end
end
context "when accessing the housing providers tab" do
context "with an organisation that the user belongs to" do
let!(:housing_provider) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:organisation_relationship) { FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) }
let!(:other_organisation_relationship) { FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) }
before do
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {}
end
it "shows the tab navigation" do
expected_html = "<nav class=\"app-primary-navigation\""
expect(response.body).to include(expected_html)
end
it "shows an add housing provider button" do
expect(page).to have_link("Add a housing provider")
end
it "shows a table of housing providers" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name)
end
it "shows only housing providers for the current user's organisation" do
expect(page).to have_content(housing_provider.name)
expect(page).not_to have_content(other_org_housing_provider.name)
end
it "shows the pagination count" do
expect(page).to have_content("1 total housing providers")
end
end
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do
before do
get "/organisations/#{unauthorised_organisation.id}/housing-providers", headers:, params: {}
end
it "returns not found 404 from users page" do
expect(response).to have_http_status(:not_found)
end
end
end
describe "#edit" do
context "with an organisation that the user belongs to" do
before do
@ -478,6 +526,54 @@ RSpec.describe OrganisationsController, type: :request do
end
end
context "when accessing the housing providers tab" do
context "with an organisation that the user belongs to" do
let!(:housing_provider) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:organisation_relationship) { FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) }
let!(:other_organisation_relationship) { FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) }
before do
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {}
end
it "shows the tab navigation" do
expected_html = "<nav class=\"app-primary-navigation\""
expect(response.body).to include(expected_html)
end
it "doesn't show an add housing provider button" do
expect(page).not_to have_link("Add a housing provider")
end
it "shows a table of housing providers" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name)
end
it "shows only housing providers for the current user's organisation" do
expect(page).to have_content(housing_provider.name)
expect(page).not_to have_content(other_org_housing_provider.name)
end
it "shows the pagination count" do
expect(page).to have_content("1 total housing providers")
end
end
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do
before do
get "/organisations/#{unauthorised_organisation.id}/housing-providers", headers:, params: {}
end
it "returns not found 404 from users page" do
expect(response).to have_http_status(:not_found)
end
end
end
describe "#edit" do
before do
get "/organisations/#{organisation.id}/edit", headers:, params: {}

Loading…
Cancel
Save