Skip to content

Commit

Permalink
Merge pull request #310 from blackcandy-org/dev
Browse files Browse the repository at this point in the history
Add JSON response for API of favorite playlist song
  • Loading branch information
aidewoode committed Oct 11, 2023
2 parents f8b8173 + ddec166 commit a5dde98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.call(@song, :id, :name)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.call(@song, :id, :name)
18 changes: 15 additions & 3 deletions test/controllers/api/v1/favorite_playlist/songs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ class Api::V1::FavoritePlaylist::SongsControllerTest < ActionDispatch::Integrati
end

test "should add songs to playlist" do
post api_v1_favorite_playlist_songs_url, params: {song_id: 3}, headers: api_token_header(@user)
post api_v1_favorite_playlist_songs_url, params: {song_id: 3}, as: :json, headers: api_token_header(@user)
response = @response.parsed_body

assert_response :success
assert_equal 3, response["id"]
assert_equal [3, 1, 2], @playlist.reload.song_ids
end

test "should remove songs from playlist" do
delete api_v1_favorite_playlist_songs_url, params: {song_id: 1}, headers: api_token_header(@user)
delete api_v1_favorite_playlist_songs_url, params: {song_id: 1}, as: :json, headers: api_token_header(@user)
response = @response.parsed_body

assert_response :success
assert_equal 1, response["id"]
assert_equal [2], @playlist.reload.song_ids

delete api_v1_favorite_playlist_songs_url, params: {song_id: 2}, headers: api_token_header(@user)
delete api_v1_favorite_playlist_songs_url, params: {song_id: 2}, as: :json, headers: api_token_header(@user)
response = @response.parsed_body

assert_response :success
assert_equal 2, response["id"]
assert_equal [], @playlist.reload.song_ids
end

Expand Down

0 comments on commit a5dde98

Please sign in to comment.