From e513215f14a128dc0e399a4faf58fafe366bb4be Mon Sep 17 00:00:00 2001 From: aidewoode Date: Mon, 18 Mar 2024 16:01:05 +0800 Subject: [PATCH] Return full song data in response of remove song through current playlist API --- .../v1/current_playlist/songs/destroy.json.jbuilder | 1 + .../api/v1/current_playlist/songs_controller_test.rb | 12 ++++++++++-- .../v1/favorite_playlist/songs_controller_test.rb | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 app/views/api/v1/current_playlist/songs/destroy.json.jbuilder diff --git a/app/views/api/v1/current_playlist/songs/destroy.json.jbuilder b/app/views/api/v1/current_playlist/songs/destroy.json.jbuilder new file mode 100644 index 00000000..1beb0eee --- /dev/null +++ b/app/views/api/v1/current_playlist/songs/destroy.json.jbuilder @@ -0,0 +1 @@ +json.partial! "api/v1/songs/song", song: @song diff --git a/test/controllers/api/v1/current_playlist/songs_controller_test.rb b/test/controllers/api/v1/current_playlist/songs_controller_test.rb index 2148bb64..b8d8308a 100644 --- a/test/controllers/api/v1/current_playlist/songs_controller_test.rb +++ b/test/controllers/api/v1/current_playlist/songs_controller_test.rb @@ -17,10 +17,18 @@ class Api::V1::CurrentPlaylist::SongsControllerTest < ActionDispatch::Integratio end test "should remove songs from playlist" do - delete api_v1_current_playlist_song_url(id: 1), headers: api_token_header(@user) + delete api_v1_current_playlist_song_url(id: 1), as: :json, headers: api_token_header(@user) + response = @response.parsed_body + + assert_response :success + assert_equal 1, response["id"] assert_equal [2, 3], @playlist.reload.song_ids - delete api_v1_current_playlist_song_url(id: 3), headers: api_token_header(@user) + delete api_v1_current_playlist_song_url(id: 3), as: :json, headers: api_token_header(@user) + response = @response.parsed_body + + assert_response :success + assert_equal 3, response["id"] assert_equal [2], @playlist.reload.song_ids end diff --git a/test/controllers/api/v1/favorite_playlist/songs_controller_test.rb b/test/controllers/api/v1/favorite_playlist/songs_controller_test.rb index 772e2642..82349e84 100644 --- a/test/controllers/api/v1/favorite_playlist/songs_controller_test.rb +++ b/test/controllers/api/v1/favorite_playlist/songs_controller_test.rb @@ -31,6 +31,7 @@ class Api::V1::FavoritePlaylist::SongsControllerTest < ActionDispatch::Integrati assert_response :success assert_equal 2, response["id"] + assert_not response["is_favorited"] assert_equal [], @playlist.reload.song_ids end