diff --git a/lib/src/endpoints/endpoint_base.dart b/lib/src/endpoints/endpoint_base.dart index e90329b..39865bd 100644 --- a/lib/src/endpoints/endpoint_base.dart +++ b/lib/src/endpoints/endpoint_base.dart @@ -57,6 +57,6 @@ abstract class EndpointBase { required T Function(Map) fromJson}) async { var jsonString = await _api._get(path); final tJson = jsonDecode(jsonString)[jsonKey] as Iterable; - return tJson.map((json) => fromJson(json)); + return tJson.where((e) => e != null).map((json) => fromJson(json)); } } diff --git a/test/data/v1/audio-features.json b/test/data/v1/audio-features.json new file mode 100644 index 0000000..8dbfbcb --- /dev/null +++ b/test/data/v1/audio-features.json @@ -0,0 +1,25 @@ +{ + "audio_features": [ + { + "acousticness": 0.011, + "analysis_url": "https://api.spotify.com/v1/audio-analysis/11dFghVXANMlKmJXsNCbNl", + "danceability": 0.696, + "duration_ms": 207960, + "energy": 0.905, + "id": "11dFghVXANMlKmJXsNCbNl", + "instrumentalness": 0.000905, + "key": 2, + "liveness": 0.302, + "loudness": -2.743, + "mode": 1, + "speechiness": 0.103, + "tempo": 114.944, + "time_signature": 4, + "track_href": "https://api.spotify.com/v1/tracks/11dFghVXANMlKmJXsNCbNl", + "type": "audio_features", + "uri": "spotify:track:11dFghVXANMlKmJXsNCbNl", + "valence": 0.625 + }, + null + ] +} \ No newline at end of file diff --git a/test/data/v1/audio-features/11dFghVXANMlKmJXsNCbNl.json b/test/data/v1/audio-features/11dFghVXANMlKmJXsNCbNl.json new file mode 100644 index 0000000..d78a23a --- /dev/null +++ b/test/data/v1/audio-features/11dFghVXANMlKmJXsNCbNl.json @@ -0,0 +1,20 @@ +{ + "acousticness": 0.011, + "analysis_url": "https://api.spotify.com/v1/audio-analysis/11dFghVXANMlKmJXsNCbNl", + "danceability": 0.696, + "duration_ms": 207960, + "energy": 0.905, + "id": "11dFghVXANMlKmJXsNCbNl", + "instrumentalness": 0.000905, + "key": 2, + "liveness": 0.302, + "loudness": -2.743, + "mode": 1, + "speechiness": 0.103, + "tempo": 114.944, + "time_signature": 4, + "track_href": "https://api.spotify.com/v1/tracks/11dFghVXANMlKmJXsNCbNl", + "type": "audio_features", + "uri": "spotify:track:11dFghVXANMlKmJXsNCbNl", + "valence": 0.625 + } \ No newline at end of file diff --git a/test/data/v1/audio-features/2cs7JxrZ9DxvsfoVI07ayX.json b/test/data/v1/audio-features/2cs7JxrZ9DxvsfoVI07ayX.json new file mode 100644 index 0000000..3919b22 --- /dev/null +++ b/test/data/v1/audio-features/2cs7JxrZ9DxvsfoVI07ayX.json @@ -0,0 +1,6 @@ +{ + "error": { + "status": 404, + "message": "analysis not found" + } + } \ No newline at end of file diff --git a/test/spotify_test.dart b/test/spotify_test.dart index 58f0383..77994ba 100644 --- a/test/spotify_test.dart +++ b/test/spotify_test.dart @@ -64,6 +64,22 @@ Future main() async { }); }); + group('Audio Features', () { + test('get', () async { + var audioFeatures = + await spotify.audioFeatures.get('11dFghVXANMlKmJXsNCbNl'); + + expect(audioFeatures.id, '11dFghVXANMlKmJXsNCbNl'); + }); + + test('list', () async { + var audioFeatures = await spotify.audioFeatures + .list(['11dFghVXANMlKmJXsNCbNl', '2cs7JxrZ9DxvsfoVI07ayX']); + + expect(audioFeatures.length, 1); + }); + }); + group('Audio Analysis', () { test('get', () async { var result = await spotify.audioAnalysis.get('xyz123');