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.

66 lines
3.3 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"
describe ProcessMergeRequestJob do
let(:job) { described_class.new }
let(:merge_organisations_service) { instance_double(Merge::MergeOrganisationsService) }
before do
allow(Merge::MergeOrganisationsService).to receive(:new).and_return(merge_organisations_service)
allow(merge_organisations_service).to receive(:call).and_return(nil)
end
context "when processing a merge request" do
let(:organisation) { create(:organisation) }
let(:merging_organisation) { create(:organisation) }
let(:other_merging_organisation) { create(:organisation) }
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: organisation, merge_date: Time.zone.local(2022, 3, 3), total_users: 5, total_schemes: 5, total_lettings_logs: 2, total_sales_logs: 8, total_managing_agents: 2, total_stock_owners: 1, existing_absorbing_organisation: true) }
before do
create(:merge_request_organisation, merge_request:, merging_organisation:)
create(:merge_request_organisation, merge_request:, merging_organisation: other_merging_organisation)
end
it "calls the merge organisations service with correct arguments" do
expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: organisation.id, merging_organisation_ids: [merging_organisation.id, other_merging_organisation.id], merge_date: Time.zone.local(2022, 3, 3), absorbing_organisation_active_from_merge_date: false)
job.perform(merge_request:)
expect(merge_request.reload.status).to eq("request_merged")
end
context "with new absorbing organisation" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: organisation, merge_date: Time.zone.local(2022, 3, 3), existing_absorbing_organisation: false) }
it "calls the merge organisations service with correct arguments" do
expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: organisation.id, merging_organisation_ids: [merging_organisation.id, other_merging_organisation.id], merge_date: Time.zone.local(2022, 3, 3), absorbing_organisation_active_from_merge_date: true)
job.perform(merge_request:)
expect(merge_request.reload.status).to eq("request_merged")
end
end
it "clears last_failed_attempt value" do
merge_request.update!(last_failed_attempt: Time.zone.now)
job.perform(merge_request:)
expect(merge_request.reload.last_failed_attempt).to be_nil
end
it "sets last_failed_attempt value, sets processing to false and clears all outcomes if there's an error" do
allow(merge_organisations_service).to receive(:call).and_raise(ActiveRecord::Rollback)
expect(merge_request.last_failed_attempt).to be_nil
job.perform(merge_request:)
merge_request.reload
expect(merge_request.last_failed_attempt).to be_within(10.seconds).of(Time.zone.now)
expect(merge_request.processing).to eq(false)
expect(merge_request.total_users).to be_nil
expect(merge_request.total_schemes).to be_nil
expect(merge_request.total_managing_agents).to be_nil
expect(merge_request.total_stock_owners).to be_nil
expect(merge_request.total_lettings_logs).to be_nil
expect(merge_request.total_sales_logs).to be_nil
end
end
end