-
Notifications
You must be signed in to change notification settings - Fork 34
add labware updated_at value and return the latest one #5780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 4 commits
4619bae
62216ec
4989c67
c9b87f9
4b05c16
23afcf4
79423ce
92ac84d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -368,8 +368,18 @@ def obtain_retention_instructions | |
| metadata.symbolize_keys[:retention_instruction] | ||
| end | ||
|
|
||
| def lookup_labwhere_location | ||
| lookup_labwhere(machine_barcode) || lookup_labwhere(human_barcode) | ||
| def lookup_labwhere_location # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity | ||
| machine_lookup = lookup_labwhere(machine_barcode) | ||
| human_lookup = lookup_labwhere(human_barcode) | ||
|
|
||
| valid_lookups = [machine_lookup, human_lookup].compact.select { |lookup| lookup[:location].present? } | ||
| return valid_lookups.max_by { |lookup| lookup[:updated_at] || Time.zone.at(0) }[:location] if valid_lookups.any? | ||
|
|
||
| return 'Not found - There is a problem with Labwhere' if [machine_lookup, human_lookup].any? do |lookup| | ||
| lookup&.dig(:error) | ||
| end | ||
|
|
||
| nil | ||
| end | ||
|
|
||
| def lookup_labwhere(barcode) | ||
|
|
@@ -378,9 +388,23 @@ def lookup_labwhere(barcode) | |
| rescue StandardError => e | ||
| # rescue LabWhereClient::LabwhereException => e | ||
| Rails.logger.error { e } | ||
| return 'Not found - There is a problem with Labwhere' | ||
| return { error: true } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we maybe return a message as well? I don't think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added error messages in return |
||
| end | ||
| info_from_labwhere.location.location_info if info_from_labwhere.present? && info_from_labwhere.location.present? | ||
|
|
||
| return nil unless info_from_labwhere.present? && info_from_labwhere.location.present? | ||
|
|
||
| { | ||
| location: info_from_labwhere.location.location_info, | ||
| updated_at: parse_labwhere_timestamp(info_from_labwhere.updated_at) | ||
| } | ||
| end | ||
|
|
||
| def parse_labwhere_timestamp(timestamp) | ||
| return if timestamp.blank? | ||
|
|
||
| Time.zone.parse(timestamp) | ||
| rescue ArgumentError | ||
| nil | ||
| end | ||
| end | ||
| # rubocop:enable Metrics/ClassLength | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,4 +83,26 @@ | |
| end | ||
| end | ||
| end | ||
|
|
||
| describe LabWhereClient::Labware do | ||
| let(:params) do | ||
| { | ||
| 'barcode' => '123456', | ||
| 'updated_at' => 'Wednesday May 6 2026 10:46', | ||
| 'location' => { | ||
| 'name' => 'f1', | ||
| 'parentage' => 'Sanger / Ogilvie / AA216', | ||
| 'barcode' => 'lw-f1-26214', | ||
| 'updated_at' => 'Tuesday June 6 2023 16:26' | ||
| } | ||
| } | ||
| end | ||
|
|
||
| it 'captures labware and location updated_at values from the API payload' do | ||
| labware = described_class.new(params) | ||
|
|
||
| expect(labware.updated_at).to eq('Wednesday May 6 2026 10:46') | ||
| expect(labware.location.updated_at).to eq('Tuesday June 6 2023 16:26') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This date format is nice for humans, but non-standard and difficult for computers to parse. May I suggest that the updated_at fields are always represented as ISO 8601 standard strings?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated. |
||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,6 +200,10 @@ | |
| end | ||
|
|
||
| describe 'report generation' do | ||
| before do | ||
| allow(LabWhereClient::Labware).to receive(:find_by_barcode).and_return(nil) | ||
| end | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this mocking out the actual code we are testing? Or is it not important to this test?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re-write to include human barcode |
||
|
|
||
| shared_examples 'a successful report' do | ||
| it 'generates the expected report rows' do | ||
| expect(location_report.save).to be_truthy | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to reduce the complexity of this function (possibly by pulling out some private methods)?
It's difficult to understand exactly what the new code does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored.