Skip to content

Commit

Permalink
Refactor message tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harrietc52 committed Jul 5, 2023
1 parent 0099a32 commit fa66d53
Showing 1 changed file with 145 additions and 127 deletions.
272 changes: 145 additions & 127 deletions spec/pipelines/pacbio/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,156 +2,174 @@

require 'rails_helper'

# TODO: add multiple wells to the plates
RSpec.describe 'PacBio', pacbio: true, type: :model do
let(:timestamp) { Time.zone.parse('Mon, 08 Apr 2019 09:15:11 UTC +00:00') }
let(:pacbio_config) { Pipelines.configure(Pipelines.load_yaml).pacbio }

before do
allow(Time).to receive(:current).and_return timestamp

# Create a default pacbio smrt link version for pacbio runs.
create(:pacbio_smrt_link_version, name: 'v10', default: true)
end

let(:config) { Pipelines.configure(Pipelines.load_yaml) }
let(:pacbio_config) { config.pacbio }
let(:revio_run) { create(:pacbio_revio_run) }
let(:revio_message) { Messages::Message.new(object: revio_run, configuration: pacbio_config.message) }
shared_examples 'check the high level content' do
it 'has a lims' do
expect(message.content[:lims]).to eq(pacbio_config.lims)
end

it 'has a key' do
expect(message.content[pacbio_config.key]).not_to be_empty
end
end

shared_examples 'check the keys' do
it 'must have a id_pac_bio_run_lims' do
expect(key[:id_pac_bio_run_lims]).to eq(run.name)
end

# let(:sequel_run) { create(:pacbio_sequel_run) }
# let(:sequel_message) { Messages::Message.new(object: sequel_run, configuration: pacbio_config.message) }
it 'must have a pac_bio_run_uuid' do
expect(key[:pac_bio_run_uuid]).to eq(run.uuid)
end

# TODO: test run with multiple plates, with multiple wells
it 'must have a pac_bio_run_name' do
expect(key[:pac_bio_run_name]).to eq(run.name)
end

it 'has a lims' do
expect(revio_message.content[:lims]).to eq(pacbio_config.lims)
# expect(sequel_message.content[:lims]).to eq(pacbio_config.lims)
it 'must have a last_updated field' do
expect(key[:last_updated]).to eq(timestamp)
end
end

it 'has a key' do
expect(revio_message.content[pacbio_config.key]).not_to be_empty
# expect(sequel_message.content[pacbio_config.key]).not_to be_empty
shared_examples 'check the plate wells' do
it 'will have the correct number' do
expect(key[:wells].length).to eq(run.wells.count)
end
end

describe 'key' do
let(:revio_key) { revio_message.content[pacbio_config.key] }
# let(:sequel_key) { sequel_message.content[pacbio_config.key] }
shared_examples 'check each well' do
it 'must have the' do
expect(message_well[:well_label]).to eq(well.position)
end

let(:timestamp) { Time.zone.parse('Mon, 08 Apr 2019 09:15:11 UTC +00:00') }
it 'must have a plate number' do
expect(message_well[:plate_number]).to eq(well.plate.plate_number)
end

before do
allow(Time).to receive(:current).and_return timestamp
it 'must have a well label' do
expect(message_well[:well_label]).to eq(well.position)
end

it 'must have a id_pac_bio_run_lims' do
expect(revio_key[:id_pac_bio_run_lims]).to eq(revio_run.name)
# expect(sequel_key[:id_pac_bio_run_lims]).to eq(sequel_run.name)
it 'must have a well uuid lims' do
expect(message_well[:well_uuid_lims]).to eq(well.uuid)
end
end

it 'must have a pac_bio_run_uuid' do
expect(revio_key[:pac_bio_run_uuid]).to eq(revio_run.uuid)
# expect(sequel_key[:pac_bio_run_uuid]).to eq(sequel_run.uuid)
shared_examples 'check the plate samples' do
it 'will have the correct number' do
expect(message_well[:samples].length).to eq(5)
end
end

it 'must have a pac_bio_run_name' do
expect(revio_key[:pac_bio_run_name]).to eq(revio_run.name)
# expect(sequel_key[:pac_bio_run_name]).to eq(sequel_run.name)
shared_examples 'check each sample' do
let(:library) { well.libraries.first }
let(:request) { library.request }

it 'must have a cost code' do
expect(message_sample[:cost_code]).to eq(request.cost_code)
end

it 'must have a last_updated field' do
expect(revio_key[:last_updated]).to eq(timestamp)
# expect(sequel_key[:last_updated]).to eq(timestamp)
end

context 'wells' do
let(:plate_well) { revio_run.plates.first.wells.first }
let(:message_well) { revio_key[:wells].first }
# let(:sequel_message_well) { sequel_key[:wells].first }

it 'will have the correct number' do
expect(revio_key[:wells].length).to eq(revio_run.wells.count)
# expect(sequel_key[:wells].length).to eq(sequel_run.wells.count)
end

context 'each' do
# TODO: check each well for revio run
it 'must have a plate number' do
expect(message_well[:plate_number]).to eq(plate_well.plate.plate_number)
end

it 'must have a plate uuid lims' do
expect(message_well[:plate_uuid_lims]).to eq(plate_well.plate.uuid)
end

