From dab01ad1acd651e9336dcf8b55baa65f2328a704 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 27 Oct 2022 16:30:22 +0100 Subject: [PATCH] test: add create_housing_provider tests --- .../requests/organisations_controller_spec.rb | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 98bd26ac6..ed6f7a535 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -534,6 +534,34 @@ RSpec.describe OrganisationsController, type: :request do expect { request }.not_to change(Organisation, :count) end end + + describe "organisation_relationships#create_housing_provider" do + let!(:housing_provider) { FactoryBot.create(:organisation) } + + let(:params) do + { + "organisation": { + "related_organisation_id": housing_provider.id, + }, + } + end + + let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: } + + it "creates a new organisation relationship" do + expect { request }.to change(OrganisationRelationship, :count).by(1) + end + + it "sets the organisation relationship attributes correctly" do + request + expect(OrganisationRelationship.exists?(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id, relationship_type: OrganisationRelationship::OWNING)).to be_truthy + end + + it "redirects to the organisation list" do + request + expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers?related_organisation_id=#{housing_provider.id}") + end + end end context "with a data provider user" do @@ -1214,7 +1242,6 @@ RSpec.describe OrganisationsController, type: :request do expect(page).to have_button("Add") end end - end context "when there are more than 20 organisations" do @@ -1374,6 +1401,34 @@ RSpec.describe OrganisationsController, type: :request do end end end + + describe "organisation_relationships#create_housing_provider" do + let!(:housing_provider) { FactoryBot.create(:organisation) } + + let(:params) do + { + "organisation": { + "related_organisation_id": housing_provider.id, + }, + } + end + + let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: } + + it "creates a new organisation relationship" do + expect { request }.to change(OrganisationRelationship, :count).by(1) + end + + it "sets the organisation relationship attributes correctly" do + request + expect(OrganisationRelationship.exists?(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id, relationship_type: OrganisationRelationship::OWNING)).to be_truthy + end + + it "redirects to the organisation list" do + request + expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers?related_organisation_id=#{housing_provider.id}") + end + end end end