From 699e467ad681b6ff50b2c2b9a272d10dd7feb4c9 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 13 Feb 2025 22:27:20 -0800 Subject: [PATCH] +tests/-debug logs --- spec/requests/parties_controller_spec.rb | 32 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/spec/requests/parties_controller_spec.rb b/spec/requests/parties_controller_spec.rb index 9df3b31..c9c23f2 100644 --- a/spec/requests/parties_controller_spec.rb +++ b/spec/requests/parties_controller_spec.rb @@ -107,6 +107,31 @@ RSpec.describe 'Parties API', type: :request do expect(json['results']).to be_an(Array) expect(json['meta']).to have_key('count') end + + before do + # For index, assume the controller builds the query with defaults turned on. + # Create one party that meets the default thresholds and one that does not. + # Defaults: weapons_count >= 5, characters_count >= 3, summons_count >= 2. + @good_party = create(:party, user: user, + weapons_count: 5, + characters_count: 4, + summons_count: 2, + visibility: 1) + @bad_party = create(:party, user: user, + weapons_count: 2, # below default threshold + characters_count: 2, + summons_count: 1, + visibility: 1) + end + + it 'returns only parties meeting the default filters' do + get '/api/v1/parties', headers: headers + expect(response).to have_http_status(:ok) + json = JSON.parse(response.body) + party_ids = json['results'].map { |p| p['id'] } + expect(party_ids).to include(@good_party.id) + expect(party_ids).not_to include(@bad_party.id) + end end describe 'GET /api/v1/parties/favorites' do @@ -123,19 +148,12 @@ RSpec.describe 'Parties API', type: :request do create_list(:grid_summon, 2, party: party) party.reload # Reload to update counter caches. - ap "DEBUG: Party counts - characters: #{party.characters_count}, weapons: #{party.weapons_count}, summons: #{party.summons_count}" - create(:favorite, user: user, party: party) end before { create(:favorite, user: user, party: party) } it 'lists parties favorited by the current user' do - # Debug: print IDs returned by the join query (this code can be removed later) - favorite_ids = Party.joins(:favorites).where(favorites: { user_id: user.id }).distinct.pluck(:id) - ap "DEBUG: Created party id: #{party.id}" - ap "DEBUG: Favorite party ids: #{favorite_ids.inspect}" - get '/api/v1/parties/favorites', headers: headers expect(response).to have_http_status(:ok) json = JSON.parse(response.body)