From aa384b5916035a6ab742fa73d3b257c9f379c636 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 21 Oct 2024 11:17:57 +0100 Subject: [PATCH 1/2] Use SS API v2 for PlateConversion call --- app/models/labware_creators/tagged_plate.rb | 18 +++++++++--------- .../sequencescape/api/v2/plate_conversion.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 app/sequencescape/sequencescape/api/v2/plate_conversion.rb diff --git a/app/models/labware_creators/tagged_plate.rb b/app/models/labware_creators/tagged_plate.rb index bd2366bab..3a22d2993 100644 --- a/app/models/labware_creators/tagged_plate.rb +++ b/app/models/labware_creators/tagged_plate.rb @@ -42,8 +42,8 @@ def create_plate! flag_tag_plate_as_exhausted - # Convert plate instead of creating it - # Target returns the newly converted tag plate + # Convert plate instead of creating it. + # Target returns the newly converted tag plate. @child = convert_tag_plate_to_new_purpose.target true @@ -64,16 +64,16 @@ def enforce_same_template_within_pool? private # - # Convert the tag plate to the new purpose + # Convert the tag plate to the new purpose. # - # @return [Sequencescape::Api::PlateConversion] The conversion action + # @return [Sequencescape::Api::V2::PlateConversion] The result of the conversion. # def convert_tag_plate_to_new_purpose - api.plate_conversion.create!( - target: tag_plate.asset_uuid, - purpose: purpose_uuid, - user: user_uuid, - parent: parent_uuid + Sequencescape::Api::V2::PlateConversion.create!( + parent_uuid: parent_uuid, + purpose_uuid: purpose_uuid, + target_uuid: tag_plate.asset_uuid, + user_uuid: user_uuid ) end diff --git a/app/sequencescape/sequencescape/api/v2/plate_conversion.rb b/app/sequencescape/sequencescape/api/v2/plate_conversion.rb new file mode 100644 index 000000000..cbc59635c --- /dev/null +++ b/app/sequencescape/sequencescape/api/v2/plate_conversion.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +# plate conversion resource +class Sequencescape::Api::V2::PlateConversion < Sequencescape::Api::V2::Base + has_one :parent, class_name: 'Sequencescape::Api::V2::Plate' + has_one :purpose, class_name: 'Sequencescape::Api::V2::PlatePurpose' + has_one :target, class_name: 'Sequencescape::Api::V2::Plate' + has_one :user, class_name: 'Sequencescape::Api::V2::User' +end From c529b4304e5876646ccc8256eb58e82eff2c55f1 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 21 Oct 2024 14:26:26 +0100 Subject: [PATCH 2/2] Fix tests for V2 API usage of PlateConversion --- spec/features/creating_a_tag_plate_spec.rb | 7 +++++++ spec/models/labware_creators/tagged_plate_spec.rb | 11 ++++++++--- spec/support/api_url_helper.rb | 8 ++++++++ spec/support/shared_tagging_examples.rb | 15 --------------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/spec/features/creating_a_tag_plate_spec.rb b/spec/features/creating_a_tag_plate_spec.rb index 4b6acc0c5..8b4cde153 100644 --- a/spec/features/creating_a_tag_plate_spec.rb +++ b/spec/features/creating_a_tag_plate_spec.rb @@ -29,6 +29,7 @@ pool_sizes: [8, 8], submission_pools_count: pools end + let(:tag_plate_barcode) { SBCF::SangerBarcode.new(prefix: 'DN', number: 2).machine_barcode.to_s } let(:tag_plate_qcable_uuid) { 'tag-plate-qcable' } let(:tag_plate_uuid) { 'tag-plate-uuid' } @@ -49,6 +50,10 @@ ] end + let(:plate_conversions_attributes) do + [{ parent_uuid: plate_uuid, purpose_uuid: child_purpose_uuid, target_uuid: tag_plate_uuid, user_uuid: user_uuid }] + end + let(:tag_template_uuid) { 'tag-layout-template-0' } let(:submission_pools) { json(:submission_pool_collection) } @@ -102,6 +107,8 @@ end scenario 'creation with the plate' do + expect_plate_conversion_creation + fill_in_swipecard_and_barcode user_swipecard, plate_barcode plate_title = find('#plate-title') expect(plate_title).to have_text('Limber Cherrypicked') diff --git a/spec/models/labware_creators/tagged_plate_spec.rb b/spec/models/labware_creators/tagged_plate_spec.rb index 782b82cd6..6124acb1d 100644 --- a/spec/models/labware_creators/tagged_plate_spec.rb +++ b/spec/models/labware_creators/tagged_plate_spec.rb @@ -182,6 +182,10 @@ let(:tag2_tube_uuid) { 'tag2-tube' } let(:tag2_template_uuid) { 'tag2-layout-template' } + let(:plate_conversions_attributes) do + [{ parent_uuid: plate_uuid, purpose_uuid: child_purpose_uuid, target_uuid: tag_plate_uuid, user_uuid: user_uuid }] + end + let(:state_changes_attributes) do [ { @@ -227,23 +231,24 @@ } end + it_behaves_like 'it has a custom page', 'tagged_plate' + it 'can be created' do expect(subject).to be_a LabwareCreators::TaggedPlate end - it_behaves_like 'it has a custom page', 'tagged_plate' - context 'on save' do it 'creates a tag plate' do + expect_plate_conversion_creation expect_state_change_creation expect_transfer_creation expect(subject.save).to be true - expect(plate_conversion_request).to have_been_made.once expect(tag_layout_creation_request).to have_been_made.once end it 'has the correct child (and uuid)' do + expect_plate_conversion_creation stub_api_v2_post('Transfer') stub_api_v2_post('StateChange') diff --git a/spec/support/api_url_helper.rb b/spec/support/api_url_helper.rb index 5e72ba417..03ba13b4b 100644 --- a/spec/support/api_url_helper.rb +++ b/spec/support/api_url_helper.rb @@ -97,6 +97,14 @@ def expect_custom_metadatum_collection_creation expect_api_v2_posts('CustomMetadatumCollection', custom_metadatum_collections_attributes) end + def expect_plate_conversion_creation + expect_api_v2_posts( + 'PlateConversion', + plate_conversions_attributes, + plate_conversions_attributes.map { |e| double(target: double(uuid: e[:target_uuid])) } + ) + end + def expect_pooled_plate_creation expect_api_v2_posts( 'PooledPlateCreation', diff --git a/spec/support/shared_tagging_examples.rb b/spec/support/shared_tagging_examples.rb index 44037b2b0..1a1ed49ae 100644 --- a/spec/support/shared_tagging_examples.rb +++ b/spec/support/shared_tagging_examples.rb @@ -1,21 +1,6 @@ # frozen_string_literal: true RSpec.shared_context 'a tag plate creator' do - let!(:plate_conversion_request) do - stub_api_post( - 'plate_conversions', - payload: { - plate_conversion: { - user: user_uuid, - target: tag_plate_uuid, - purpose: child_purpose_uuid, - parent: plate_uuid - } - }, - body: '{}' # We don't care - ) - end - let(:tag_layout_template) { json(:tag_layout_template, uuid: tag_template_uuid) } let(:enforce_uniqueness) { true }