From 638d4e6d985c2759db1a14b4116cd192b8154b85 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 31 Oct 2022 10:15:55 +0000 Subject: [PATCH] test: add housing provider removal tests --- ...anisation_relationships_controller_spec.rb | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/spec/requests/organisation_relationships_controller_spec.rb b/spec/requests/organisation_relationships_controller_spec.rb index 9fdb01ec9..9dc242e05 100644 --- a/spec/requests/organisation_relationships_controller_spec.rb +++ b/spec/requests/organisation_relationships_controller_spec.rb @@ -189,6 +189,31 @@ RSpec.describe OrganisationRelationshipsController, type: :request do expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents?related_organisation_id=#{managing_agent.id}") end end + + describe "organisation_relationships#delete_housing_provider" do + let!(:housing_provider) { FactoryBot.create(:organisation) } + + before do + FactoryBot.create(:organisation_relationship, :owning, child_organisation: organisation, parent_organisation: housing_provider) + end + + let(:params) do + { + "organisation_to_remove_id": housing_provider.id, + } + end + + let(:request) { delete "/organisations/#{organisation.id}/housing-providers", headers:, params: } + + it "deletes the new organisation relationship" do + expect { request }.to change(OrganisationRelationship, :count).by(-1) + end + + it "redirects to the organisation list" do + request + expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers?removed_organisation_id=#{housing_provider.id}") + end + end end context "with a data provider user" do @@ -369,6 +394,31 @@ RSpec.describe OrganisationRelationshipsController, type: :request do end end + describe "organisation_relationships#delete_housing_provider" do + let!(:housing_provider) { FactoryBot.create(:organisation) } + + before do + FactoryBot.create(:organisation_relationship, :owning, child_organisation: organisation, parent_organisation: housing_provider) + end + + let(:params) do + { + "organisation_to_remove_id": housing_provider.id, + } + end + + let(:request) { delete "/organisations/#{organisation.id}/housing-providers", headers:, params: } + + it "deletes the new organisation relationship" do + expect { request }.to change(OrganisationRelationship, :count).by(-1) + end + + it "redirects to the organisation list" do + request + expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers?removed_organisation_id=#{housing_provider.id}") + end + end + context "when viewing a specific organisation's housing providers" do let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } @@ -400,6 +450,10 @@ RSpec.describe OrganisationRelationshipsController, type: :request do expect(page).not_to have_content(other_org_housing_provider.name) end + it "shows remove link(s)" do + expect(response.body).to include("Remove") + end + it "shows the pagination count" do expect(page).to have_content("1 total housing providers") end