Skip to content
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

Y24-190 Milestone 1: API v1 -> v2 Migration #1884

Merged
merged 80 commits into from
Sep 19, 2024
Merged

Conversation

sdjmchattie
Copy link
Contributor

Milestone 1 for #1772

Changes proposed in this pull request

Note that these changes were tested by the Integration Suite after deployment to UAT: https://gitlab.internal.sanger.ac.uk/psd/integration-suite/-/pipelines/300247/builds

Instructions for Reviewers

[All PRs] - Confirm PR template filled
[Feature Branches] - Review code

Only just found out about it and it looks like it hasn't been done by anyone in recent times.
It's used by sub-classes so they need to be fixed first
…mium-pipelines

Y24-190-2: Use SS API v2 for barcode printers

# This returns an array of well location to pool pairs. The 'walker' is responsible for actually doing the walking
# of the wells that are acceptable, and it calls back with the location of the well being processed.
def group_wells(plate)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because we are supporting v1 as well until this work is complete.


# Performs the coercion of this instance so that it behaves appropriately given the direction
# and walking algorithm information.
def coerce
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because we are supporting v1 as well until this work is complete.

Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 99.49495% with 6 lines in your changes missing coverage. Please review.

Project coverage is 77.96%. Comparing base (1588ba2) to head (c841bbb).
Report is 91 commits behind head on develop.

Files with missing lines Patch % Lines
...escape/sequencescape/api/v2/tag_layout_template.rb 91.66% 2 Missing ⚠️
...ncerns/labware_creators/support_v2_source_plate.rb 85.71% 1 Missing ⚠️
app/models/labels/plate_split.rb 0.00% 1 Missing ⚠️
app/models/labware_creators/pooled_tubes_base.rb 75.00% 1 Missing ⚠️
app/sequencescape/sequencescape/api/v2/transfer.rb 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1884      +/-   ##
===========================================
+ Coverage    77.46%   77.96%   +0.50%     
===========================================
  Files          455      459       +4     
  Lines        17275    17688     +413     
  Branches       229      229              
===========================================
+ Hits         13382    13791     +409     
- Misses        3891     3895       +4     
  Partials         2        2              
Flag Coverage Δ
javascript 69.72% <100.00%> (+1.10%) ⬆️
pull_request 77.96% <99.49%> (+0.50%) ⬆️
push 77.96% <99.49%> (+0.50%) ⬆️
ruby 91.11% <93.25%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@StephenHulme StephenHulme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, no red flags, and appreciate the comments 👍

Copy link
Contributor

@harrietc52 harrietc52 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again minor comments :) can all be ignored. It hasn't been my more thorough code review but a scan over everything looks good and a big step forward. Thanks

end
end
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear 👍

end
end

def tubes_from_transfer
@transfer
create_transfer!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, how come you call the method here instead of using @create_transfer which I think should already exist and is not nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@create_transfer is the memoized backing store for the method. When you implement getters, you should use them at all times if possible. Not doing so can cause hard to debug issues where the getter is supposed to be managing access to the backing store. The only reason the other mention in this file is not using the method is that you cannot check for a nil value if it is always populated by the getter method.

I don't think we really need to check for a nil value, but I didn't want to get too deep into the weeds and cause a bug myself. The first time you try to get the transfer via the method, it would be called anyway, so why would you need to check if it's been called? I'm not sure.

# TODO: {Y24-190} Work out a way to call the `create!` method on TagLayoutTemplate model in Sequencescape
# using the V2 API. I think either we need to misuse the PATCH method with some kind of
# attributes telling Sequencescape to run the `create!` method, or we need to create a new
# endpoint associated with a TagLayoutTemplate that will run the `create!` method.
api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment just to make it super clear that api here is still currently using the SS V1 API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api is always SS V1 throughout Limber. We never access the V2 api via a variable called api.

