Skip to content

Commit

Permalink
update test after adding uuid to resource
Browse files Browse the repository at this point in the history
  • Loading branch information
KatyTaylor committed Jul 26, 2024
1 parent 9992523 commit 33dfc92
Showing 1 changed file with 45 additions and 0 deletions.
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 'returns 400, because uuid is read-only' do
api_patch "#{base_endpoint}/#{resource_model.id}", payload
expect(response).to have_http_status(400)

Check failure on line 130 in spec/requests/api/v2/tube_purposes_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/Rails/HttpStatus: Prefer `:bad_request` over `400` to describe HTTP status code. (https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus)

Check failure on line 130 in spec/requests/api/v2/tube_purposes_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/Rails/HttpStatus: Prefer `:bad_request` over `400` to describe HTTP status code. (https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus)
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 'returns 400, because uuid is read-only' do
api_post base_endpoint, payload
expect(response).to have_http_status(400)

Check failure on line 196 in spec/requests/api/v2/tube_purposes_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/Rails/HttpStatus: Prefer `:bad_request` over `400` to describe HTTP status code. (https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus)

Check failure on line 196 in spec/requests/api/v2/tube_purposes_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/Rails/HttpStatus: Prefer `:bad_request` over `400` to describe HTTP status code. (https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus)
end
end
end
end

0 comments on commit 33dfc92

Please sign in to comment.