Skip to content

Commit

Permalink
Merge pull request #2013 from sanger/Y24-190-use-api-v2-plate-creation
Browse files Browse the repository at this point in the history
Y24-190: Use API v2 for PlateCreation
  • Loading branch information
sdjmchattie authored Oct 23, 2024
2 parents 56e1636 + 559a90b commit 9a6765e
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 249 deletions.
6 changes: 5 additions & 1 deletion app/models/labware_creators/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ def create_plate_with_standard_transfer!
end

def create_plate_from_parent!
api.plate_creation.create!(parent: parent_uuid, child_purpose: purpose_uuid, user: user_uuid)
Sequencescape::Api::V2::PlateCreation.create!(
child_purpose_uuid: purpose_uuid,
parent_uuid: parent_uuid,
user_uuid: user_uuid
)
end

def transfer!(attributes)
Expand Down
9 changes: 9 additions & 0 deletions app/sequencescape/sequencescape/api/v2/plate_creation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

# Represents a plate creation in Limber via the Sequencescape API
class Sequencescape::Api::V2::PlateCreation < Sequencescape::Api::V2::Base
has_one :child, class_name: 'Sequencescape::Api::V2::Plate'
has_one :child_purpose, class_name: 'Sequencescape::Api::V2::PlatePurpose'
has_one :parent, class_name: 'Sequencescape::Api::V2::Plate'
has_one :user, class_name: 'Sequencescape::Api::V2::User'
end
18 changes: 6 additions & 12 deletions spec/features/creating_a_plate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,8 @@
create :v2_plate, uuid: 'child-uuid', barcode_number: 7, state: 'passed', purpose_name: child_purpose_name
end

let!(:plate_creation_request) do
stub_api_post(
'plate_creations',
payload: {
plate_creation: {
parent: plate_uuid,
child_purpose: child_purpose_uuid,
user: user_uuid
}
},
body: json(:plate_creation)
)
let(:plate_creations_attributes) do
[{ child_purpose_uuid: child_purpose_uuid, parent_uuid: plate_uuid, user_uuid: user_uuid }]
end

let(:filters) { {} }
Expand Down Expand Up @@ -93,6 +83,7 @@
end

scenario 'basic plate creation' do
expect_plate_creation
expect_transfer_request_collection_creation

fill_in_swipecard_and_barcode user_swipecard, plate_barcode
Expand All @@ -109,6 +100,7 @@
let(:ancestors_scope) { double('ancestors_scope') }

before do
expect_plate_creation
expect_transfer_request_collection_creation

allow(child_plate).to receive(:stock_plates).and_return(stock_plates)
Expand Down Expand Up @@ -233,6 +225,7 @@
end

scenario 'basic plate creation' do
expect_plate_creation
expect_transfer_request_collection_creation

fill_in_swipecard_and_barcode user_swipecard, plate_barcode
Expand Down Expand Up @@ -276,6 +269,7 @@
end

scenario 'basic plate creation' do
expect_plate_creation
expect_transfer_request_collection_creation

fill_in_swipecard_and_barcode user_swipecard, plate_barcode
Expand Down
12 changes: 1 addition & 11 deletions spec/features/creating_plate_with_bait_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@
# end of stubs for plate_creation baiting page

# These stubs are required to create a new plate with baits
stub_api_post(
'plate_creations',
body: json(:plate_creation),
payload: {
plate_creation: {
parent: plate_uuid,
user: user_uuid,
child_purpose: child_purpose_uuid
}
}
)
stub_api_v2_post('PlateCreation', double(child: child_plate))
stub_api_v2_post('TransferRequestCollection')

# end of stubs for creating a new plate with baits
Expand Down
24 changes: 8 additions & 16 deletions spec/models/labware_creators/baited_plate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
let(:requests) do
Array.new(6) { |i| create :library_request, state: 'started', uuid: "request-#{i}", submission_id: '2' }
end
let(:parent) { create :v2_plate, uuid: parent_uuid, outer_requests: requests, barcode_number: 2 }
let(:child) { create :v2_plate, uuid: 'child-uuid', outer_requests: requests, barcode_number: 3 }
let(:parent_plate) { create :v2_plate, uuid: parent_uuid, outer_requests: requests, barcode_number: 2 }
let(:child_plate) { create :v2_plate, uuid: 'child-uuid', outer_requests: requests, barcode_number: 3 }
let(:transfer_template_uuid) { 'custom-pooling' }
let(:transfer_template) { json :transfer_template, uuid: transfer_template_uuid }

Expand All @@ -38,23 +38,13 @@
context 'create plate' do
has_a_working_api

let!(:plate_creation_request) do
stub_api_post(
'plate_creations',
payload: {
plate_creation: {
parent: parent_uuid,
child_purpose: purpose_uuid,
user: user_uuid
}
},
body: json(:plate_creation)
)
let(:plate_creations_attributes) do
[{ child_purpose_uuid: purpose_uuid, parent_uuid: parent_uuid, user_uuid: user_uuid }]
end

before do
stub_v2_plate(parent, stub_search: false)
stub_v2_plate(child, stub_search: false)
stub_v2_plate(parent_plate, stub_search: false)
stub_v2_plate(child_plate, stub_search: false)

stub_api_v2_post('BaitLibraryLayout')
stub_api_v2_post('BaitLibraryLayout', [bait_library_layout], method: :preview)
Expand All @@ -71,7 +61,9 @@
end

