Merge branch 'codex/tur-98-team-action-lists-404' into 'master'

TUR-98: Return 404 for missing team action resources

See merge request turniere/turniere-backend!65
This commit is contained in:
Daniel Schädler 2026-04-27 21:10:02 +00:00
commit 49d9a77c90
3 changed files with 58 additions and 0 deletions

View File

@ -8,6 +8,7 @@ class ApplicationController < ActionController::API
rescue_from ActionController::ParameterMissing do |e| rescue_from ActionController::ParameterMissing do |e|
render json: { error: e.message }, status: :bad_request render json: { error: e.message }, status: :bad_request
end end
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_error
protected protected

View File

@ -103,18 +103,21 @@ RSpec.describe 'Tournament sync test HTTP E2E' do
missing_item_update = client.patch('/team_action_items/999999999', body: { completed: true }) missing_item_update = client.patch('/team_action_items/999999999', body: { completed: true })
expect(missing_item_update[:status]).to eq(404) 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( missing_list_update = client.patch(
"/tournaments/#{leader.fetch(:id)}/team_action_lists/unknown_key/teams/#{first_item.dig(:team, :id)}", "/tournaments/#{leader.fetch(:id)}/team_action_lists/unknown_key/teams/#{first_item.dig(:team, :id)}",
body: { completed: true } body: { completed: true }
) )
expect(missing_list_update[:status]).to eq(404) 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( missing_team_update = client.patch(
"/tournaments/#{leader.fetch(:id)}/team_action_lists/#{playoff_token_list_key}/teams/999999999", "/tournaments/#{leader.fetch(:id)}/team_action_lists/#{playoff_token_list_key}/teams/999999999",
body: { completed: true } body: { completed: true }
) )
expect(missing_team_update[:status]).to eq(404) expect(missing_team_update[:status]).to eq(404)
expect(missing_team_update.dig(:json, :error)).to include("Couldn't find TeamActionItem")
end end
def login_client def login_client

View File

@ -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