Propagates music artwork deletion failures and keeps stored records consistent

This commit is contained in:
BinaryAlley committed 2026-11-16 23:19:30 +02:00
1 parent ab32add68a
commit 40ee922c18
4 files changed
+61 -4

No files matched your search

@@ -170,6 +170,37 @@ public class MusicArtworkServiceTests
_mockFileProviderService.Received(1).DeleteFile(bookletFileId);
}
[Fact]
public void DeleteAlbumArtwork_WhenDeletingAFileFails_ShouldReturnTheErrorAndStopDeletingTheRemainingFiles()
{
// Arrange
Guid libraryId = Guid.NewGuid();
Guid albumId = Guid.NewGuid();
Guid artistId = Guid.NewGuid();
string libraryName = "Test Library";
string artistName = "Test Artist";
string albumTitle = "Test Album";
string artworkDirectoryPath = BuildArtworkDirectoryPath(libraryId, albumId, libraryName, artistId, artistName, albumTitle);
MockArtworkDirectoryStubs(artworkDirectoryPath);
_mockDirectoryProviderService.DirectoryExists(Arg.Any<FileSystemPathId>()).Returns(Result.From(true));
FileSystemPathId coverFileId = _fileSystemPathIdFixture.Create(Path.Combine(artworkDirectoryPath, "cover.jpg"));
FileSystemPathId bookletFileId = _fileSystemPathIdFixture.Create(Path.Combine(artworkDirectoryPath, "booklet-1.jpg"));
Error deleteError = Errors.FileSystemManagement.FileDeleteError;
_mockFileProviderService.GetFilePaths(Arg.Any<FileSystemPathId>(), true)
.Returns(Result.From<IEnumerable<FileSystemPathId>>([coverFileId, bookletFileId]));
_mockFileProviderService.DeleteFile(coverFileId).Returns(deleteError);
// Act
Result<Deleted> result = _sut.DeleteAlbumArtwork(libraryId, albumId, libraryName, artistId, artistName, albumTitle);
// Assert
Assert.True(result.IsFailure);
Assert.Equal(deleteError, result.FirstError);
_mockFileProviderService.Received(1).DeleteFile(coverFileId);
_mockFileProviderService.DidNotReceive().DeleteFile(bookletFileId);
}
[Fact]
public void DeleteAlbumArtwork_WhenCalledWithInvalidNameSegments_ShouldReturnError()
{
@@ -343,7 +343,7 @@ public class MusicMediaLibraryScanArtworkEnricherTests
}
[Fact]
public async Task EnrichAsync_WhenClearingTheStoredArtworkFilesFails_ShouldLeaveTheArtistUnresolved()
public async Task EnrichAsync_WhenClearingTheStoredArtworkFilesFails_ShouldClearTheStoredArtworkRecordsAndMarkTheArtistFailed()
{
// Arrange
ArtistEntity artist = _artistEntityFixture.Create(libraryId: _libraryId.Value);
@@ -356,8 +356,16 @@ public class MusicMediaLibraryScanArtworkEnricherTests
await _sut.EnrichAsync(_libraryId, _scanId, _userId, CancellationToken.None);
// Assert
await _mockMusicArtworkRepository.DidNotReceive().DeleteByOwnerAsync(Arg.Any<MusicArtworkOwnerType>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockMusicArtworkRepository.DidNotReceive().InsertRangeAsync(Arg.Any<IReadOnlyCollection<MusicArtworkEntity>>(), Arg.Any<CancellationToken>());
await _mockMusicArtworkRepository.Received(1).DeleteByOwnerAsync(MusicArtworkOwnerType.Artist, artist.Id, Arg.Any<CancellationToken>());
await _mockMusicArtworkRepository.Received(1).InsertRangeAsync(
Arg.Is<IReadOnlyCollection<MusicArtworkEntity>>(entities => entities.Count == 1
&& entities.First().OwnerType == MusicArtworkOwnerType.Artist
&& entities.First().OwnerId == artist.Id
&& entities.First().Status == ArtworkStatus.Failed
&& entities.First().FileName == null),
Arg.Any<CancellationToken>());
await _mockMusicArtworkService.DidNotReceive().SaveArtistArtworkAsync(
Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<ArtworkDto>(), Arg.Any<CancellationToken>());
}
[Fact]