it 'should create objects' do
expect_plate_creation
expect_transfer_request_collection_creation

expect(subject.create_labware!).to eq true
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
{ volume: '20.0', source_asset: well_d1.uuid, target_asset: '3-well-C2', outer_request: requests[3].uuid }
]
end

let(:dest_well_qc_attributes) do
[
{ 'well_name' => 'A1', 'conc' => '1.0' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,7 @@
fixture_file_upload('spec/fixtures/files/duplex_seq/duplex_seq_dil_file.csv', 'sequencescape/qc_file')
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)
)
end
let(:plate_creations_attributes) { [{ child_purpose_uuid:, parent_uuid:, user_uuid: }] }

let(:transfer_requests_attributes) do
[
Expand Down Expand Up @@ -437,11 +425,10 @@
before { stub_api_v2_patch('Well') }

it 'makes the expected transfer requests to bin the wells' do
expect_plate_creation
expect_transfer_request_collection_creation

expect(subject.save!).to eq true

expect(plate_creation_request).to have_been_made
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@

let(:user_uuid) { 'user-uuid' }

let(:plate_creations_attributes) { [{ child_purpose_uuid:, parent_uuid:, user_uuid: }] }

context 'on new' do
has_a_working_api

Expand Down Expand Up @@ -367,20 +369,6 @@
)
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)
)
end

let(:transfer_requests_attributes) do
[
{
Expand Down Expand Up @@ -476,6 +464,7 @@
end

it 'makes the expected method calls when creating the child plate' do
expect_plate_creation
expect_transfer_request_collection_creation

# NB. because we're mocking the API call for the save of the request metadata we cannot
Expand All @@ -485,8 +474,6 @@
expect(subject).to receive(:create_or_update_request_metadata).exactly(14).times

expect(subject.save!).to eq true

expect(plate_creation_request).to have_been_made
end
end

Expand Down Expand Up @@ -683,20 +670,6 @@
)
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)
)
end

# Create child wells in order of the requests they originated from.
# Which is to do with how the binning algorithm lays them out, based on the value of PCR cycles.
# Just done like this to make it easier to match up the requests to the wells.
Expand Down Expand Up @@ -823,6 +796,7 @@
end

it 'makes the expected method calls when creating the child plate' do
expect_plate_creation
expect_transfer_request_collection_creation

# NB. because we're mocking the API call for the save of the request metadata we cannot
Expand All @@ -832,8 +806,6 @@
expect(subject).to receive(:create_or_update_request_metadata).exactly(10).times

expect(subject.save!).to eq true

expect(plate_creation_request).to have_been_made
end
end

Expand Down Expand Up @@ -1029,20 +1001,6 @@
)
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)
)
end

# Create child wells in order of the requests they originated from.
# Which is to do with how the binning algorithm lays them out, based on the value of PCR cycles.
# Just done like this to make it easier to match up the requests to the wells.
Expand Down Expand Up @@ -1169,6 +1127,7 @@
end

it 'makes the expected method calls when creating the child plate' do
expect_plate_creation
expect_transfer_request_collection_creation

# NB. because we're mocking the API call for the save of the request metadata we cannot
Expand All @@ -1178,8 +1137,6 @@
expect(subject).to receive(:create_or_update_request_metadata).exactly(10).times

expect(subject.save!).to eq true

expect(plate_creation_request).to have_been_made
end
end

Expand Down Expand Up @@ -1507,20 +1464,6 @@
)
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)
)
end

before do
allow(pm_pcr_cycles).to receive(:update).and_return(true)

Expand All @@ -1536,13 +1479,12 @@
end

it 'makes the expected method calls when creating the child plate' do
expect_plate_creation
expect_transfer_request_collection_creation

# NB. because we're mocking the API call for the save of the request metadata we cannot
# check the metadata values on the requests, only that the correct method was triggered.
expect(subject.save!).to eq true

expect(plate_creation_request).to have_been_made
end

# Check that we cannot create the child plate whilst there are active requests on the parent plate
Expand All @@ -1551,29 +1493,29 @@
let(:loop_1_request) { create :isc_prep_request, state: 'pending', uuid: 'request-1' }

it 'does not create the child plate' do
expect(Sequencescape::Api::V2::PlateCreation).not_to receive(:create!)

# WellFilter catches that there are 2 active submissions on the well and throws an exception
expect { subject.save! }.to raise_error(LabwareCreators::ResourceInvalid)
expect(subject.errors.messages[:well_filter].count).to eq(1)
expect(subject.errors.messages[:well_filter][0]).to eq(
'found 2 eligible requests for A1, possible overlapping submissions'
)

expect(plate_creation_request).to_not have_been_made
end
end

context 'when the request is not the expected type' do
let(:loop_2_request) { create :library_request, state: 'pending', uuid: 'request-2' }

it 'does not create the child plate' do
expect(Sequencescape::Api::V2::PlateCreation).not_to receive(:create!)

expect { subject.save! }.to raise_error(LabwareCreators::ResourceInvalid)
expect(subject.errors.messages[:base].count).to eq(1)
expect(subject.errors.messages[:base][0]).to eq(
'Parent plate should only contain active requests of type (limber_targeted_nanoseq_isc_prep), ' \
'found unexpected types (limber_wgs)'
)

expect(plate_creation_request).to_not have_been_made
end
end
end
Expand Down
Loading

0 comments on commit 9a6765e

Please sign in to comment.