From d0d20ed292e9789c42f8fcc01ba325f855c7716c Mon Sep 17 00:00:00 2001 From: Malaber Date: Mon, 27 Apr 2026 19:58:06 +0200 Subject: [PATCH] Fix team action list not found responses --- app/controllers/application_controller.rb | 1 + spec/e2e/http/tournament_sync_test_spec.rb | 3 ++ .../requests/team_action_list_updates_spec.rb | 54 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 spec/requests/team_action_list_updates_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b1bddc6..158102a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/spec/e2e/http/tournament_sync_test_spec.rb b/spec/e2e/http/tournament_sync_test_spec.rb index 1d82f59..08cb789 100644 --- a/spec/e2e/http/tournament_sync_test_spec.rb +++ b/spec/e2e/http/tournament_sync_test_spec.rb @@ -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 diff --git a/spec/requests/team_action_list_updates_spec.rb b/spec/requests/team_action_list_updates_spec.rb new file mode 100644 index 0000000..3eae07d --- /dev/null +++ b/spec/requests/team_action_list_updates_spec.rb @@ -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