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.

452 lines
21 KiB

CLDC-3382 Add support user functionality to merge organisations (#2566) * CLDC-2093 Merge organisations page - view all merge requests (#2561) * CLDC-3585 Update absorbing organisation question (#2564) * Update user permissions and absorbing org question order * Update absorbing organisation question and routing * CLDC 2094: View a merge request (#2565) * CLDC-3584 Update merging orgs question (#2567) * Update merging organisations question * Update rebase tests * Update routing between CYA and questions * CLDC-3586 Update merge date merge request question (#2571) * Remove unused paths and update merge date * lint * Create delete merge request functionality (#2568) * CLDC-3588: Add helpdesk ticket question (#2572) * Merge request fixes (#2578) * Add cancel button to merging orgs and update merging orgs selection * Update submit button text * Update back buttons * CLDC-2101 Add begin merge (#2575) * Calculate merge request status * Add start merge and merge request job * Update merge request when it gets processed * Refactor and display a banner for failed requests * update test * Update change links * Update copy for error message (#2583) * Do not display cancel button if there's no submit (#2584) * Update hint date (#2588) * CLDC-2100++ Add success notification after delete (#2589) * Update helpdesk_ticket.html.erb * CLDC-2094++ Merge details page adjustments (#2593) * Change page name and hide buttons during processing status * Update test * Make merge request status dynamic (#2592) * Make merge request status dynamic * Update tests * Keep check answers referrer when validation is hit (#2594) * Keep check answers referrer when validation is hit * Remove absorbing org from merging organisations list * Update text to handle singular merge requests * Add merge start confirmation page (#2601) * Set merge request as non processing if it fails (#2598) * Set merge request to no longer processing if it fails * clear last_failed_attempt as soon as we start processing the merge * CLDC-3603 View merged users outcomes (#2602) * Update user outcomes view link * Add user outcomes page * Set user outcomes before merge and on merge fail * Update hardcoded total user count * Account for singular user numbers * CLDC-3603 View scheme outcomes (#2604) * Update scheme outcomes view link * Add scheme outcomes page * Update scheme outcome before merge and on merge fail * Update back links in merge outcomes pages (#2611) * CLDC-3605 View relationships page (#2606) * CLDC-3609 Add existing absorbing organisation merge request question (#2600) * Add existing absorbing organisation page and field * Update status calculation and add new question to check answers * Call correct merge service flow * Update test * Update test * Return correct status when existing_absorbing_organisation is false (#2617) * Change styling of relationship outcomes page (#2619) * CLDC-3604 View logs outcomes (#2618) * Update view logs outcomes link * Add logs outcomes page * Set logs outcome before merge and on merge fail * Update logs outcomes text * Update line break * Fix incorrect filtering of relationships and count * Fix test * Fix test * Fix test * Make example date depend on collection year (#2620) --------- Co-authored-by: Manny Dinssa <44172848+Dinssa@users.noreply.github.com>
4 months ago
require "rails_helper"
RSpec.describe MergeRequest, type: :model do
describe ".visible" do
let(:open_collection_period_start_date) { 1.year.ago }
let!(:merged_recent) { create(:merge_request, request_merged: true, merge_date: 3.months.ago) }
let!(:merged_old) { create(:merge_request, request_merged: true, merge_date: 18.months.ago) }
let!(:not_merged) { create(:merge_request, request_merged: false) }
before do
allow(FormHandler.instance).to receive(:start_date_of_earliest_open_collection_period).and_return(open_collection_period_start_date)
end
it "includes merged requests with merge dates after the open collection period start date" do
expect(described_class.visible).to include(merged_recent)
end
it "excludes merged requests with merge dates before the open collection period start date" do
expect(described_class.visible).not_to include(merged_old)
end
it "includes not_merged requests" do
expect(described_class.visible).to include(not_merged)
end
end
describe "#discard!" do
let(:merge_request) { create(:merge_request) }
it "sets the discarded_at field" do
merge_request.discard!
expect(merge_request.discarded_at).not_to be_nil
end
it "does not delete the record" do
merge_request.discard!
expect(merge_request).to be_persisted
end
it "is not visible in the visible scope" do
merge_request.discard!
expect(described_class.visible).not_to include(merge_request)
end
end
describe "#status" do
it "returns the correct status for deleted merge request" do
merge_request = build(:merge_request, id: 1, discarded_at: Time.zone.today)
expect(merge_request.status).to eq MergeRequest::STATUS[:deleted]
end
it "returns the correct status for a merged request" do
merge_request = build(:merge_request, id: 1, request_merged: true)
expect(merge_request.status).to eq MergeRequest::STATUS[:request_merged]
end
it "returns the correct status for a ready to merge request" do
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation), merge_date: Time.zone.today, existing_absorbing_organisation: true)
create(:merge_request_organisation, merge_request:)
expect(merge_request.status).to eq MergeRequest::STATUS[:ready_to_merge]
end
it "returns the correct status for a ready to merge request when existing_absorbing_organisation is false" do
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation), merge_date: Time.zone.today, existing_absorbing_organisation: false)
create(:merge_request_organisation, merge_request:)
expect(merge_request.status).to eq MergeRequest::STATUS[:ready_to_merge]
end
it "returns the merge issues if dsa is not signed for absorbing organisation" do
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation, with_dsa: false), merge_date: Time.zone.today, existing_absorbing_organisation: true)
create(:merge_request_organisation, merge_request:)
expect(merge_request.status).to eq MergeRequest::STATUS[:merge_issues]
end
it "returns the incomplete if absorbing organisation is missing" do
merge_request = build(:merge_request, id: 1, absorbing_organisation: nil, merge_date: Time.zone.today)
create(:merge_request_organisation, merge_request:)
expect(merge_request.status).to eq MergeRequest::STATUS[:incomplete]
end
it "returns the incomplete if merge requests organisation is missing" do
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation), merge_date: Time.zone.today)
expect(merge_request.status).to eq MergeRequest::STATUS[:incomplete]
end
it "returns the incomplete if merge date is missing" do
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation))
create(:merge_request_organisation, merge_request:)
expect(merge_request.status).to eq MergeRequest::STATUS[:incomplete]
end
it "returns the incomplete if existing absorbing organisation is missing" do
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation, with_dsa: false), merge_date: Time.zone.today)
create(:merge_request_organisation, merge_request:)
expect(merge_request.status).to eq MergeRequest::STATUS[:incomplete]
end
it "returns processing if merge is processing" do
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation), processing: true)
create(:merge_request_organisation, merge_request:)
expect(merge_request.status).to eq MergeRequest::STATUS[:processing]
end
end
describe "#organisations_with_users" do
context "when absorbing organisation has users" do
let(:merge_request) { create(:merge_request, absorbing_organisation:) }
let(:absorbing_organisation) { create(:organisation) }
before do
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1)
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2)
end
context "and some merging organisations have users" do
let(:merging_organisation_1) { create(:organisation) }
let(:merging_organisation_2) { create(:organisation, with_dsa: false) }
it "returns correct organisations with users" do
expect(absorbing_organisation.users.count).to eq(1)
expect(merging_organisation_1.users.count).to eq(1)
expect(merging_organisation_2.users.count).to eq(0)
expect(merge_request.organisations_with_users.count).to eq(2)
expect(merge_request.organisations_with_users).to include(merging_organisation_1)
expect(merge_request.organisations_with_users).to include(absorbing_organisation)
end
end
context "and no merging organisations have users" do
let(:merging_organisation_1) { create(:organisation, with_dsa: false) }
let(:merging_organisation_2) { create(:organisation, with_dsa: false) }
it "returns correct organisations with users" do
expect(absorbing_organisation.users.count).to eq(1)
expect(merging_organisation_1.users.count).to eq(0)
expect(merging_organisation_2.users.count).to eq(0)
expect(merge_request.organisations_with_users.count).to eq(1)
expect(merge_request.organisations_with_users).to include(absorbing_organisation)
end
end
end
context "when absorbing organisation has no users" do
let(:merge_request) { create(:merge_request, absorbing_organisation:) }
let(:absorbing_organisation) { create(:organisation, with_dsa: false) }
before do
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1)
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2)
end
context "and some merging organisations have users" do
let(:merging_organisation_1) { create(:organisation) }
let(:merging_organisation_2) { create(:organisation, with_dsa: false) }
it "returns correct organisations with users" do
expect(merging_organisation_1.users.count).to eq(1)
expect(absorbing_organisation.users.count).to eq(0)
expect(merging_organisation_2.users.count).to eq(0)
expect(merge_request.organisations_with_users.count).to eq(1)
expect(merge_request.organisations_with_users).to include(merging_organisation_1)
end
end
context "and no merging organisations have users" do
let(:merging_organisation_1) { create(:organisation, with_dsa: false) }
let(:merging_organisation_2) { create(:organisation, with_dsa: false) }
it "returns correct organisations with users" do
expect(absorbing_organisation.users.count).to eq(0)
expect(merging_organisation_1.users.count).to eq(0)
expect(merging_organisation_2.users.count).to eq(0)
expect(merge_request.organisations_with_users.count).to eq(0)
end
end
end
end
describe "#organisations_with_schemes" do
let(:merge_request) { create(:merge_request, absorbing_organisation:) }
let(:absorbing_organisation) { create(:organisation) }
let(:merging_organisation_1) { create(:organisation) }
let(:merging_organisation_2) { create(:organisation) }
before do
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1)
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2)
end
context "when absorbing organisation has schemes" do
before do
create(:scheme, owning_organisation: absorbing_organisation)
end
context "and some merging organisations have schemes" do
before do
create(:scheme, owning_organisation: merging_organisation_1)
end
it "returns correct organisations with schemes" do
expect(absorbing_organisation.owned_schemes.count).to eq(1)
expect(merging_organisation_1.owned_schemes.count).to eq(1)
expect(merging_organisation_2.owned_schemes.count).to eq(0)
expect(merge_request.organisations_with_schemes.count).to eq(2)
expect(merge_request.organisations_with_schemes).to include(merging_organisation_1)
expect(merge_request.organisations_with_schemes).to include(absorbing_organisation)
end
end
context "and no merging organisations have schemes" do
it "returns correct organisations with schemes" do
expect(absorbing_organisation.owned_schemes.count).to eq(1)
expect(merging_organisation_1.owned_schemes.count).to eq(0)
expect(merging_organisation_2.owned_schemes.count).to eq(0)
expect(merge_request.organisations_with_schemes.count).to eq(1)
expect(merge_request.organisations_with_schemes).to include(absorbing_organisation)
end
end
end
context "when absorbing organisation has no schemes" do
context "and some merging organisations have schemes" do
before do
create(:scheme, owning_organisation: merging_organisation_1)
end
it "returns correct organisations with schemes" do
expect(merging_organisation_1.owned_schemes.count).to eq(1)
expect(absorbing_organisation.owned_schemes.count).to eq(0)
expect(merging_organisation_2.owned_schemes.count).to eq(0)
expect(merge_request.organisations_with_schemes.count).to eq(1)
expect(merge_request.organisations_with_schemes).to include(merging_organisation_1)
end
end
context "and no merging organisations have schemes" do
it "returns correct organisations with schemes" do
expect(absorbing_organisation.owned_schemes.count).to eq(0)
expect(merging_organisation_1.owned_schemes.count).to eq(0)
expect(merging_organisation_2.owned_schemes.count).to eq(0)
expect(merge_request.organisations_with_schemes.count).to eq(0)
end
end
end
end
describe "#organisations_without_users" do
context "when absorbing organisation has users" do
let(:merge_request) { create(:merge_request, absorbing_organisation:) }
let(:absorbing_organisation) { create(:organisation) }
before do
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1)
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2)
end
context "and some merging organisations have users" do
let(:merging_organisation_1) { create(:organisation) }
let(:merging_organisation_2) { create(:organisation, with_dsa: false) }
it "returns correct organisations with users" do
expect(absorbing_organisation.users.count).to eq(1)
expect(merging_organisation_1.users.count).to eq(1)
expect(merging_organisation_2.users.count).to eq(0)
expect(merge_request.organisations_without_users.count).to eq(1)
expect(merge_request.organisations_without_users).to include(merging_organisation_2)
end
end
context "and no merging organisations have users" do
let(:merging_organisation_1) { create(:organisation, with_dsa: false) }
let(:merging_organisation_2) { create(:organisation, with_dsa: false) }
it "returns correct organisations with users" do
expect(absorbing_organisation.users.count).to eq(1)
expect(merging_organisation_1.users.count).to eq(0)
expect(merging_organisation_2.users.count).to eq(0)
expect(merge_request.organisations_without_users.count).to eq(2)
expect(merge_request.organisations_without_users).to include(merging_organisation_1)
expect(merge_request.organisations_without_users).to include(merging_organisation_2)
end
end
end
context "when absorbing organisation has no users" do
let(:merge_request) { create(:merge_request, absorbing_organisation:) }
let(:absorbing_organisation) { create(:organisation, with_dsa: false) }
before do
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1)
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2)
end
context "and some merging organisations have users" do
let(:merging_organisation_1) { create(:organisation) }
let(:merging_organisation_2) { create(:organisation, with_dsa: false) }
it "returns correct organisations with users" do
expect(merging_organisation_1.users.count).to eq(1)
expect(absorbing_organisation.users.count).to eq(0)
expect(merging_organisation_2.users.count).to eq(0)
expect(merge_request.organisations_without_users.count).to eq(2)
expect(merge_request.organisations_without_users).to include(absorbing_organisation)
expect(merge_request.organisations_without_users).to include(merging_organisation_2)
end
end
context "and no merging organisations have users" do
let(:merging_organisation_1) { create(:organisation, with_dsa: false) }
let(:merging_organisation_2) { create(:organisation, with_dsa: false) }
it "returns correct organisations with users" do
expect(absorbing_organisation.users.count).to eq(0)
expect(merging_organisation_1.users.count).to eq(0)
expect(merging_organisation_2.users.count).to eq(0)
expect(merge_request.organisations_without_users.count).to eq(3)
expect(merge_request.organisations_without_users).to include(absorbing_organisation)
expect(merge_request.organisations_without_users).to include(merging_organisation_1)
expect(merge_request.organisations_without_users).to include(merging_organisation_2)
end
end
end
end
describe "#organisations_without_schemes" do
let(:merge_request) { create(:merge_request, absorbing_organisation:) }
let(:absorbing_organisation) { create(:organisation) }
let(:merging_organisation_1) { create(:organisation) }
let(:merging_organisation_2) { create(:organisation) }
before do
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1)
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2)
end
context "when absorbing organisation has schemes" do
before do
create(:scheme, owning_organisation: absorbing_organisation)
end
context "and some merging organisations have schemes" do
before do
create(:scheme, owning_organisation: merging_organisation_1)
end
it "returns correct organisations with schemes" do
expect(absorbing_organisation.owned_schemes.count).to eq(1)
expect(merging_organisation_1.owned_schemes.count).to eq(1)
expect(merging_organisation_2.owned_schemes.count).to eq(0)
expect(merge_request.organisations_without_schemes.count).to eq(1)
expect(merge_request.organisations_without_schemes).to include(merging_organisation_2)
end
end
context "and no merging organisations have schemes" do
it "returns correct organisations with schemes" do
expect(absorbing_organisation.owned_schemes.count).to eq(1)
expect(merging_organisation_1.owned_schemes.count).to eq(0)
expect(merging_organisation_2.owned_schemes.count).to eq(0)
expect(merge_request.organisations_without_schemes.count).to eq(2)
expect(merge_request.organisations_without_schemes).to include(merging_organisation_1)
expect(merge_request.organisations_without_schemes).to include(merging_organisation_2)
end
end
end
context "when absorbing organisation has no schemes" do
context "and some merging organisations have schemes" do
before do
create(:scheme, owning_organisation: merging_organisation_1)
end
it "returns correct organisations with schemes" do
expect(merging_organisation_1.owned_schemes.count).to eq(1)
expect(absorbing_organisation.owned_schemes.count).to eq(0)
expect(merging_organisation_2.owned_schemes.count).to eq(0)
expect(merge_request.organisations_without_schemes.count).to eq(2)
expect(merge_request.organisations_without_schemes).to include(absorbing_organisation)
expect(merge_request.organisations_without_schemes).to include(merging_organisation_2)
end
end
context "and no merging organisations have schemes" do
it "returns correct organisations with schemes" do
expect(absorbing_organisation.owned_schemes.count).to eq(0)
expect(merging_organisation_1.owned_schemes.count).to eq(0)
expect(merging_organisation_2.owned_schemes.count).to eq(0)
expect(merge_request.organisations_without_schemes.count).to eq(3)
expect(merge_request.organisations_without_schemes).to include(absorbing_organisation)
expect(merge_request.organisations_without_schemes).to include(merging_organisation_1)
expect(merge_request.organisations_without_schemes).to include(merging_organisation_2)
end
end
end
end
describe "relationship outcomes" do
let(:stock_owner1) { create(:organisation, name: "Stock owner 1") }
let(:stock_owner2) { create(:organisation, name: "Stock owner 2") }
let(:stock_owner3) { create(:organisation, name: "Stock owner 3") }
let(:managing_agent1) { create(:organisation, name: "Managing agent 1") }
let(:managing_agent2) { create(:organisation, name: "Managing agent 2") }
let(:absorbing_organisation) { create(:organisation, name: "Absorbing Org") }
let(:merging_organisations) { create_list(:organisation, 2) { |org, i| org.name = "Dummy Org #{i + 1}" } }
let(:merge_request) { create(:merge_request, absorbing_organisation:, merging_organisations:) }
before do
create(:organisation_relationship, child_organisation: absorbing_organisation, parent_organisation: stock_owner1)
create(:organisation_relationship, child_organisation: merging_organisations.first, parent_organisation: stock_owner2)
create(:organisation_relationship, child_organisation: merging_organisations.first, parent_organisation: stock_owner1)
create(:organisation_relationship, child_organisation: merging_organisations.first, parent_organisation: stock_owner3)
create(:organisation_relationship, parent_organisation: absorbing_organisation, child_organisation: managing_agent1)
create(:organisation_relationship, parent_organisation: absorbing_organisation, child_organisation: managing_agent2)
create(:organisation_relationship, parent_organisation: merging_organisations.first, child_organisation: managing_agent2)
end
describe "#total_stock_owners_after_merge" do
it "returns the correct count of stock owners after merge" do
expect(merge_request.total_stock_owners_after_merge).to eq(3)
end
end
describe "#total_managing_agents_after_merge" do
it "returns the correct count of managing agents after merge" do
expect(merge_request.total_managing_agents_after_merge).to eq(2)
end
end
describe "#total_stock_owners_managing_agents_label" do
it "returns the correct label" do
expect(merge_request.total_stock_owners_managing_agents_label).to eq("3 stock owners\n2 managing agents")
end
end
end
end