mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11: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
+5
-30
@@ -26,7 +26,6 @@ using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -54,7 +53,6 @@ public class UpdateTrackCommandHandlerTests
|
||||
private readonly IAuthorizationService _mockAuthorizationService;
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly IValidator<UpdateTrackCommand> _mockValidator;
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly UpdateTrackCommandHandler _sut;
|
||||
private readonly Guid _userId;
|
||||
private readonly UpdateTrackCommandFixture _updateTrackCommandFixture = new();
|
||||
@@ -86,16 +84,14 @@ public class UpdateTrackCommandHandlerTests
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockValidator = Substitute.For<IValidator<UpdateTrackCommand>>();
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_userId = Guid.NewGuid();
|
||||
|
||||
// Default stubs: the current user is authenticated, the library ownership policy allows access, the validator passes,
|
||||
// the track path is within the library content locations, the artist is updated and the library and contributors exist.
|
||||
// the artist is updated and the library and contributors exist.
|
||||
_mockCurrentUserService.UserId.Returns(_userId);
|
||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockValidator.Validate(Arg.Any<UpdateTrackCommand>()).Returns([]);
|
||||
_mockPathService.IsPathWithin(Arg.Any<string>(), Arg.Any<string>()).Returns(true);
|
||||
_mockArtistRepository.UpdateAsync(Arg.Any<ArtistEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<CancellationToken>())
|
||||
@@ -109,7 +105,7 @@ public class UpdateTrackCommandHandlerTests
|
||||
return Result.From<IReadOnlyList<MediaContributorEntity>>([.. contributorIds.Select(contributorId => _mediaContributorEntityFixture.Create(id: contributorId, displayName: contributorId.ToString()))]);
|
||||
});
|
||||
|
||||
_sut = new UpdateTrackCommandHandler(_mockUnitOfWork, _mockAuthorizationService, _mockCurrentUserService, _mockValidator, _mockPathService);
|
||||
_sut = new UpdateTrackCommandHandler(_mockUnitOfWork, _mockAuthorizationService, _mockCurrentUserService, _mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -118,6 +114,7 @@ public class UpdateTrackCommandHandlerTests
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
(ArtistEntity existingArtist, Guid albumId, Guid trackId) = CreateArtistWithTrack(libraryId);
|
||||
string originalPath = existingArtist.Albums.SelectMany(album => album.Tracks).First(track => track.Id == trackId).Path;
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: existingArtist.Id.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString());
|
||||
ArtistEntity? updatedArtist = null;
|
||||
TrackEntity? updatedTrack = null;
|
||||
@@ -139,7 +136,8 @@ public class UpdateTrackCommandHandlerTests
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(trackId, result.Value.Id);
|
||||
Assert.Equal(command.Path, result.Value.Path);
|
||||
// The file system path is preserved by the update, it is set only when the track is created.
|
||||
Assert.Equal(originalPath, result.Value.Path);
|
||||
Assert.Equal(command.Metadata!.Title, result.Value.Metadata!.Title);
|
||||
Assert.Equal(command.Contributors!.Count, result.Value.Contributors!.Count);
|
||||
await _mockArtistRepository.Received(1).UpdateAsync(Arg.Any<ArtistEntity>(), Arg.Any<CancellationToken>());
|
||||
@@ -338,29 +336,6 @@ public class UpdateTrackCommandHandlerTests
|
||||
await _mockArtistRepository.DidNotReceive().UpdateAsync(Arg.Any<ArtistEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathIsNotWithinLibraryContentLocations_ShouldReturnPathError()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
(ArtistEntity existingArtist, Guid albumId, Guid trackId) = CreateArtistWithTrack(libraryId);
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: existingArtist.Id.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString());
|
||||
_mockArtistRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ArtistEntity?>(existingArtist));
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_ => Result.From<LibraryEntity?>(_libraryEntityFixture.Create(contentLocations: ["/music/queen"])));
|
||||
_mockPathService.IsPathWithin(Arg.Any<string>(), Arg.Any<string>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<TrackResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.TrackPathMustBeWithinLibraryContentLocations, result.FirstError);
|
||||
_mockPathService.Received(1).IsPathWithin(command.Path!, Arg.Any<string>());
|
||||
await _mockArtistRepository.DidNotReceive().UpdateAsync(Arg.Any<ArtistEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenNoContributorsAreReferenced_ShouldNotQueryTheContributorRepository()
|
||||
{
|
||||
|
||||
-65
@@ -353,71 +353,6 @@ public class UpdateTrackCommandValidatorTests
|
||||
result.ShouldNotHaveValidationError(Errors.Music.TrackIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(includePath: false);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.Music.TrackPathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(path: string.Empty);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.Music.TrackPathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(path: " ");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.Music.TrackPathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathExceeds2048Characters_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(path: new Faker().Random.String2(2049));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.Music.TrackPathMustBeMaximum2048CharactersLong);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIs2048Characters_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(path: new Faker().Random.String2(2048));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.Music.TrackPathMustBeMaximum2048CharactersLong);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenMetadataIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user