Skip to content

Commit

Permalink
Added qcable test for v2 api
Browse files Browse the repository at this point in the history
  • Loading branch information
harrietc52 committed Jan 10, 2025
1 parent 049fc23 commit 4c1462c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/controllers/tag_plates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

# Receives AJAX requests when creating tag plates, returns the
# plate information eg. lot number, template, status
# plate information eg. lot number, template
# The front end makes a decision regarding suitability
class TagPlatesController < ApplicationController
INCLUDES = [:labware, { lot: [{ lot_type: :target_purpose }, :template] }].freeze

def show
qcable_resource = Sequencescape::Api::V2::Qcable.find_by(uuid: params[:id])
qcable_resource = Sequencescape::Api::V2::Qcable.includes(*INCLUDES).find(uuid: params[:id]).first
qcable_presenter = Presenters::QcablePresenter.new(qcable_resource)
respond_to { |format| format.json { render json: { 'qcable' => qcable_presenter } } }
end
Expand Down
47 changes: 47 additions & 0 deletions spec/factories/qcable_factories.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
# frozen_string_literal: true

FactoryBot.define do
# API V2 QCable
factory :v2_qcable, class: Sequencescape::Api::V2::Qcable, traits: [:barcoded_v2] do
skip_create

uuid
state { 'available' }

transient do
labware { create :v2_plate }
lot { create :v2_lot }
end

after(:build) do |qcable, factory|
qcable._cached_relationship(:labware) { factory.labware } if factory.labware
qcable._cached_relationship(:lot) { factory.lot } if factory.lot
qcable._cached_relationship(:asset) { factory.labware } if factory.labware # alias for labware
end
end

factory :v2_lot, class: Sequencescape::Api::V2::Lot do
skip_create

sequence(:lot_number) { |n| "UAT12345.#{n}" }

transient do
lot_type { create :v2_lot_type }
template { create :v2_tag_layout_template }
end

after(:build) do |lot, factory|
lot._cached_relationship(:lot_type) { factory.lot_type } if factory.lot_type
lot._cached_relationship(:template) { factory.template } if factory.template
end
end

factory :v2_lot_type, class: Sequencescape::Api::V2::LotType do
skip_create

sequence(:name) { |n| "LotType#{n}" }

transient { target_purpose { create :v2_purpose } }

after(:build) do |lot_type, factory|
lot_type._cached_relationship(:target_purpose) { factory.target_purpose } if factory.target_purpose
end
end

# API V1 Qcable (Records the QC status of eg. a tag plate)
factory :qcable, class: Limber::Qcable, traits: %i[api_object barcoded] do
with_belongs_to_associations 'lot', 'qcable_creator', 'asset'
Expand Down
7 changes: 3 additions & 4 deletions spec/features/creating_a_tag_plate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
purpose_uuid: 'stock-plate-purpose-uuid'
)
end
let(:qcable) { create :v2_qcable }

let(:tag_plate_barcode) { SBCF::SangerBarcode.new(prefix: 'DN', number: 2).machine_barcode.to_s }
let(:tag_plate_qcable_uuid) { 'tag-plate-qcable' }
Expand Down Expand Up @@ -91,10 +92,8 @@
stub_v2_barcode_printers(create_list(:v2_plate_barcode_printer, 3))
stub_v2_tag_layout_templates(templates)

# API v1 UUID requests for a qcable via qcable_presenter.
stub_api_get(tag_plate_qcable_uuid, body: tag_plate_qcable)
stub_api_get('lot-uuid', body: json(:tag_lot, lot_number: tag_lot_number, template_uuid: tag_template_uuid))
stub_api_get('tag-lot-type-uuid', body: json(:tag_lot_type))
# API v2 requests for the qcable
stub_v2_qcable(qcable)
end

shared_examples 'it supports the plate' do
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 @@ -258,6 +258,14 @@ def stub_v2_qc_file(qc_file)
allow(Sequencescape::Api::V2::QcFile).to receive(:find).with(*arguments).and_return([qc_file])
end

def stub_v2_qcable(qcable)
arguments = [{ uuid: qcable.uuid }]
query_builder = double

allow(query_builder).to receive(:find_by).with(*arguments).and_return(qcable)
allow(Sequencescape::Api::V2::Qcable).to receive(:includes).and_return(query_builder)
end

def stub_v2_study(study)
arguments = [{ name: study.name }]
allow(Sequencescape::Api::V2::Study).to receive(:find).with(*arguments).and_return([study])
Expand Down

0 comments on commit 4c1462c

Please sign in to comment.