Fix team action list not found responses
This commit is contained in:
parent
7a97a17940
commit
d0d20ed292
|
|
@ -8,6 +8,7 @@ class ApplicationController < ActionController::API
|
|||
rescue_from ActionController::ParameterMissing do |e|
|
||||
render json: { error: e.message }, status: :bad_request
|
||||
end
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_error
|
||||
|
||||
protected
|
||||
|
||||
|
|
|
|||
|
|
@ -103,18 +103,21 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
|
|||
|
||||
missing_item_update = client.patch('/team_action_items/999999999', body: { completed: true })
|
||||
expect(missing_item_update[:status]).to eq(404)
|
||||
expect(missing_item_update.dig(:json, :error)).to include("Couldn't find TeamActionItem")
|
||||
|
||||
missing_list_update = client.patch(
|
||||
"/tournaments/#{leader.fetch(:id)}/team_action_lists/unknown_key/teams/#{first_item.dig(:team, :id)}",
|
||||
body: { completed: true }
|
||||
)
|
||||
expect(missing_list_update[:status]).to eq(404)
|
||||
expect(missing_list_update.dig(:json, :error)).to include("Couldn't find TeamActionList")
|
||||
|
||||
missing_team_update = client.patch(
|
||||
"/tournaments/#{leader.fetch(:id)}/team_action_lists/#{playoff_token_list_key}/teams/999999999",
|
||||
body: { completed: true }
|
||||
)
|
||||
expect(missing_team_update[:status]).to eq(404)
|
||||
expect(missing_team_update.dig(:json, :error)).to include("Couldn't find TeamActionItem")
|
||||
end
|
||||
|
||||
def login_client
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Team action list updates', type: :request do
|
||||
let(:team_action_item) { create(:team_action_item) }
|
||||
let(:list) { team_action_item.team_action_list }
|
||||
let(:team) { team_action_item.team }
|
||||
let(:owner_headers) { list.tournament.owner.create_new_auth_token }
|
||||
|
||||
describe 'PATCH /team_action_items/:id' do
|
||||
it 'returns not found when the item is missing' do
|
||||
patch '/team_action_items/999999999',
|
||||
params: { completed: true },
|
||||
headers: owner_headers,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(response.parsed_body.fetch('error')).to include("Couldn't find TeamActionItem")
|
||||
end
|
||||
|
||||
it 'updates an existing item' do
|
||||
patch "/team_action_items/#{team_action_item.id}",
|
||||
params: { completed: true },
|
||||
headers: owner_headers,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(team_action_item.reload.completed).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /tournaments/:tournament_id/team_action_lists/:key/teams/:team_id' do
|
||||
it 'returns not found when the list key is missing' do
|
||||
patch "/tournaments/#{list.tournament.id}/team_action_lists/unknown_key/teams/#{team.id}",
|
||||
params: { completed: true },
|
||||
headers: owner_headers,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(response.parsed_body.fetch('error')).to include("Couldn't find TeamActionList")
|
||||
end
|
||||
|
||||
it 'returns not found when the team is missing from the list context' do
|
||||
patch "/tournaments/#{list.tournament.id}/team_action_lists/#{list.key}/teams/999999999",
|
||||
params: { completed: true },
|
||||
headers: owner_headers,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(response.parsed_body.fetch('error')).to include("Couldn't find TeamActionItem")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue