Browse Source

test: add create_housing_provider tests

pull/954/head
natdeanlewissoftwire 4 years ago
parent
commit
dab01ad1ac
  1. 57
      spec/requests/organisations_controller_spec.rb

57
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

Loading…
Cancel
Save