Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

728 lines
27 KiB

require "rails_helper"
RSpec.describe OrganisationRelationshipsController, type: :request do
let(:organisation) { user.organisation }
let!(:unauthorised_organisation) { FactoryBot.create(:organisation) }
let(:headers) { { "Accept" => "text/html" } }
let(:page) { Capybara::Node::Simple.new(response.body) }
context "when user is signed in" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
context "with a data coordinator user" do
before do
sign_in user
end
context "when accessing the stock owners tab" do
context "with an organisation that the user belongs to" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
let!(:other_org_stock_owner) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:inactive_stock_owner) { FactoryBot.create(:organisation, name: "Inactive LTD", active: false) }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: inactive_stock_owner)
get "/organisations/#{organisation.id}/stock-owners", 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 stock owner button" do
expect(page).to have_link("Add a stock owner")
end
it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(stock_owner.name)
end
it "shows only stock owners for the current user's organisation" do
expect(page).to have_content(stock_owner.name)
expect(page).not_to have_content(other_org_stock_owner.name)
end
it "does not show inactive stock owners" do
expect(page).not_to have_content(inactive_stock_owner.name)
end
it "shows the pagination count" do
CLDC-3014 Add schemes and locations csv download functionality (#2083) * feat: add schemes and locations download links and pages * feat: update current path helper * feat: update tests for different user visibility levels * feat: update search caption tests * refactor: lint tests * refactor: lint tests * git: revert unintentional inclusion * feat: update tests * refactor: lint * feat: DRY up routing * refactor: lint * feat: add csv confirmation view * feat: add scheme csv service * feat: rename * feat: update csv service * feat: update csv service * feat: update controller and rename view * feat: update view * refactor: lint * feat: show correct headers in csv * feat: add locations and combined csv behaviour * feat: remove redundant user instance variable * feat: add scheme csv service spec * feat: add scheme email csv job tests * feat: update filters in spec * refactor: move scheme_email_csv_job_spec.rb * feat: update spec * refactor: remove blank line * feat: add nowrap to all download links * feat: update org schemes controller with org schemes (and rename for clarity) * feat: update link indentation and spec * feat: only include location LA name, and rename to location_local_authority * feat: update seed locations with westminster local authorities to avoid similar confusion to some that arose in PO review * feat: display multiple active periods on a single line * feat: display multiple active periods on a single line * feat: update line spacing in search captions * feat: replace 2/3 with full column in download page * feat: move scheme alphabeticising into manager * feat: update tests now search/filterless copy has changed * refactor: lint * refactor: lint * refactor: lint * feat: add filter alphabeticising test * feat: correct spacing
1 year ago
expect(page).to have_content("1 total stock owners")
end
context "when adding a stock owner" do
let!(:active_organisation) { FactoryBot.create(:organisation, name: "Active Org", active: true) }
let!(:inactive_organisation) { FactoryBot.create(:organisation, name: "Inactive LTD", active: false) }
before do
get "/organisations/#{organisation.id}/stock-owners/add", headers:, params: {}
end
it "has the correct header" do
expect(response.body).to include("What is the name of your stock owner?")
end
it "shows an add button" do
expect(page).to have_button("Add")
end
it "shows a cancel button" do
expect(page).to have_link("Cancel", href: "/organisations/#{organisation.id}/stock-owners")
end
it "includes only active organisations as options" do
expect(response.body).to include(active_organisation.name)
expect(response.body).not_to include(inactive_organisation.name)
end
end
context "and current organisation is deactivated" do
before do
organisation.update!(active: false)
get "/organisations/#{organisation.id}/stock-owners", headers:, params: {}
end
it "does not show the add stock owner button" do
expect(page).not_to have_link("Add a stock owner")
end
it "shows a banner" do
expect(page).to have_content("This organisation is deactivated.")
expect(page).to have_content("You cannot add any new stock owners.")
end
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}/stock-owners", headers:, params: {}
end
it "returns not found 404 from users page" do
expect(response).to have_http_status(:not_found)
end
end
end
context "when accessing the managing agents tab" do
context "with an organisation that the user belongs to" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let!(:other_org_managing_agent) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:inactive_managing_agent) { FactoryBot.create(:organisation, name: "Inactive LTD", active: false) }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") }
before do
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent)
FactoryBot.create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: other_org_managing_agent)
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: inactive_managing_agent)
get "/organisations/#{organisation.id}/managing-agents", 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 managing-agent button" do
expect(page).to have_link("Add a managing agent")
end
it "shows a table of managing-agents" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(managing_agent.name)
end
it "shows only managing-agents for the current user's organisation" do
expect(page).to have_content(managing_agent.name)
expect(page).not_to have_content(other_org_managing_agent.name)
end
it "does not show inactive managing-agents" do
expect(page).not_to have_content(inactive_managing_agent.name)
end
it "shows the pagination count" do
expect(page).to have_content("1 total managing agents")
end
context "and current organisation is deactivated" do
before do
organisation.update!(active: false)
get "/organisations/#{organisation.id}/managing-agents", headers:, params: {}
end
it "does not show the add managing agent button" do
expect(page).not_to have_link("Add a managing agent")
end
it "shows a banner" do
expect(page).to have_content("This organisation is deactivated.")
expect(page).to have_content("You cannot add any new managing agents.")
end
end
end
context "when adding a managing agent" do
let!(:active_organisation) { FactoryBot.create(:organisation, name: "Active Org", active: true) }
let!(:inactive_organisation) { FactoryBot.create(:organisation, name: "Inactive LTD", active: false) }
before do
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {}
end
it "has the correct header" do
expect(response.body).to include("What is the name of your managing agent?")
end
it "includes only active organisations as options" do
expect(response.body).to include(active_organisation.name)
expect(response.body).not_to include(inactive_organisation.name)
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}/managing-agents", headers:, params: {}
end
it "returns not found 404 from users page" do
expect(response).to have_http_status(:not_found)
end
end
end
describe "organisation_relationships#create_stock_owner" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
let(:params) do
{
"organisation_relationship": {
"parent_organisation_id": stock_owner.id,
},
}
end
let(:request) { post "/organisations/#{organisation.id}/stock-owners", 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).to exist(child_organisation_id: organisation.id, parent_organisation_id: stock_owner.id)
end
it "redirects to the organisation list" do
request
expect(response).to redirect_to("/organisations/#{organisation.id}/stock-owners")
end
end
describe "organisation_relationships#create_managing_agent" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let(:params) do
{
"organisation_relationship": {
"child_organisation_id": managing_agent.id,
},
}
end
let(:request) { post "/organisations/#{organisation.id}/managing-agents", 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).to exist(parent_organisation_id: organisation.id, child_organisation_id: managing_agent.id)
end
it "redirects to the organisation list" do
request
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents")
end
end
describe "organisation_relationships#delete_stock_owner" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
let(:params) do
{
"target_organisation_id": stock_owner.id,
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
}
end
let(:request) { delete "/organisations/#{organisation.id}/stock-owners", headers:, params: }
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
end
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}/stock-owners")
end
end
describe "organisation_relationships#delete_managing_agent" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let(:params) do
{
"target_organisation_id": managing_agent.id,
}
end
let(:request) { delete "/organisations/#{organisation.id}/managing-agents", headers:, params: }
before do
FactoryBot.create(
:organisation_relationship,
parent_organisation: organisation,
child_organisation: managing_agent,
)
end
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}/managing-agents")
end
end
end
context "with a data provider user" do
let(:user) { FactoryBot.create(:user) }
before do
sign_in user
end
context "when accessing the stock owners tab" do
context "with an organisation that the user belongs to" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
let!(:other_org_stock_owner) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") }
before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_stock_owner)
get "/organisations/#{organisation.id}/stock-owners", 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 stock owner button" do
expect(page).not_to have_link("Add a stock owner")
end
it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(stock_owner.name)
end
it "shows only stock owners for the current user's organisation" do
expect(page).to have_content(stock_owner.name)
expect(page).not_to have_content(other_org_stock_owner.name)
end
it "shows the pagination count" do
CLDC-3014 Add schemes and locations csv download functionality (#2083) * feat: add schemes and locations download links and pages * feat: update current path helper * feat: update tests for different user visibility levels * feat: update search caption tests * refactor: lint tests * refactor: lint tests * git: revert unintentional inclusion * feat: update tests * refactor: lint * feat: DRY up routing * refactor: lint * feat: add csv confirmation view * feat: add scheme csv service * feat: rename * feat: update csv service * feat: update csv service * feat: update controller and rename view * feat: update view * refactor: lint * feat: show correct headers in csv * feat: add locations and combined csv behaviour * feat: remove redundant user instance variable * feat: add scheme csv service spec * feat: add scheme email csv job tests * feat: update filters in spec * refactor: move scheme_email_csv_job_spec.rb * feat: update spec * refactor: remove blank line * feat: add nowrap to all download links * feat: update org schemes controller with org schemes (and rename for clarity) * feat: update link indentation and spec * feat: only include location LA name, and rename to location_local_authority * feat: update seed locations with westminster local authorities to avoid similar confusion to some that arose in PO review * feat: display multiple active periods on a single line * feat: display multiple active periods on a single line * feat: update line spacing in search captions * feat: replace 2/3 with full column in download page * feat: move scheme alphabeticising into manager * feat: update tests now search/filterless copy has changed * refactor: lint * refactor: lint * refactor: lint * feat: add filter alphabeticising test * feat: correct spacing
1 year ago
expect(page).to have_content("1 total stock owners")
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}/stock-owners", headers:, params: {}
end
it "returns not found 404 from users page" do
expect(response).to have_http_status(:not_found)
end
end
end
context "when directly accessing the page to add a stock owner" do
let(:request) { get "/organisations/#{organisation.id}/stock-owners/add" }
it "returns 401" do
request
expect(response).to have_http_status(:unauthorized)
end
end
context "when directly adding a stock owner" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
let(:params) do
{
"organisation_relationship": {
"parent_organisation_id": stock_owner.id,
},
}
end
let(:request) { post "/organisations/#{organisation.id}/stock-owners", params: }
it "returns 401" do
request
expect(response).to have_http_status(:unauthorized)
end
it "does not create a new organisation relationship" do
expect { request }.not_to change(OrganisationRelationship, :count)
end
end
context "when directly removing a stock owner" do
let(:stock_owner) { FactoryBot.create(:organisation) }
let(:request) { get "/organisations/#{organisation.id}/stock-owners/remove?target_organisation_id=#{stock_owner.id}" }
before do
FactoryBot.create(:organisation_relationship, parent_organisation: stock_owner, child_organisation: organisation)
end
it "returns 401" do
request
expect(response).to have_http_status(:unauthorized)
end
end
context "when directly accessing the page to add a managing agent" do
let(:request) { get "/organisations/#{organisation.id}/managing-agents/add" }
it "returns 401" do
request
expect(response).to have_http_status(:unauthorized)
end
end
context "when directly adding a managing agent" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let(:params) do
{
"organisation_relationship": {
"child_organisation_id": managing_agent.id,
},
}
end
let(:request) { post "/organisations/#{organisation.id}/managing-agents", params: }
it "returns 401" do
request
expect(response).to have_http_status(:unauthorized)
end
it "does not create a new organisation relationship" do
expect { request }.not_to change(OrganisationRelationship, :count)
end
end
context "when directly removing a managing agent" do
let(:managing_agent) { FactoryBot.create(:organisation) }
let(:request) { get "/organisations/#{organisation.id}/managing-agents/remove?target_organisation_id=#{managing_agent.id}" }
before do
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent)
end
it "returns 401" do
request
expect(response).to have_http_status(:unauthorized)
end
end
context "when accessing the managing agents tab" do
context "with an organisation that the user belongs to" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let!(:other_org_managing_agent) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") }
before do
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent)
FactoryBot.create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: other_org_managing_agent)
get "/organisations/#{organisation.id}/managing-agents", 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 managing agent button" do
expect(page).not_to have_link("Add a managing agent")
end
it "shows a table of managing agents" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(managing_agent.name)
end
it "shows only managing agents for the current user's organisation" do
expect(page).to have_content(managing_agent.name)
expect(page).not_to have_content(other_org_managing_agent.name)
end
it "shows the pagination count" do
expect(page).to have_content("1 total managing agents")
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}/managing-agents", headers:, params: {}
end
it "returns not found 404 from users page" do
expect(response).to have_http_status(:not_found)
end
end
end
end
context "with a support user" do
let(:user) { FactoryBot.create(:user, :support) }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
end
describe "organisation_relationships#create_stock_owner" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
let(:params) do
{
"organisation_relationship": {
"parent_organisation_id": stock_owner.id,
},
}
end
let(:request) { post "/organisations/#{organisation.id}/stock-owners", 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).to exist(child_organisation_id: organisation.id, parent_organisation_id: stock_owner.id)
end
it "redirects to the organisation list" do
request
expect(response).to redirect_to("/organisations/#{organisation.id}/stock-owners")
end
end
describe "organisation_relationships#create_managing_agent" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let(:params) do
{
"organisation_relationship": {
"child_organisation_id": managing_agent.id,
},
}
end
let(:request) { post "/organisations/#{organisation.id}/managing-agents", 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).to exist(parent_organisation_id: organisation.id, child_organisation_id: managing_agent.id)
end
it "redirects to the organisation list" do
request
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents")
end
end
describe "organisation_relationships#delete_stock_owner" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
let(:params) do
{
"target_organisation_id": stock_owner.id,
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
}
end
let(:request) { delete "/organisations/#{organisation.id}/stock-owners", headers:, params: }
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
end
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}/stock-owners")
end
end
describe "organisation_relationships#delete_managing_agent" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let(:params) do
{
"target_organisation_id": managing_agent.id,
}
end
let(:request) { delete "/organisations/#{organisation.id}/managing-agents", headers:, params: }
before do
FactoryBot.create(
:organisation_relationship,
parent_organisation: organisation,
child_organisation: managing_agent,
)
end
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}/managing-agents")
end
end
context "when viewing a specific organisation's stock owners" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
let!(:other_org_stock_owner) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_stock_owner)
get "/organisations/#{organisation.id}/stock-owners", headers:, params: {}
end
it "displays the name of the organisation" do
expect(page).to have_content(organisation.name)
end
it "has a sub-navigation with correct tabs" do
expect(page).to have_css(".app-sub-navigation")
expect(page).to have_content("Users")
end
it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(stock_owner.name)
end
it "shows only stock owners for this organisation" do
expect(page).to have_content(stock_owner.name)
expect(page).not_to have_content(other_org_stock_owner.name)
end
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
it "shows remove link(s)" do
expect(response.body).to include("Remove")
end
it "shows the pagination count" do
CLDC-3014 Add schemes and locations csv download functionality (#2083) * feat: add schemes and locations download links and pages * feat: update current path helper * feat: update tests for different user visibility levels * feat: update search caption tests * refactor: lint tests * refactor: lint tests * git: revert unintentional inclusion * feat: update tests * refactor: lint * feat: DRY up routing * refactor: lint * feat: add csv confirmation view * feat: add scheme csv service * feat: rename * feat: update csv service * feat: update csv service * feat: update controller and rename view * feat: update view * refactor: lint * feat: show correct headers in csv * feat: add locations and combined csv behaviour * feat: remove redundant user instance variable * feat: add scheme csv service spec * feat: add scheme email csv job tests * feat: update filters in spec * refactor: move scheme_email_csv_job_spec.rb * feat: update spec * refactor: remove blank line * feat: add nowrap to all download links * feat: update org schemes controller with org schemes (and rename for clarity) * feat: update link indentation and spec * feat: only include location LA name, and rename to location_local_authority * feat: update seed locations with westminster local authorities to avoid similar confusion to some that arose in PO review * feat: display multiple active periods on a single line * feat: display multiple active periods on a single line * feat: update line spacing in search captions * feat: replace 2/3 with full column in download page * feat: move scheme alphabeticising into manager * feat: update tests now search/filterless copy has changed * refactor: lint * refactor: lint * refactor: lint * feat: add filter alphabeticising test * feat: correct spacing
1 year ago
expect(page).to have_content("1 total stock owners")
end
context "when adding a stock owner" do
before do
get "/organisations/#{organisation.id}/stock-owners/add", headers:, params: {}
end
it "has the correct header" do
expect(response.body).to include("What is the name of this organisation&#39;s stock owner?")
end
it "shows an add button" do
expect(page).to have_button("Add")
end
end
end
context "when viewing a specific organisation's managing agents" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let!(:other_org_managing_agent) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
before do
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent)
FactoryBot.create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: other_org_managing_agent)
get "/organisations/#{organisation.id}/managing-agents", headers:, params: {}
end
it "displays the name of the organisation" do
expect(page).to have_content(organisation.name)
end
it "has a sub-navigation with correct tabs" do
expect(page).to have_css(".app-sub-navigation")
expect(page).to have_content("Users")
end
it "shows a table of managing agents" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(managing_agent.name)
end
it "shows only managing agents for this organisation" do
expect(page).to have_content(managing_agent.name)
expect(page).not_to have_content(other_org_managing_agent.name)
end
it "shows the pagination count" do
expect(page).to have_content("1 total managing agents")
end
it "shows remove link(s)" do
expect(response.body).to include("Remove")
end
context "when adding a managing agent" do
before do
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {}
end
it "has the correct header" do
expect(response.body).to include("What is the name of this organisation&#39;s managing agent?")
end
it "shows an add button" do
expect(page).to have_button("Add")
end
it "shows a cancel button" do
expect(page).to have_link("Cancel", href: "/organisations/#{organisation.id}/managing-agents")
end
end
end
end
end
end