mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +00:00
Removes track path editing from the music track update flow
Stops Track.UpdateDetails and Artist.UpdateTrackInAlbum from assigning a path, so a track path can be set only when the track is created. Removes Path from UpdateTrackRequest, UpdateTrackCommand, UpdateTrackCommandValidator and UpdateMusicTrackRequest, and removes the path containment check and IPathService dependency from UpdateTrackCommandHandler. The path stays visible in TrackResponse, MusicTrackDto and the read-only field of the track page. Updates the endpoint summary, request and API docs, and the affected tests.
This commit is contained in:
1 parent
728a879bb8
commit
1aa427b1e2
29 files changed
+47
-243
No files matched your search
+6
-52
@@ -56,7 +56,6 @@ namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.Library.AudioL
|
||||
public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>, IAsyncLifetime
|
||||
{
|
||||
private static readonly string s_contentRootPath = Path.Combine(Path.GetTempPath(), "lumina-update-track-tests");
|
||||
private static readonly string s_outsideContentRootPath = Path.Combine(Path.GetTempPath(), "lumina-update-track-outside");
|
||||
|
||||
private HttpClient _client;
|
||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||
@@ -115,10 +114,9 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
||||
string updatedPath = Path.Combine(s_contentRootPath, $"love-of-my-life-{Guid.NewGuid():N}.flac");
|
||||
string originalPath = Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac");
|
||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, originalPath);
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||
path: updatedPath,
|
||||
metadata: _musicTrackMetadataDtoFixture.Create(title: "Somebody to Love"),
|
||||
moods: [],
|
||||
isrcs: [],
|
||||
@@ -142,14 +140,15 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
Assert.NotNull(trackResponse);
|
||||
Assert.Equal(trackId, trackResponse!.Id);
|
||||
Assert.Equal(libraryId, trackResponse.LibraryId);
|
||||
Assert.Equal(updatedPath, trackResponse.Path);
|
||||
// the file system path is preserved by the update, it is set only when the track is created
|
||||
Assert.Equal(originalPath, trackResponse.Path);
|
||||
Assert.Equal("Somebody to Love", trackResponse.Metadata!.Title);
|
||||
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
TrackEntity storedTrack = dbContext.Tracks.Single(track => track.Id == trackId);
|
||||
Assert.Equal("Somebody to Love", storedTrack.Title);
|
||||
Assert.Equal(updatedPath, storedTrack.Path);
|
||||
Assert.Equal(originalPath, storedTrack.Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -160,7 +159,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
Guid libraryId = await SeedLibraryAsync(otherUserId);
|
||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||
path: Path.Combine(s_contentRootPath, "dont-stop-me-now.flac"),
|
||||
metadata: _musicTrackMetadataDtoFixture.Create(title: "Don't Stop Me Now"),
|
||||
moods: [],
|
||||
isrcs: [],
|
||||
@@ -301,22 +299,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
await AssertNotFoundAsync(response, "LibraryNotFound");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateTrack_WhenPathIsOutsideLibraryContentLocations_ShouldReturnPathError()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(path: Path.Combine(s_outsideContentRootPath, "under-pressure.flac"));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}", request);
|
||||
|
||||
// Assert
|
||||
await AssertUnprocessableEntityWithValidationErrors(response, "TrackPathMustBeWithinLibraryContentLocations");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateTrack_WhenAReferencedContributorDoesNotExist_ShouldReturnMediaContributorNotFoundProblem()
|
||||
{
|
||||
@@ -325,7 +307,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||
path: Path.Combine(s_contentRootPath, "somebody-to-love.flac"),
|
||||
contributors: [_mediaContributorReferenceDtoFixture.Create(contributorId: Guid.NewGuid(), role: MediaContributorRole.Vocals)]);
|
||||
|
||||
// Act
|
||||
@@ -350,7 +331,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
];
|
||||
await SeedContributorsAsync(duplicatedContributors);
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||
path: Path.Combine(s_contentRootPath, "another-one-bites-the-dust.flac"),
|
||||
moods: [],
|
||||
isrcs: [],
|
||||
contributors: duplicatedContributors,
|
||||
@@ -373,32 +353,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
Assert.Contains(links, link => link.Role == MediaContributorRole.Guitar);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateTrack_WhenPathIsNull_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(includePath: false);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await PutTrackAsync(request);
|
||||
|
||||
// Assert
|
||||
await AssertUnprocessableEntityWithValidationErrors(response, "TrackPathCannotBeEmpty");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateTrack_WhenPathExceeds2048Characters_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(path: new Faker().Random.String2(2049));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await PutTrackAsync(request);
|
||||
|
||||
// Assert
|
||||
await AssertUnprocessableEntityWithValidationErrors(response, "TrackPathMustBeMaximum2048CharactersLong");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateTrack_WhenMetadataIsNull_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
@@ -1004,7 +958,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = await SeedLibraryAsync(userId);
|
||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(path: Path.Combine(s_contentRootPath, "the-show-must-go-on.flac"));
|
||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create();
|
||||
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
|
||||
|
||||
// Act & Assert
|
||||
|
||||
Reference in new issue
Block a user