Skip to content

Commit

Permalink
Merge pull request #148 from sanger/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
pjvv authored May 6, 2020
2 parents 4864bf2 + 010088a commit 6d75c7f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 29 deletions.
29 changes: 12 additions & 17 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-05-01 07:09:23 +0100 using RuboCop version 0.82.0.
# on 2020-05-05 17:37:22 +0100 using RuboCop version 0.82.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -32,7 +32,7 @@ Layout/EmptyLineAfterGuardClause:
- 'features/step_definitions/delayed_job_steps.rb'
- 'features/support/sequencescape.rb'

# Offense count: 98
# Offense count: 101
# Cop supports --auto-correct.
Layout/EmptyLineAfterMagicComment:
Enabled: false
Expand Down Expand Up @@ -166,36 +166,31 @@ Lint/UselessAssignment:
- 'db/migrate/20150202171723_add_destroy_labware.rb'
- 'features/support/fake_sinatra_service.rb'

# Offense count: 12
# Offense count: 13
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 44
Max: 41

# Offense count: 2
# Offense count: 7
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 35

# Offense count: 1
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 4

# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 15
# Offense count: 16
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 29
Max: 26

# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 10
Max: 9

# Offense count: 4
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
Expand Down Expand Up @@ -253,7 +248,7 @@ Style/BarePercentLiterals:
- 'features/step_definitions/bed_verification_steps.rb'
- 'features/step_definitions/delayed_job_steps.rb'

# Offense count: 35
# Offense count: 40
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle.
# SupportedStyles: nested, compact
Expand All @@ -268,7 +263,7 @@ Style/ConditionalAssignment:
Exclude:
- 'app/controllers/process_plates_controller.rb'

# Offense count: 84
# Offense count: 88
Style/Documentation:
Enabled: false

Expand Down Expand Up @@ -521,7 +516,7 @@ Style/StderrPuts:
- 'config/boot.rb'
- 'lib/tasks/cucumber.rake'

# Offense count: 1
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Expand Down Expand Up @@ -564,7 +559,7 @@ Style/WordArray:
- 'test/unit/instrument_javascript_presenter_test.rb'
- 'test/unit/witness_test.rb'

# Offense count: 313
# Offense count: 390
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down
27 changes: 15 additions & 12 deletions app/controllers/process_plates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@ def create
api: api
)
if bed_layout_verification.validate_and_create_audits?(params)
# if the instrument process is "Receive plates", call the 'wrangler/tube_rack' API
# the param is called 'source_plates' but we could be working with tube racks or plates etc.
barcodes = sanitize_barcodes(params[:source_plates])
receive_plates_process = InstrumentProcess.find_by(id: params[:instrument_process]).key.eql?('slf_receive_plates')

if barcodes && receive_plates_process
# call the lighthouse service first as we are assuming that most labware scanned will be
# plates from Lighthouse Labs
lighthouse_responses = Lighthouse.call_api(barcodes)
# find out if the 'receive_plates' process was executed
receive_plates_process = InstrumentProcess.find_by(id: params[:instrument_process]).key.eql?('slf_receive_plates')

# keeping it simple for now, if all the responses are not CREATED, send ALL the barcodes
# to the wrangler
wrangler_responses = Wrangler.call_api(barcodes) unless all_created?(lighthouse_responses)
end
call_external_services(barcodes) if barcodes && receive_plates_process

# add a flash on the page for the number of unique barcodes scanned in
num_unique_barcodes = bed_layout_verification.process_plate&.barcodes.uniq.length
Expand All @@ -57,7 +50,17 @@ def create
end
end

private
# Call any external services - currently lighthouse service for plates from Lighthouse Labs and
# wrangler for tube racks. If no samples are found in the lighthouse service, try the wrangler
def call_external_services(barcodes)
# call the lighthouse service first as we are assuming that most labware scanned will be
# plates from Lighthouse Labs
lighthouse_responses = Lighthouse.call_api(barcodes)

# keeping it simple for now, if all the responses are not CREATED, send ALL the barcodes
# to the wrangler
wrangler_responses = Wrangler.call_api(barcodes) unless all_created?(lighthouse_responses)
end

# Returns a list of unique barcodes by removing blanks and duplicates
def sanitize_barcodes(barcodes)
Expand All @@ -68,6 +71,6 @@ def sanitize_barcodes(barcodes)
def all_created?(responses)
return false if responses.empty?

responses.all? { |response| response[:code] == 201 }
responses.all? { |response| response[:code] == "201" }
end
end
40 changes: 40 additions & 0 deletions test/controllers/process_plates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'test_helper'
require 'lighthouse'
require 'wrangler'

class ProcessPlatesControllerTest < ActiveSupport::TestCase
context 'while testing public functions' do
should 'sanitize barcodes' do
assert_equal(ProcessPlatesController.new.sanitize_barcodes('123 456'), %w[123 456])
assert_equal(ProcessPlatesController.new.sanitize_barcodes('123 456'), %w[123 456])
assert_equal(ProcessPlatesController.new.sanitize_barcodes('123 123 456'), %w[123 456])
assert_equal(ProcessPlatesController.new.sanitize_barcodes("123\n456"), %w[123 456])
end

should 'verify all responses are HTTP CREATED (201)' do
assert_equal(ProcessPlatesController.new.all_created?([]), false)
assert_equal(ProcessPlatesController.new.all_created?([{ code: '201' }, { code: '201' }]), true)
assert_equal(ProcessPlatesController.new.all_created?([{ code: 201 }, { code: 201 }]), false)
assert_equal(ProcessPlatesController.new.all_created?([{ code: '201' }, { code: '200' }]), false)
end

should 'call external services 1' do
Lighthouse.expects(:call_api).with(%w[123 456]).returns([])
Wrangler.expects(:call_api).with(%w[123 456])
ProcessPlatesController.new.call_external_services(%w[123 456])
end

should 'call external services 2' do
Lighthouse.expects(:call_api).with(%w[123 456]).returns([{ code: 400 }])
Wrangler.expects(:call_api).with(%w[123 456])
ProcessPlatesController.new.call_external_services(%w[123 456])
end

should 'call only lighthouse service' do
Lighthouse.expects(:call_api).returns([{ code: '201' }])
ProcessPlatesController.new.call_external_services(%w[123 456])
end
end
end

0 comments on commit 6d75c7f

Please sign in to comment.