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 #4315

Merged
merged 97 commits into from
Sep 5, 2024
Merged

Conversation

sdjmchattie
Copy link
Contributor

@sdjmchattie sdjmchattie commented Sep 2, 2024

Milestone 1 for sanger/limber#1772

Changes proposed in this pull request

  • Add new/updated API v2 endpoints for:
    • BarcodePrinter
    • CustomMetadatumCollection
    • StateChange
    • TagLayoutTemplate
    • Transfer
    • TransferTemplate
  • Minor tweaks to development tool config such as pry.
  • Updated documentation stubs for API resources.

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

They were failing when they found Concerns and SharedBehaviour sub modules which did not contain JSONAPI::Resource implementations.
Presumably for efficiency, which we shouldn't be concerned about here, but Rubocop insists!
…o-v2-api

Y24-190-2: Add barcode printers to v2 API
The context is setting up a CustomMetadatumCollection, but we don't need one to be able to #post.
…-creators-in-api-v2

Y24-190-3: Support Limber TagLayoutTemplate in API v2
These contain TODOs for things which are going to require knowledge of the Sequencescape models.
…metadata-in-api-v2

# Conflicts:
#	spec/requests/api/v2/custom_metadatum_collections_spec.rb
@sdjmchattie
Copy link
Contributor Author

Cucumber tests will not pass because of ongoing issues with GitHub action runners that are now using the new build image.

Copy link

codecov bot commented Sep 2, 2024

Codecov Report

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

Project coverage is 87.51%. Comparing base (862edf4) to head (13fd8fc).
Report is 116 commits behind head on develop.

Files with missing lines Patch % Lines
lib/tasks/devour.rake 0.00% 5 Missing ⚠️
...pp/resources/api/v2/transfers/transfer_resource.rb 98.48% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4315      +/-   ##
===========================================
+ Coverage    87.48%   87.51%   +0.02%     
===========================================
  Files         1376     1380       +4     
  Lines        29700    29824     +124     
===========================================
+ Hits         25984    26101     +117     
- Misses        3716     3723       +7     

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


# @!method uuid
# A filter to return only users with the given UUID.
filter :uuid, apply: lambda { |records, value, _options| records.with_uuid(*value) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Might this Resource want the creatable_fields to not include uuid too, if it is created by the system on creation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bearing in mind that I didn't actually create this endpoint, I only added documentation to it and added the UUID filter.

I have been preferring to use creatable_fields in more recent resources as it gives nicer error messages than using readonly: true on the attribute itself. You get an error with a description that you cannot include the attribute instead of getting an error 500 from the server when you try to set an attribute that it read only. I could go through and update all the existing endpoints, but it will mean more messing around with tests so I've avoided doing it for existing resources.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, no problem. I thought too it looks much nicer, didn’t know the details but that is definitely better handling. Each resource can be updated as and when they are touched 👍

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.

Minor comments, feel free to ignore. Nice work, as always! 👍

spec/requests/api/v2/transfers/transfers_spec.rb Outdated Show resolved Hide resolved
end

it 'disallows updating of read only fields', :aggregate_failures do
expect(resource).not_to have_updatable_field :uuid
Copy link
Contributor

Choose a reason for hiding this comment

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

To not have updatable field id too maybe?

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 stopped adding :id to these simply because I could also check that :banana is not an updatable_field. id doesn't form part of the resource and so testing for its lack of existence didn't feel like it was adding value to these tests. These tests are quite poor anyway. They only test the properties of the attribute entries like readonly. They don't confirm whether the resource is immutable and they don't know how to parse the things like fetchable_fields and creatable_fields methods that are part of the library we're using. The best tests are in the requests spec folder.

expect(resource).to have_updatable_field :destination_uuid
expect(resource).to have_updatable_field :user_uuid
expect(resource).to have_updatable_field :transfers
expect(resource).to have_updatable_field :transfer_template_uuid
Copy link
Contributor

Choose a reason for hiding this comment

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

Quite like the tests of .not_to have updatable_field if you wanted to add any here aswell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above 😄

Copy link
Member

@andrewsparkes andrewsparkes 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 I think, well done. I went a bit blind by the end. A few minor comments only.

end
end

class BetweenPlateAndTubesController < JSONAPI::ResourceController
Copy link
Member

Choose a reason for hiding this comment

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

I was a bit confused as to what all these controller types are. Different types of transfer controllers presumably.

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, this is me dealing with polymorphism. You might want to only GET the BetweenPlates transfers and in order to have a route in the routes file, you must have a corresponding controller. Although they're all implemented in the base class, this gives you methods that handle creating a resource, patching a resource, etc.

Copy link
Member

Choose a reason for hiding this comment

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

That's useful info, could you add comments to that affect? Just above this BetweenPlateAndTubesController to say 'the following controllers are ...' etc.


factory(:pooling_transfer_template) do
transfer_class_name { 'Transfer::BetweenPlatesBySubmission' }
transfers { nil }
Copy link
Member

Choose a reason for hiding this comment

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

Are these transfers nil because that is correct or because you don't know what they should be? Some comments and or a todo in either case would help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes fair enough. I've added a comment. Basically some transfer types do not have the transfers in the template. These in particular expect the transfers to be passed in the creation request as they are defined by the user in the Limber UI I believe. I only have a vague understanding of how it all works. The production database shows these as nil in the templates.

@@ -8,105 +8,282 @@

it_behaves_like 'ApiKeyAuthenticatable'

context 'with multiple custom_metadatum_collections' do
context 'with multiple collection' do
Copy link
Member

Choose a reason for hiding this comment

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

collections

@@ -4,17 +4,24 @@
require './app/resources/api/v2/user_resource'

RSpec.describe Api::V2::UserResource, type: :resource do
subject { described_class.new(resource_model, {}) }
subject(:resource) { described_class.new(resource_model, {}) }
Copy link
Member

Choose a reason for hiding this comment

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

how does this work? you define the subject(:resource) but then it's not referred to in the it sections below. Does is_expected magically use the subject?

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's some sort of rspec magic. is_expected seems to know it needs to use the thing defined as the subject. I didn't know this pattern, but I saw it already existed in our tests. The only change here was to name the subject, which Rubocop insists on when you remove the exception to the rule like I did here in the rubocop config file.

@sdjmchattie sdjmchattie merged commit 7cffb98 into develop Sep 5, 2024
22 of 23 checks passed
@sdjmchattie sdjmchattie deleted the develop-Y24-190 branch September 5, 2024 09:34
@sdjmchattie sdjmchattie restored the develop-Y24-190 branch September 5, 2024 09:52
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