-
Notifications
You must be signed in to change notification settings - Fork 33
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
Conversation
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
…creators-in-api-v2
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
When changing to that driver, the downloads fail to be found
…-state-change Y24-190-3 Support Limber with API v2 StateChange
Cucumber tests will not pass because of ongoing issues with GitHub action runners that are now using the new build image. |
Codecov ReportAttention: Patch coverage is
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. |
|
||
# @!method uuid | ||
# A filter to return only users with the given UUID. | ||
filter :uuid, apply: lambda { |records, value, _options| records.with_uuid(*value) } |
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.
Might this Resource want the creatable_fields
to not include uuid
too, if it is created by the system on creation?
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.
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.
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.
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 👍
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.
Minor comments, feel free to ignore. Nice work, as always! 👍
end | ||
|
||
it 'disallows updating of read only fields', :aggregate_failures do | ||
expect(resource).not_to have_updatable_field :uuid |
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.
To not have updatable field id
too maybe?
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.
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 |
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.
Quite like the tests of .not_to have updatable_field
if you wanted to add any here aswell
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.
Same as above 😄
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.
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 |
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.
I was a bit confused as to what all these controller types are. Different types of transfer controllers presumably.
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.
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.
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.
That's useful info, could you add comments to that affect? Just above this BetweenPlateAndTubesController to say 'the following controllers are ...' etc.
spec/factories/transfers.rb
Outdated
|
||
factory(:pooling_transfer_template) do | ||
transfer_class_name { 'Transfer::BetweenPlatesBySubmission' } | ||
transfers { nil } |
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.
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.
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.
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 |
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.
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, {}) } |
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.
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?
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.
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.
# Conflicts: # features/support/capybara.rb
Milestone 1 for sanger/limber#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