Skip to content

Commit

Permalink
Merge pull request #2010 from sanger/Y24-190-use-api-v2-plate-conversion
Browse files Browse the repository at this point in the history
Y24-190-3: Use API v2 for PlateConversion calls
  • Loading branch information
sdjmchattie authored Oct 23, 2024
2 parents 702cf2f + c9e6d80 commit 56e1636
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 27 deletions.
18 changes: 9 additions & 9 deletions app/models/labware_creators/tagged_plate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions app/sequencescape/sequencescape/api/v2/plate_conversion.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions spec/features/creating_a_tag_plate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand All @@ -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) }
Expand Down Expand Up @@ -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')
Expand Down
11 changes: 8 additions & 3 deletions spec/models/labware_creators/tagged_plate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
{
Expand Down Expand Up @@ -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')

Expand Down
8 changes: 8 additions & 0 deletions spec/support/api_url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ def expect_bulk_transfer_creation
expect_api_v2_posts('BulkTransfer', bulk_transfer_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',
Expand Down
15 changes: 0 additions & 15 deletions spec/support/shared_tagging_examples.rb
Original file line number Diff line number Diff line change
@@ -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 }

Expand Down

0 comments on commit 56e1636

Please sign in to comment.