Skip to content

Commit

Permalink
Merge pull request #487 from ramsayleung/ramsay/fix-tracklink-id-null
Browse files Browse the repository at this point in the history
Fix JSON deserialize error that TrackLink::id could be null
  • Loading branch information
ramsayleung authored Aug 5, 2024
2 parents eb1260c + 41c2127 commit c38948f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.14.0 (unreleased)
**Breaking changes**
- ([#487](https://github.com/ramsayleung/rspotify/pull/487)) Change the type of `TrackLink.id` from `TrackId<'static>` to `Option<TrackId<'static>>`

## 0.13.2 (2024.06.03)
- ([#480](https://github.com/ramsayleung/rspotify/pull/480)) Fix deserialize empty images from null.

Expand Down
6 changes: 5 additions & 1 deletion rspotify-model/src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::collections::HashMap;

use crate::{
custom_serde::duration_ms, PlayableId, Restriction, SimplifiedAlbum, SimplifiedArtist, TrackId,
Type,
};

/// Full track object
Expand Down Expand Up @@ -40,11 +41,14 @@ pub struct FullTrack {
}

/// Track link object
/// [track-relinking](https://developer.spotify.com/documentation/web-api/concepts/track-relinking)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct TrackLink {
pub external_urls: HashMap<String, String>,
pub href: String,
pub id: TrackId<'static>,
pub id: Option<TrackId<'static>>,
pub r#type: Type,
pub uri: String,
}

/// Intermediate full track wrapped by `Vec`
Expand Down
19 changes: 19 additions & 0 deletions tests/test_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,3 +1204,22 @@ fn test_collectionyourepisodes_type() {
let context: Context = deserialize(json);
assert_eq!(context._type, Type::Collectionyourepisodes);
}

#[test]
#[wasm_bindgen_test]
fn test_null_id_in_tracklink() {
let json = r#"
{
"external_urls": {
"spotify": "https://open.spotify.com/track/0tSkMuKKrLXEfxc58cEhFX"
},
"href": "https://api.spotify.com/v1/tracks/0tSkMuKKrLXEfxc58cEhFX",
"id": null,
"type": "track",
"uri": "spotify:track:0tSkMuKKrLXEfxc58cEhFX"
}
"#;
let linked_from: TrackLink = deserialize(json);
assert!(linked_from.id.is_none());
assert_eq!(linked_from.r#type, Type::Track);
}

0 comments on commit c38948f

Please sign in to comment.