it 'must have a well label' do
expect(message_well[:well_label]).to eq(plate_well.position)
end

it 'must have a well uuid lims' do
expect(message_well[:well_uuid_lims]).to eq(plate_well.uuid)
end
end

context 'samples' do
# TODO: check each sample for revio run
let(:libraries) { create_list(:pacbio_library, 5, :tagged) }
let(:library) { libraries.first }
let(:pool) { create(:pacbio_pool, libraries:) }
let(:request) { library.request }
let(:message_sample) { message_well[:samples].first }
let(:request_library) { requests.first }

before do
plate_well.pools = [pool]
end

it 'will have the correct number' do
expect(message_well[:samples].length).to eq(5)
end

it 'must have a cost code' do
expect(message_sample[:cost_code]).to eq(request.cost_code)
end

it 'must have a library tube id' do
expect(message_sample[:pac_bio_library_tube_id_lims]).to eq(library.id)
end

it 'must have a well uuid lims' do
expect(message_sample[:pac_bio_library_tube_uuid]).to eq(library.uuid)
end

it 'must have a sample name' do
expect(message_sample[:pac_bio_library_tube_name]).to eq(library.request.sample_name)
end

it 'can have a pool barcode' do
expect(message_sample[:pac_bio_library_tube_barcode]).to eq(library.pool.tube.barcode)
end

it 'must have a sample_uuid' do
expect(message_sample[:sample_uuid]).to eq(request.sample.external_id)
end

it 'must have a study_uuid' do
expect(message_sample[:study_uuid]).to eq(request.external_study_id)
end

it 'can have a tag sequence' do
expect(message_sample[:tag_sequence]).to eq(library.tag.oligo)
end

it 'can have a tag group id' do
expect(message_sample[:tag_set_id_lims]).to eq(library.tag.tag_set.id)
end

it 'can have a tag identifier' do
expect(message_sample[:tag_identifier]).to eq(library.tag.group_id)
end

it 'can have a tag set name' do
expect(message_sample[:tag_set_name]).to eq(library.tag.tag_set.name)
end

it 'can have a pipeline id' do
expect(message_sample[:pipeline_id_lims]).to eq(request.library_type)
end
end
it 'must have a library tube id' do
expect(message_sample[:pac_bio_library_tube_id_lims]).to eq(library.id)
end

it 'must have a well uuid lims' do
expect(message_sample[:pac_bio_library_tube_uuid]).to eq(library.uuid)
end

it 'must have a sample name' do
expect(message_sample[:pac_bio_library_tube_name]).to eq(request.sample_name)
end

it 'can have a pool barcode' do
expect(message_sample[:pac_bio_library_tube_barcode]).to eq(library.pool.tube.barcode)
end

it 'must have a sample_uuid' do
expect(message_sample[:sample_uuid]).to eq(request.sample.external_id)
end

it 'must have a study_uuid' do
expect(message_sample[:study_uuid]).to eq(request.external_study_id)
end

it 'can have a tag sequence' do
expect(message_sample[:tag_sequence]).to eq(library.tag.oligo)
end

it 'can have a tag group id' do
expect(message_sample[:tag_set_id_lims]).to eq(library.tag.tag_set.id)
end

it 'can have a tag identifier' do
expect(message_sample[:tag_identifier]).to eq(library.tag.group_id)
end

it 'can have a tag set name' do
expect(message_sample[:tag_set_name]).to eq(library.tag.tag_set.name)
end

it 'can have a pipeline id' do
expect(message_sample[:pipeline_id_lims]).to eq(request.library_type)
end
end

context 'when the run is Sequel IIe' do
let(:run) { create(:pacbio_sequel_run) }
let(:libraries) { create_list(:pacbio_library, 5, :tagged) }
let(:pool) { create(:pacbio_pool, libraries:) }

let(:message) { Messages::Message.new(object: run, configuration: pacbio_config.message) }
let(:key) { message.content[pacbio_config.key] }

let(:message_well) { key[:wells][0] }
let(:message_sample) { message_well[:samples][0] }
let(:well) { run.plates[0].wells[0] }

before do
well.pools = [pool]
end

it_behaves_like 'check the high level content'
it_behaves_like 'check the keys'
it_behaves_like 'check the plate wells'
it_behaves_like 'check each well'
it_behaves_like 'check the plate samples'
it_behaves_like 'check each sample'
end

context 'when the run is Revio' do
let(:run) { create(:pacbio_revio_run) }
let(:libraries) { create_list(:pacbio_library, 5, :tagged) }
let(:pool) { create(:pacbio_pool, libraries:) }

let(:message) { Messages::Message.new(object: run, configuration: pacbio_config.message) }
let(:key) { message.content[pacbio_config.key] }

let(:message_well) { key[:wells][0] }
let(:message_sample) { message_well[:samples][0] }
let(:well) { run.plates[0].wells[0] }

before do
well.pools = [pool]
end

it_behaves_like 'check the high level content'
it_behaves_like 'check the keys'
it_behaves_like 'check the plate wells'
it_behaves_like 'check each well'
it_behaves_like 'check the plate samples'
it_behaves_like 'check each sample'
end
end

0 comments on commit fa66d53

Please sign in to comment.