Skip to content

Commit

Permalink
track/trophies index returns a JSON object, not a list (#6948)
Browse files Browse the repository at this point in the history
* track/trophies index returns a JSON object, not a list

* update test

* tests comparing JSON values
  • Loading branch information
glennj authored Jun 21, 2024
1 parent f481b04 commit 71f9024
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/tracks/trophies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class API::Tracks::TrophiesController < API::BaseController
def index
track = Track.find(params[:track_slug])

render json: SerializeTrackTrophies.(track, current_user)
render json: { trophies: SerializeTrackTrophies.(track, current_user) }
end

def reveal
Expand Down
7 changes: 5 additions & 2 deletions test/controllers/api/tracks/trophies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class API::Tracks::TrophiesControllerTest < API::BaseTestCase
guard_incorrect_token! :reveal_api_track_trophy_path, args: 2, method: :patch
guard_incorrect_token! :api_track_trophies_path, args: 1, method: :get

#########
# Index #
#########
test "index with none revealed" do
track = create :track
create :trophy, valid_track_slugs: [track.slug]
Expand All @@ -13,7 +16,7 @@ class API::Tracks::TrophiesControllerTest < API::BaseTestCase
get api_track_trophies_url(track.slug), headers: @headers, as: :json

assert_response :ok
expected = SerializeTrackTrophies.(track, User.first).to_json
expected = { trophies: SerializeTrackTrophies.(track, User.first) }.to_json
assert_equal expected, response.body
end

Expand All @@ -27,7 +30,7 @@ class API::Tracks::TrophiesControllerTest < API::BaseTestCase
get api_track_trophies_url(track.slug), headers: @headers, as: :json

assert_response :ok
expected = SerializeTrackTrophies.(track, user).to_json
expected = { trophies: SerializeTrackTrophies.(track, User.first) }.to_json
assert_equal expected, response.body
end

Expand Down

0 comments on commit 71f9024

Please sign in to comment.