-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from JamesGlover/fix_missing_events_on_human_r…
…eadable Events consider human readable barcodes
- Loading branch information
Showing
6 changed files
with
101 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class TestSearchResult | ||
attr_accessor :barcode, :uuid | ||
def initialize(machine_barcode, uuid: 'uuid') | ||
# Not what actually happens, but it'll work for our purposes | ||
encoded_barcode = machine_barcode.bytes.map { |b| (b % 48).to_s }.join | ||
@uuid = uuid | ||
@barcode = OpenStruct.new(ean13: encoded_barcode, machine: machine_barcode) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
class TestSequencescapeApi | ||
class CreatedStore | ||
attr_reader :created | ||
|
||
def initialize | ||
@created = [] | ||
end | ||
|
||
def create!(params) | ||
@created << params | ||
end | ||
end | ||
|
||
attr_accessor :plate | ||
attr_accessor :barcode | ||
attr_accessor :barcode_to_results | ||
|
||
def initialize(barcode_to_results) | ||
@barcode_to_results = barcode_to_results | ||
end | ||
|
||
def asset_audit | ||
@asset_audit ||= CreatedStore.new | ||
end | ||
|
||
def search | ||
self | ||
end | ||
|
||
def find(_search_uuid) | ||
self | ||
end | ||
|
||
def all(_plate, options = {}) | ||
@barcode_to_results[options[:barcode]] || [] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
require 'test_helper' | ||
require 'support/test_sequencescape_api' | ||
require 'support/test_search_result' | ||
|
||
class ProcessPlateTest < ActiveSupport::TestCase | ||
context 'Generating remote asset audits' do | ||
setup do | ||
ipi = Factory :instrument_processes_instrument | ||
@instrument = ipi.instrument | ||
@instrument_process = ipi.instrument_process | ||
end | ||
|
||
context 'where all parameters are valid' do | ||
setup do | ||
User.stubs(:login_from_user_code).with('123').returns('abc') | ||
User.stubs(:login_from_user_code).with('456').returns('def') | ||
@api = TestSequencescapeApi.new(['DN456S'] => [TestSearchResult.new('DN456S', uuid: 'plate-uuid')]) | ||
|
||
process_plate = ProcessPlate.new( | ||
api: @api, | ||
user_barcode: '123', | ||
instrument_barcode: @instrument.barcode.to_s, | ||
source_plates: 'DN456S', | ||
visual_check: false, | ||
instrument_process_id: @instrument.instrument_processes.first.id.to_s, | ||
witness_barcode: '456' | ||
) | ||
process_plate.save | ||
process_plate.create_audits_without_delay | ||
end | ||
|
||
should 'generate remote asset audits' do | ||
assert_equal @api.asset_audit.created.length, 1 | ||
assert_equal(@api.asset_audit.created.first, key: @instrument_process.key, | ||
message: "Process '#{@instrument_process.name}' performed on instrument #{@instrument.name}", | ||
created_by: 'abc', | ||
asset: 'plate-uuid', | ||
witnessed_by: 'def') | ||
end | ||
end | ||
end | ||
end |