diff --git a/Backend.Tests.Spotify/SpotifyOperationsTests.cs b/Backend.Tests.Spotify/SpotifyOperationsTests.cs index 78d4416..e59e84a 100644 --- a/Backend.Tests.Spotify/SpotifyOperationsTests.cs +++ b/Backend.Tests.Spotify/SpotifyOperationsTests.cs @@ -14,6 +14,7 @@ public class SpotifyOperationsTests : BaseTests public override void SetUp() { base.SetUp(); + Assert.IsNotNull(ConnectionManager.Instance.GetSavedToken()); ConnectionManager.Instance.TryInitFromSavedToken().Wait(); } diff --git a/Backend.Tests/SpotifyOperationsMockTests.cs b/Backend.Tests/SpotifyOperationsMockTests.cs index ce4a9c2..d0869b0 100644 --- a/Backend.Tests/SpotifyOperationsMockTests.cs +++ b/Backend.Tests/SpotifyOperationsMockTests.cs @@ -11,6 +11,12 @@ namespace Backend.Tests { public class SpotifyOperationsMockTests : BaseTests { + [SetUp] + public override void SetUp() + { + REQUIRES_DB = true; + base.SetUp(); + } [Test] public async Task GetPlaylistItems() { diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterAcousticnessNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterAcousticnessNode.cs index 380f3e3..1f1f067 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterAcousticnessNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterAcousticnessNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterAcousticnessNode : FilterRangeNode { - protected override int? GetValue(Track t) => t.AudioFeatures.AcousticnessPercent; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => t.AudioFeatures?.AcousticnessPercent; public override bool RequiresAudioFeatures => true; } } diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterDanceabilityNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterDanceabilityNode.cs index 67d97d5..2834540 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterDanceabilityNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterDanceabilityNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterDanceabilityNode : FilterRangeNode { - protected override int? GetValue(Track t) => t.AudioFeatures.DanceabilityPercent; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => t.AudioFeatures?.DanceabilityPercent; public override bool RequiresAudioFeatures => true; } } diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterEnergyNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterEnergyNode.cs index 76ef2da..9a6ee9e 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterEnergyNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterEnergyNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterEnergyNode : FilterRangeNode { - protected override int? GetValue(Track t) => t.AudioFeatures.EnergyPercent; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => t.AudioFeatures?.EnergyPercent; public override bool RequiresAudioFeatures => true; } } diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterInstrumentalnessNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterInstrumentalnessNode.cs index 7072718..0d16603 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterInstrumentalnessNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterInstrumentalnessNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterInstrumentalnessNode : FilterRangeNode { - protected override int? GetValue(Track t) => t.AudioFeatures.InstrumentalnessPercent; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => t.AudioFeatures?.InstrumentalnessPercent; public override bool RequiresAudioFeatures => true; } } diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterLivenessNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterLivenessNode.cs index 45e8296..2f20920 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterLivenessNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterLivenessNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterLivenessNode : FilterRangeNode { - protected override int? GetValue(Track t) => t.AudioFeatures.LivenessPercent; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => t.AudioFeatures?.LivenessPercent; public override bool RequiresAudioFeatures => true; } } diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterLoudnessNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterLoudnessNode.cs index e0097e4..590cd8a 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterLoudnessNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterLoudnessNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterLoudnessNode : FilterRangeNode { - protected override int? GetValue(Track t) => (int)t.AudioFeatures.Loudness; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => (int)t.AudioFeatures?.Loudness; public override bool RequiresAudioFeatures => true; } } diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterSpeechinessNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterSpeechinessNode.cs index c3535b3..833b77e 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterSpeechinessNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterSpeechinessNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterSpeechinessNode : FilterRangeNode { - protected override int? GetValue(Track t) => t.AudioFeatures.SpeechinessPercent; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => t.AudioFeatures?.SpeechinessPercent; public override bool RequiresAudioFeatures => true; } } diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterTempoNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterTempoNode.cs index 9b392cf..7888255 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterTempoNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterTempoNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterTempoNode : FilterRangeNode { - protected override int? GetValue(Track t) => (int)t.AudioFeatures.Tempo; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => (int)t.AudioFeatures?.Tempo; public override bool RequiresAudioFeatures => true; } } diff --git a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterValenceNode.cs b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterValenceNode.cs index d9fd7f4..95830de 100644 --- a/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterValenceNode.cs +++ b/Backend/Entities/GraphNodes/AudioFeaturesFilters/FilterValenceNode.cs @@ -8,7 +8,8 @@ namespace Backend.Entities.GraphNodes.AudioFeaturesFilters { public class FilterValenceNode : FilterRangeNode { - protected override int? GetValue(Track t) => t.AudioFeatures.ValencePercent; + // if db is pre-AudioFeatures even including AudioFeatures results in AudioFeature being null + protected override int? GetValue(Track t) => t.AudioFeatures?.ValencePercent; public override bool RequiresAudioFeatures => true; } } diff --git a/Tests.Util/SpotifyClientMock.cs b/Tests.Util/SpotifyClientMock.cs index 46319b0..6e2ff7a 100644 --- a/Tests.Util/SpotifyClientMock.cs +++ b/Tests.Util/SpotifyClientMock.cs @@ -331,17 +331,65 @@ public ISpotifyClient SetUp( trackMock.Setup(track => track.Get(It.IsAny(), It.IsAny())) .Returns((string trackId, TrackRequest req) => Task.FromResult(Tracks.FirstOrDefault(t => t.Id == trackId))); + trackMock.Setup(track => track.GetSeveralAudioFeatures(It.IsAny())) + .Returns((TracksAudioFeaturesRequest req) => + { + var response = new TracksAudioFeaturesResponse + { + // TODO this is not tested yet and is only here to avoid SyncLibrary failing + AudioFeatures = req.Ids.Select(id => new TrackAudioFeatures + { + Id = id, + Acousticness = 0.5f, + AnalysisUrl = "http://some.url/", + Danceability = 0.5f, + DurationMs = 123, + Energy = 0.5f, + Instrumentalness = 0.5f, + Key = 3, + Liveness = 0.5f, + Loudness = 0.5f, + Mode = 0, + Speechiness = 0.5f, + Tempo = 123, + TimeSignature = 4, + TrackHref = "http://some.href/", + Type = "SomeType", + Uri = "http://some.uri", + Valence = 0.5f, + }).ToList(), + }; + return Task.FromResult(response); + }); var userMock = new Mock(); userMock.Setup(user => user.Current()) .Returns(() => Task.FromResult(User)); + // TODO this was not tested yet + var artistMock = new Mock(); + artistMock.Setup(artist => artist.GetSeveral(It.IsAny())) + .Returns((ArtistsRequest req) => + { + var response = new ArtistsResponse + { + Artists = req.Ids.Select(id => new FullArtist + { + Id = id, // TODO this is technically not needed (only genres are needed) + Genres = new List { "genre1", "genre2" }, + Name = $"{id}.Name", // TODO this is technically not needed (only genres are needed) + }).ToList(), + }; + return Task.FromResult(response); + }); + mock.SetupGet(client => client.Library).Returns(libraryMock.Object); mock.SetupGet(client => client.Playlists).Returns(playlistsMock.Object); mock.SetupGet(client => client.Follow).Returns(followMock.Object); mock.SetupGet(client => client.Albums).Returns(albumMock.Object); mock.SetupGet(client => client.Tracks).Returns(trackMock.Object); mock.SetupGet(client => client.UserProfile).Returns(userMock.Object); + mock.SetupGet(client => client.Artists).Returns(artistMock.Object); SpotifyClient = mock.Object;