@@ -80,6 +80,10 @@
outer_requests: quad_a_requests
)
end
let(:child_plate_a_create_args) do
{ user_id: user.id, asset_id: child_plate_a.id, metadata: { stock_barcode: "* #{child_plate_a.barcode.machine}" } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the * for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. It gets appended in the code so I have to append it in the test as well.

@@ -304,7 +305,8 @@
'custom_metadatum_collection-uuid',
body: json(:v1_custom_metadatum_collection, uuid: 'custom_metadatum_collection-uuid')
)
stub_api_get('user-uuid', body: user)
stub_api_get('user-uuid', body: v1_user)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if there is a reason the V1 User endpoint still needs to be used in this Class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, no. Removing the line does make the test fail though because the endpoint does get queried:

WebMock::NetConnectNotAllowedError:
       Real HTTP connections are disabled. Unregistered request: GET http://example.com:3000/user-uuid

     # ./app/models/labware_metadata.rb:21:in `update!'
     # ./app/models/labware_creators/quadrant_stamp_base.rb:39:in `block in create_labware!'
     # ./app/models/labware_creators/multi_stamp.rb:40:in `create_labware!'
     # ./app/models/labware_creators/quadrant_stamp_base.rb:38:in `create_labware!'
     # ./app/models/labware_creators/base.rb:56:in `save'
     # ./app/models/labware_creators/base.rb:52:in `save!'
     # ./spec/models/labware_creators/quadrant_stamp_primer_panel_spec.rb:328:in `block (4 levels) in <top (required)>'

# 'Sequencescape::Api::V2::' and returns the given value or else true.
receiving_class = "Sequencescape::Api::V2::#{klass}".constantize
return_value ||= true
allow(receiving_class).to receive(:create!).and_return(return_value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to intercept any create (or save above) without the bang too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did intercept create without the! and it never gets called in our code so I stopped doing it. I suspect I'll find some case soon that needs it, but I didn't see the point in stubbing something we're not calling. I will be easy to add if it's needed at the time. I have this file open as a permanent fixture during the Limber migration.

@@ -4,61 +4,38 @@
require './app/controllers/robots_controller'

RSpec.describe RobotsController, type: :controller, robots: true do
has_a_working_api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this referring to the V1 api? Is it worth adding a comment saying this can be removed once the update to V2 api is complete (if that is the plan?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does some very dodgy stuff to make V1 APIs be stubbed all over the place. Removal is the plan. This is literally everywhere in the unit tests. It's part of my overall plan to clean up all traces of V1, but there's not much point in adding comments as I'm aware and will just be removing the comments later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I've also experimented with removing them when I think the API is no longer needed in some tests and it always highlights how much more v1 is still to be removed because the tests fail)

@sdjmchattie
Copy link
Contributor Author

Again minor comments :) can all be ignored. It hasn't been my more thorough code review but a scan over everything looks good and a big step forward. Thanks

I applaud your determination to get through these pull requests! 122 changes files and a diff of over 4,000 lines is enough to put most off. Much appreciated.

# Conflicts:
#	app/frontend/javascript/shared/resources.js
#	app/sequencescape/sequencescape/api/v2/tube.rb
"options": {
}
},
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 12 locations. Consider refactoring.

"options": {
}
},
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

"options": {
}
},
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

"options": {
}
},
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

# Conflicts:
#	spec/models/labware_creators/plate_split_to_tube_racks_spec.rb
Copy link

codeclimate bot commented Sep 17, 2024

Code Climate has analyzed commit c841bbb and detected 22 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 21

The test coverage on the diff in this pull request is 93.2% (50% is the threshold).

This pull request will bring the total coverage in the repository to 91.1% (0.0% change).

View more on Code Climate.

@sdjmchattie sdjmchattie merged commit 197bcc7 into develop Sep 19, 2024
14 checks passed
@sdjmchattie sdjmchattie deleted the develop-Y24-190 branch September 19, 2024 09:57
@sdjmchattie sdjmchattie restored the develop-Y24-190 branch September 19, 2024 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants