Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y24-190-3: Use SpecificTubeCreation on API v2 #1916

Merged
11 changes: 5 additions & 6 deletions app/models/labware_creators/plate_split_to_tube_racks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,12 @@ def parent_wells_for_contingency
# @param tube_attributes [Hash] A hash of attributes to use for the created tubes.
# @return [Hash<String, Tube>] A hash of the created tubes indexed by name.
def create_tubes(tube_purpose_uuid, number_of_tubes, tube_attributes)
api
.specific_tube_creation
Sequencescape::Api::V2::SpecificTubeCreation
.create!(
user: user_uuid,
parent: parent_uuid,
child_purposes: [tube_purpose_uuid] * number_of_tubes,
tube_attributes: tube_attributes
child_purpose_uuids: [tube_purpose_uuid] * number_of_tubes,
parent_uuids: [parent_uuid],
andrewsparkes marked this conversation as resolved.
Show resolved Hide resolved
tube_attributes: tube_attributes,
user_uuid: user_uuid
)
.children
.index_by(&:name)
Expand Down
11 changes: 5 additions & 6 deletions app/models/labware_creators/pooled_tubes_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ def create_labware!
end

def create_child_stock_tubes
api
.specific_tube_creation
Sequencescape::Api::V2::SpecificTubeCreation
.create!(
user: user_uuid,
parent: parent_uuid,
child_purposes: [purpose_uuid] * pool_uuids.length,
tube_attributes: tube_attributes
child_purpose_uuids: [purpose_uuid] * pool_uuids.length,
parent_uuids: [parent_uuid],
tube_attributes: tube_attributes,
user_uuid: user_uuid
)
.children
.index_by(&:name)
Expand Down
11 changes: 5 additions & 6 deletions app/models/labware_creators/pooled_tubes_by_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ def parent_v1
# Have we made this class so cardinal-specific (e.g. lookup of ancestor vac tubes) that it cannot be re-used?

