Skip to content

Commit

Permalink
Merge pull request #4230 from sanger/config_generate_fix
Browse files Browse the repository at this point in the history
Fix: Add uuid to tube purpose resource
  • Loading branch information
KatyTaylor authored Jul 26, 2024
2 parents f3a10b1 + 85f9a04 commit fbc7ea9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/resources/api/v2/tube_purpose_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ class TubePurposeResource < BaseResource
# @!attribute [rw]
# @return [String] The target type.
attribute :target_type

# @!attribute [r]
# @return [String] The UUID of the tube purpose.
attribute :uuid

# Gets the list of fields which are creatable on a TubePurpose.
#
# @param _context [JSONAPI::Resource::Context] not used
# @return [Array<Symbol>] the list of creatable fields.
def self.creatable_fields(_context)
super - %i[uuid] # Do not allow creating with any readonly fields
end

# Gets the list of fields which are updatable on an existing TubePurpose.
#
# @param _context [JSONAPI::Resource::Context] not used
# @return [Array<Symbol>] the list of updatable fields.
def self.updatable_fields(_context)
super - %i[uuid] # Do not allow creating with any readonly fields
end
end
end
end
45 changes: 45 additions & 0 deletions spec/requests/api/v2/tube_purposes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
expect(json.dig('data', 'attributes', 'name')).to eq(resource_model.name)
expect(json.dig('data', 'attributes', 'purpose_type')).to eq(resource_model.type)
expect(json.dig('data', 'attributes', 'target_type')).to eq(resource_model.target_type)
expect(json.dig('data', 'attributes', 'uuid')).to eq(resource_model.uuid)
end
end

Expand Down Expand Up @@ -56,6 +57,7 @@
expect(json.dig('data', 'attributes', 'name')).to eq(updated_name)
expect(json.dig('data', 'attributes', 'purpose_type')).to eq(resource_model.type)
expect(json.dig('data', 'attributes', 'target_type')).to eq(resource_model.target_type)
expect(json.dig('data', 'attributes', 'uuid')).to eq(resource_model.uuid)
end
end

Expand All @@ -80,6 +82,7 @@
expect(json.dig('data', 'attributes', 'name')).to eq(resource_model.name)
expect(json.dig('data', 'attributes', 'purpose_type')).to eq(updated_purpose_type)
expect(json.dig('data', 'attributes', 'target_type')).to eq(resource_model.target_type)
expect(json.dig('data', 'attributes', 'uuid')).to eq(resource_model.uuid)
end
end

Expand All @@ -104,6 +107,27 @@
expect(json.dig('data', 'attributes', 'name')).to eq(resource_model.name)
expect(json.dig('data', 'attributes', 'purpose_type')).to eq(resource_model.type)
expect(json.dig('data', 'attributes', 'target_type')).to eq(updated_target_type)
expect(json.dig('data', 'attributes', 'uuid')).to eq(resource_model.uuid)
end
end

context 'when patching the uuid' do
let(:updated_uuid) { 'new-uuid' }
let(:payload) do
{
'data' => {
'id' => resource_model.id,
'type' => 'tube_purposes',
'attributes' => {
'uuid' => updated_uuid
}
}
}
end

it 'responds with 400 bad request, because uuid is read-only' do
api_patch "#{base_endpoint}/#{resource_model.id}", payload
expect(response).to have_http_status(:bad_request)
end
end
end
Expand Down Expand Up @@ -151,5 +175,26 @@
expect(response).to have_http_status(:unprocessable_entity)
end
end

context 'with an invalid payload (includes uuid)' do
let(:payload) do
{
'data' => {
'type' => 'tube_purposes',
'attributes' => {
'name' => 'New Name',
'purpose_type' => 'Test Purpose Type',
'target_type' => 'MultiplexedLibraryTube',
'uuid' => 'new-uuid'
}
}
}
end

it 'responds with 400 bad request, because uuid is read-only' do
api_post base_endpoint, payload
expect(response).to have_http_status(:bad_request)
end
end
end
end
2 changes: 2 additions & 0 deletions spec/resources/api/v2/tube_purpose_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
expect(resource).to have_attribute :name
expect(resource).to have_attribute :purpose_type
expect(resource).to have_attribute :target_type
expect(resource).to have_attribute :uuid
end

# Updatable fields
it 'allows updating of read-write fields', :aggregate_failures do
expect(resource).to have_updatable_field :name
expect(resource).to have_updatable_field :purpose_type
expect(resource).to have_updatable_field :target_type
expect(resource).not_to have_updatable_field :uuid
end

# Filters
Expand Down

0 comments on commit fbc7ea9

Please sign in to comment.