From f6407e56d7d851d92b0fbb9b6975ea4be19a2725 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Tue, 22 Oct 2024 12:31:13 +0100 Subject: [PATCH] Fix tests in quadrant_split_plate_spec --- .../quadrant_split_plate_spec.rb | 40 +++---------------- spec/support/api_url_helper.rb | 10 ++--- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/spec/models/labware_creators/quadrant_split_plate_spec.rb b/spec/models/labware_creators/quadrant_split_plate_spec.rb index 7ba59b15e..decd5ed32 100644 --- a/spec/models/labware_creators/quadrant_split_plate_spec.rb +++ b/spec/models/labware_creators/quadrant_split_plate_spec.rb @@ -27,15 +27,7 @@ let(:stock_purpose_name) { 'Merger Plate Purpose' } let(:stock_plate_barcode) { 1 } - let(:stock_plate_v1) do - json( - :stock_plate_with_metadata, - purpose_name: stock_purpose_name, - barcode_number: stock_plate_barcode, - uuid: stock_plate_uuid - ) - end - let(:stock_plate_v2) do + let(:stock_plate) do create( :v2_stock_plate_for_plate, purpose_name: stock_purpose_name, @@ -64,7 +56,7 @@ create( :v2_plate, uuid: parent_uuid, - stock_plate: stock_plate_v2, + stock_plate: stock_plate, barcode_number: '2', size: parent_plate_size, outer_requests: requests @@ -123,11 +115,6 @@ { user_id: user.id, asset_id: child_plate_d.id, metadata: { stock_barcode: "* #{child_plate_d.barcode.machine}" } } end - let(:child_plate_a_v1) { json(:plate_with_metadata, uuid: 'child-a-uuid', barcode_number: '3') } - let(:child_plate_b_v1) { json(:plate_with_metadata, uuid: 'child-b-uuid', barcode_number: '4') } - let(:child_plate_c_v1) { json(:plate_with_metadata, uuid: 'child-c-uuid', barcode_number: '5') } - let(:child_plate_d_v1) { json(:plate_with_metadata, uuid: 'child-d-uuid', barcode_number: '6') } - before do create(:purpose_config, name: child_purpose_name, uuid: child_purpose_uuid) allow(Sequencescape::Api::V2::Plate).to receive(:find_all).with( @@ -153,31 +140,14 @@ [child_plate_a_create_args, child_plate_b_create_args, child_plate_c_create_args, child_plate_d_create_args] end - let!(:plate_creation_request) do - stub_api_post( - 'plate_creations', - payload: { - plate_creation: { - parent: parent_uuid, - child_purpose: child_purpose_uuid, - user: user_uuid - } - }, - body: [ - json(:plate_creation, child_uuid: 'child-a-uuid'), - json(:plate_creation, child_uuid: 'child-b-uuid'), - json(:plate_creation, child_uuid: 'child-c-uuid'), - json(:plate_creation, child_uuid: 'child-d-uuid') - ] - ) - end + let(:plate_creations_attributes) { [{ child_purpose_uuid:, parent_uuid:, user_uuid: }] * 4 } before do allow(SearchHelper).to receive(:merger_plate_names).and_return(stock_purpose_name) stub_v2_user(user) - stub_v2_labware(stock_plate_v2) + stub_v2_labware(stock_plate) stub_v2_labware(child_plate_a) stub_v2_labware(child_plate_b) stub_v2_labware(child_plate_c) @@ -186,11 +156,11 @@ it 'makes the expected requests' do expect_custom_metadatum_collection_creation + expect_plate_creation([child_plate_a, child_plate_b, child_plate_c, child_plate_d]) expect_transfer_request_collection_creation expect(subject.save!).to eq true - expect(plate_creation_request).to have_been_made.times(4) expect(subject.redirection_target).to eq(plate) end end diff --git a/spec/support/api_url_helper.rb b/spec/support/api_url_helper.rb index 5ae2521eb..3b0201f97 100644 --- a/spec/support/api_url_helper.rb +++ b/spec/support/api_url_helper.rb @@ -97,12 +97,10 @@ def expect_custom_metadatum_collection_creation expect_api_v2_posts('CustomMetadatumCollection', custom_metadatum_collections_attributes) end - def expect_plate_creation - expect_api_v2_posts( - 'PlateCreation', - plate_creations_attributes, - [double(child: child_plate)] * plate_creations_attributes.size - ) + def expect_plate_creation(child_plates = nil) + child_plates ||= [child_plate] * plate_creations_attributes.size + return_values = child_plates.map { |child_plate| double(child: child_plate) } + expect_api_v2_posts('PlateCreation', plate_creations_attributes, return_values) end def expect_pooled_plate_creation