def create_child_stock_tubes
api
.specific_tube_creation
Sequencescape::Api::V2::SpecificTubeCreation
.create!(
user: user_uuid,
parent: parent_uuid,
child_purposes: [purpose_uuid] * pool_uuids.length,
tube_attributes: tube_attributes
child_purpose_uuids: [purpose_uuid] * pool_uuids.length,
parent_uuids: [parent_uuid],
tube_attributes: tube_attributes,
user_uuid: user_uuid
)
.children
.index_by(&:name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ class PooledTubesBySubmissionWithPhiX < PooledTubesBySubmission
attr_accessor :spikedbuffer_tube_barcode

def create_child_stock_tubes
api
.specific_tube_creation
Sequencescape::Api::V2::SpecificTubeCreation
.create!(
user: user_uuid,
parents: parents,
child_purposes: [purpose_uuid] * pool_uuids.length,
tube_attributes: tube_attributes
parent_uuids: parents,
tube_attributes: tube_attributes,
user_uuid: user_uuid
)
.children
.index_by(&:name)
Expand Down
17 changes: 10 additions & 7 deletions app/models/labware_creators/pooled_tubes_from_whole_plates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ class PooledTubesFromWholePlates < Base

def create_labware!
# Create a single tube
# TODO: This should link to multiple parents in production
# TODO: {Y24-190} See if we can do all the transfers as part of the SpecificTubeCreation instead of separately.
@child =
api
.specific_tube_creation
Sequencescape::Api::V2::SpecificTubeCreation
.create!(
user: user_uuid,
parent: parents.first.uuid,
child_purposes: [purpose_uuid],
tube_attributes: [{ name: "#{stock_plate_barcode}+" }]
child_purpose_uuids: [purpose_uuid],
parent_uuids: [parents.first.uuid],
tube_attributes: [{ name: "#{stock_plate_barcode}+" }],
user_uuid: user_uuid
)
.children
.first
Expand All @@ -40,6 +39,10 @@ def stock_plate_barcode
"#{parents.first.stock_plate.barcode.prefix}#{parents.first.stock_plate.barcode.number}"
end

def redirection_target
TubeProxy.new(@child.uuid)
end

# TODO: This should probably be asynchronous
def available_plates
@search_options = OngoingPlate.new(purposes: [parent.plate_purpose.uuid], include_used: false, states: ['passed'])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Represents a specific tube creation in Limber via the Sequencescape API
class Sequencescape::Api::V2::SpecificTubeCreation < Sequencescape::Api::V2::Base
andrewsparkes marked this conversation as resolved.
Show resolved Hide resolved
has_many :children, class_name: 'Sequencescape::Api::V2::Tube'
StephenHulme marked this conversation as resolved.
Show resolved Hide resolved
has_many :parents, class_name: 'Sequencescape::Api::V2::Labware'
has_one :user, class_name: 'Sequencescape::Api::V2::User'
end
51 changes: 19 additions & 32 deletions spec/features/pooling_multiple_plates_into_one_tube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,13 @@
end
let(:example_plate_3_listed) { associated(*example_plate3_args) }

let(:child_tube_uuid) { 'tube-0' }
let(:child_tube) do
create :v2_tube, purpose_uuid: 'child-purpose-0', purpose_name: 'Pool tube', uuid: child_tube_uuid
end
let(:child_tube) { create :v2_tube, purpose_uuid: 'child-purpose-0', purpose_name: 'Pool tube' }

let(:tube_creation_request_uuid) { SecureRandom.uuid }

let!(:tube_creation_request) do
# TODO: In reality we want to link in all four parents.
stub_api_post(
'specific_tube_creations',
payload: {
specific_tube_creation: {
user: user_uuid,
parent: plate_uuid,
child_purposes: ['child-purpose-0'],
tube_attributes: [{ name: 'DN2+' }]
}
},
body: json(:specific_tube_creation, uuid: tube_creation_request_uuid, children_count: 1)
)
end
let(:specific_tube_creation) do
response = double
allow(response).to receive(:children).and_return([child_tube])

# Find out what tubes we've just made!
let!(:tube_creation_children_request) do
stub_api_get(tube_creation_request_uuid, 'children', body: json(:tube_collection, names: ['DN1+']))
response
end

# Used to fetch the pools. This is the kind of thing we could pass through from a custom form
Expand Down Expand Up @@ -119,8 +100,6 @@

stub_v2_plate(example_plate_new_api)

stub_v2_plate(example_plate_new_api)

stub_api_get(plate_uuid, body: example_plate)
stub_api_get(plate_uuid, 'wells', body: well_set_a)

Expand All @@ -132,13 +111,25 @@
scenario 'creates multiple plates' do
stub_v2_plate(example_plate_2)

expect_api_v2_posts(
'SpecificTubeCreation',
[
{
child_purpose_uuids: ['child-purpose-0'],
parent_uuids: [plate_uuid],
tube_attributes: [{ name: 'DN2+' }],
user_uuid: user_uuid
}
],
[specific_tube_creation]
)
expect_api_v2_posts(
'Transfer',
[plate_uuid, plate_uuid_2].map do |source_uuid|
{
user_uuid: user_uuid,
source_uuid: source_uuid,
destination_uuid: 'tube-0',
destination_uuid: child_tube.uuid,
transfer_template_uuid: 'whole-plate-to-tube'
}
end
Expand All @@ -156,15 +147,11 @@
click_on('Make Pool')
expect(page).to have_text('New empty labware added to the system')
expect(page).to have_text('Pool tube')

# This isn't strictly speaking correct to test. But there isn't a great way
# of confirming that the right information got passed to the back end otherwise.
# (Although you expect it to fail on an incorrect request)
expect(tube_creation_request).to have_been_made
end

scenario 'detects tag clash' do
stub_v2_plate(example_plate_3)

fill_in_swipecard_and_barcode(user_swipecard, plate_barcode_1)
plate_title = find('#plate-title')
expect(plate_title).to have_text('example-purpose')
Expand Down
48 changes: 23 additions & 25 deletions spec/models/labware_creators/custom_pooled_tubes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,28 @@
)
end

let(:tube_creation_request_uuid) { SecureRandom.uuid }

let(:tube_creation_request) do
stub_api_post(
'specific_tube_creations',
payload: {
specific_tube_creation: {
user: user_uuid,
parent: parent_uuid,
child_purposes: [purpose_uuid, purpose_uuid],
tube_attributes: [{ name: 'DN5 A1:B2' }, { name: 'DN5 C1:G2' }]
def expect_specific_tube_creation
child_tubes = [
create(:v2_tube, name: 'DN5 A1:B2', uuid: 'tube-0'),
create(:v2_tube, name: 'DN5 C1:G2', uuid: 'tube-1')
]

# Create a mock for the specific tube creation.
specific_tube_creation = double
allow(specific_tube_creation).to receive(:children).and_return(child_tubes)

# Expect the post request and return the mock.
expect_api_v2_posts(
'SpecificTubeCreation',
[
{
child_purpose_uuids: [purpose_uuid, purpose_uuid],
parent_uuids: [parent_uuid],
tube_attributes: child_tubes.map { |tube| { name: tube.name } },
user_uuid: user_uuid
}
},
body: json(:specific_tube_creation, uuid: tube_creation_request_uuid, children_count: 2)
)
end

# Find out what tubes we've just made!
let(:tube_creation_children_request) do
stub_api_get(
tube_creation_request_uuid,
'children',
body: json(:tube_collection, names: ['DN5 A1:B2', 'DN5 C1:G2'])
],
[specific_tube_creation]
)
end

Expand Down Expand Up @@ -138,8 +137,6 @@
before do
stub_parent_request
stub_qc_file_creation
tube_creation_children_request
tube_creation_request
transfer_creation_request
end

Expand All @@ -149,9 +146,10 @@
end

it 'pools according to the file' do
expect_specific_tube_creation

expect(subject.save).to be_truthy
expect(stub_qc_file_creation).to have_been_made.once
expect(tube_creation_request).to have_been_made.once
expect(transfer_creation_request).to have_been_made.once
end
end
Expand Down
Loading
Loading