mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18: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
@@ -320,7 +320,6 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"title": "Bohemian Rhapsody",
|
"title": "Bohemian Rhapsody",
|
||||||
"originalTitle": "Bohemian Rhapsody",
|
"originalTitle": "Bohemian Rhapsody",
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ Authorization: Bearer {{ACCESS_TOKEN}}
|
|||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"title": "Bohemian Rhapsody",
|
"title": "Bohemian Rhapsody",
|
||||||
"originalTitle": "Bohemian Rhapsody",
|
"originalTitle": "Bohemian Rhapsody",
|
||||||
|
|||||||
-1
@@ -158,7 +158,6 @@ public static class UpdateArtistCommandMapping
|
|||||||
Result<Updated> updateTrackResult = artist.UpdateTrackInAlbum(
|
Result<Updated> updateTrackResult = artist.UpdateTrackInAlbum(
|
||||||
existingAlbum,
|
existingAlbum,
|
||||||
existingTrack,
|
existingTrack,
|
||||||
domainTrack.Path,
|
|
||||||
domainTrack.Metadata,
|
domainTrack.Metadata,
|
||||||
domainTrack.Disambiguation,
|
domainTrack.Disambiguation,
|
||||||
domainTrack.TrackNumber,
|
domainTrack.TrackNumber,
|
||||||
|
|||||||
-1
@@ -111,7 +111,6 @@ public static class AudioMetadataDtoMapping
|
|||||||
return artist.UpdateTrackInAlbum(
|
return artist.UpdateTrackInAlbum(
|
||||||
album,
|
album,
|
||||||
track,
|
track,
|
||||||
track.Path,
|
|
||||||
metadataResult.Value,
|
metadataResult.Value,
|
||||||
disambiguation,
|
disambiguation,
|
||||||
track.TrackNumber,
|
track.TrackNumber,
|
||||||
|
|||||||
-1
@@ -85,7 +85,6 @@ public static class UpdateTrackCommandMapping
|
|||||||
Result<Updated> updateResult = artist.UpdateTrackInAlbum(
|
Result<Updated> updateResult = artist.UpdateTrackInAlbum(
|
||||||
album,
|
album,
|
||||||
track,
|
track,
|
||||||
command.Path!,
|
|
||||||
metadataResult.Value,
|
metadataResult.Value,
|
||||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||||
command.TrackNumber!.Value,
|
command.TrackNumber!.Value,
|
||||||
|
|||||||
-1
@@ -26,7 +26,6 @@ public static class UpdateTrackRequestMapping
|
|||||||
artistId,
|
artistId,
|
||||||
albumId,
|
albumId,
|
||||||
trackId,
|
trackId,
|
||||||
request.Path,
|
|
||||||
request.Metadata,
|
request.Metadata,
|
||||||
request.TrackNumber,
|
request.TrackNumber,
|
||||||
request.DiscNumber,
|
request.DiscNumber,
|
||||||
|
|||||||
-2
@@ -19,7 +19,6 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.
|
|||||||
/// <param name="ArtistId">The unique identifier of the artist this track belongs to, taken from the route.</param>
|
/// <param name="ArtistId">The unique identifier of the artist this track belongs to, taken from the route.</param>
|
||||||
/// <param name="AlbumId">The unique identifier of the album this track belongs to, taken from the route.</param>
|
/// <param name="AlbumId">The unique identifier of the album this track belongs to, taken from the route.</param>
|
||||||
/// <param name="TrackId">The unique identifier of the track, taken from the route.</param>
|
/// <param name="TrackId">The unique identifier of the track, taken from the route.</param>
|
||||||
/// <param name="Path">The file system path of the track.</param>
|
|
||||||
/// <param name="Metadata">The audio metadata of the track.</param>
|
/// <param name="Metadata">The audio metadata of the track.</param>
|
||||||
/// <param name="TrackNumber">The number of the track on its disc.</param>
|
/// <param name="TrackNumber">The number of the track on its disc.</param>
|
||||||
/// <param name="DiscNumber">The number of the disc the track belongs to, if applicable.</param>
|
/// <param name="DiscNumber">The number of the disc the track belongs to, if applicable.</param>
|
||||||
@@ -39,7 +38,6 @@ public record UpdateTrackCommand(
|
|||||||
string? ArtistId,
|
string? ArtistId,
|
||||||
string? AlbumId,
|
string? AlbumId,
|
||||||
string? TrackId,
|
string? TrackId,
|
||||||
string? Path,
|
|
||||||
MusicTrackMetadataDto? Metadata,
|
MusicTrackMetadataDto? Metadata,
|
||||||
int? TrackNumber,
|
int? TrackNumber,
|
||||||
int? DiscNumber,
|
int? DiscNumber,
|
||||||
|
|||||||
+1
-21
@@ -26,7 +26,6 @@ using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIden
|
|||||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||||
using System;
|
using System;
|
||||||
@@ -48,7 +47,6 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
|||||||
private readonly IAuthorizationService _authorizationService;
|
private readonly IAuthorizationService _authorizationService;
|
||||||
private readonly ICurrentUserService _currentUserService;
|
private readonly ICurrentUserService _currentUserService;
|
||||||
private readonly IValidator<UpdateTrackCommand> _validator;
|
private readonly IValidator<UpdateTrackCommand> _validator;
|
||||||
private readonly IPathService _pathService;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="UpdateTrackCommandHandler"/> class.
|
/// Initializes a new instance of the <see cref="UpdateTrackCommandHandler"/> class.
|
||||||
@@ -57,14 +55,12 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
|||||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||||
/// <param name="pathService">Injected service for file system path related functionality.</param>
|
public UpdateTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<UpdateTrackCommand> validator)
|
||||||
public UpdateTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<UpdateTrackCommand> validator, IPathService pathService)
|
|
||||||
{
|
{
|
||||||
_unitOfWork = unitOfWork;
|
_unitOfWork = unitOfWork;
|
||||||
_authorizationService = authorizationService;
|
_authorizationService = authorizationService;
|
||||||
_currentUserService = currentUserService;
|
_currentUserService = currentUserService;
|
||||||
_validator = validator;
|
_validator = validator;
|
||||||
_pathService = pathService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -127,11 +123,6 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
|||||||
if (getLibraryResult.Value is null)
|
if (getLibraryResult.Value is null)
|
||||||
return Errors.Library.LibraryNotFound;
|
return Errors.Library.LibraryNotFound;
|
||||||
|
|
||||||
// A track is only readable if it is stored inside one of the content locations of its library, so a client can never edit an entry
|
|
||||||
// that points the reading pipeline at an arbitrary file of the host.
|
|
||||||
if (!AreTrackPathsWithinLibraryContentLocations(getLibraryResult.Value, command))
|
|
||||||
return Errors.Music.TrackPathMustBeWithinLibraryContentLocations;
|
|
||||||
|
|
||||||
// Media contributors are referenced by Id and are never created implicitly by editing a track, so each one must already exist.
|
// Media contributors are referenced by Id and are never created implicitly by editing a track, so each one must already exist.
|
||||||
Result<IReadOnlyList<MediaContributorEntity>> getContributorsResult = await GetExistingContributorsAsync(command, cancellationToken).ConfigureAwait(false);
|
Result<IReadOnlyList<MediaContributorEntity>> getContributorsResult = await GetExistingContributorsAsync(command, cancellationToken).ConfigureAwait(false);
|
||||||
if (getContributorsResult.IsFailure)
|
if (getContributorsResult.IsFailure)
|
||||||
@@ -164,17 +155,6 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
|||||||
return getPersistedTrackResult.Value.ToResponse();
|
return getPersistedTrackResult.Value.ToResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether the track path referenced by <paramref name="command"/> is stored inside one of the content locations of <paramref name="library"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="library">The media library that owns the track.</param>
|
|
||||||
/// <param name="command">The command carrying the referenced track.</param>
|
|
||||||
/// <returns><see langword="true"/> when the referenced track path is within a content location of the library; otherwise, <see langword="false"/>.</returns>
|
|
||||||
private bool AreTrackPathsWithinLibraryContentLocations(LibraryEntity library, UpdateTrackCommand command)
|
|
||||||
{
|
|
||||||
return library.ContentLocations.Any(contentLocation => _pathService.IsPathWithin(command.Path!, contentLocation.Path));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the media contributors referenced by <paramref name="command"/>, requiring each referenced Id to already exist.
|
/// Gets the media contributors referenced by <paramref name="command"/>, requiring each referenced Id to already exist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
-6
@@ -57,12 +57,6 @@ public class UpdateTrackCommandValidator : AbstractValidator<UpdateTrackCommand>
|
|||||||
.When(command => command.TrackId is not null && command.TrackId.Length > 0)
|
.When(command => command.TrackId is not null && command.TrackId.Length > 0)
|
||||||
.WithError(Errors.Music.TrackIdCannotBeEmpty);
|
.WithError(Errors.Music.TrackIdCannotBeEmpty);
|
||||||
|
|
||||||
RuleFor(command => command.Path)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithError(Errors.Music.TrackPathCannotBeEmpty)
|
|
||||||
.MaximumLength(2048)
|
|
||||||
.WithError(Errors.Music.TrackPathMustBeMaximum2048CharactersLong);
|
|
||||||
|
|
||||||
// Validates the audio metadata of the track: title, lengths, release information, languages, genres and tags.
|
// Validates the audio metadata of the track: title, lengths, release information, languages, genres and tags.
|
||||||
RuleFor(command => command.Metadata)
|
RuleFor(command => command.Metadata)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
|
|||||||
-2
@@ -14,7 +14,6 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Track
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a request to update an existing track.
|
/// Represents a request to update an existing track.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Path">The file system path of the track. Required.</param>
|
|
||||||
/// <param name="Metadata">The audio metadata of the track. Required.</param>
|
/// <param name="Metadata">The audio metadata of the track. Required.</param>
|
||||||
/// <param name="TrackNumber">The number of the track on its disc. Required.</param>
|
/// <param name="TrackNumber">The number of the track on its disc. Required.</param>
|
||||||
/// <param name="DiscNumber">The number of the disc the track belongs to. Optional.</param>
|
/// <param name="DiscNumber">The number of the disc the track belongs to. Optional.</param>
|
||||||
@@ -30,7 +29,6 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Track
|
|||||||
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
||||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||||
public record UpdateTrackRequest(
|
public record UpdateTrackRequest(
|
||||||
string? Path,
|
|
||||||
MusicTrackMetadataDto? Metadata,
|
MusicTrackMetadataDto? Metadata,
|
||||||
int? TrackNumber,
|
int? TrackNumber,
|
||||||
int? DiscNumber,
|
int? DiscNumber,
|
||||||
|
|||||||
+2
-4
@@ -638,11 +638,11 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// A track is a child entity of the artist aggregate, not an aggregate root, so it is mutated through its owning artist,
|
/// A track is a child entity of the artist aggregate, not an aggregate root, so it is mutated through its owning artist,
|
||||||
/// which is the consistency boundary. Book is itself an aggregate root, so its update flow reconstitutes it directly
|
/// which is the consistency boundary. Book is itself an aggregate root, so its update flow reconstitutes it directly
|
||||||
/// with its own Create method instead. This difference is intentional.
|
/// with its own Create method instead. This difference is intentional. The file system path of the track is never updated
|
||||||
|
/// here: a track path is set only when the track is created by the scanner.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="album">The album the track belongs to.</param>
|
/// <param name="album">The album the track belongs to.</param>
|
||||||
/// <param name="track">The track to update.</param>
|
/// <param name="track">The track to update.</param>
|
||||||
/// <param name="path">The file system path of the track.</param>
|
|
||||||
/// <param name="metadata">The audio metadata of the track.</param>
|
/// <param name="metadata">The audio metadata of the track.</param>
|
||||||
/// <param name="disambiguation">The optional disambiguation comment of the track.</param>
|
/// <param name="disambiguation">The optional disambiguation comment of the track.</param>
|
||||||
/// <param name="trackNumber">The number of the track on its disc.</param>
|
/// <param name="trackNumber">The number of the track on its disc.</param>
|
||||||
@@ -662,7 +662,6 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
|||||||
public Result<Updated> UpdateTrackInAlbum(
|
public Result<Updated> UpdateTrackInAlbum(
|
||||||
Album album,
|
Album album,
|
||||||
Track track,
|
Track track,
|
||||||
string path,
|
|
||||||
AudioMetadata metadata,
|
AudioMetadata metadata,
|
||||||
Optional<string> disambiguation,
|
Optional<string> disambiguation,
|
||||||
int trackNumber,
|
int trackNumber,
|
||||||
@@ -686,7 +685,6 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
|||||||
return Errors.Music.TrackNotFound;
|
return Errors.Music.TrackNotFound;
|
||||||
|
|
||||||
track.UpdateDetails(
|
track.UpdateDetails(
|
||||||
path,
|
|
||||||
metadata,
|
metadata,
|
||||||
disambiguation,
|
disambiguation,
|
||||||
trackNumber,
|
trackNumber,
|
||||||
|
|||||||
+5
-4
@@ -343,9 +343,12 @@ public sealed class Track : Entity<TrackId>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the details of the track, without touching the moods, the ISRCs, the media contributors, and the ratings.
|
/// Updates the details of the track, without touching the file system path, the moods, the ISRCs, the media contributors, and the ratings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The file system path of the track.</param>
|
/// <remarks>
|
||||||
|
/// The file system path is intentionally not editable here: it is set only when the track is created by the scanner, so that a client
|
||||||
|
/// can never point an existing track at an arbitrary file of the host.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="metadata">The audio metadata of the track.</param>
|
/// <param name="metadata">The audio metadata of the track.</param>
|
||||||
/// <param name="disambiguation">The optional disambiguation comment of the track.</param>
|
/// <param name="disambiguation">The optional disambiguation comment of the track.</param>
|
||||||
/// <param name="trackNumber">The number of the track on its disc.</param>
|
/// <param name="trackNumber">The number of the track on its disc.</param>
|
||||||
@@ -359,7 +362,6 @@ public sealed class Track : Entity<TrackId>
|
|||||||
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
|
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
|
||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||||
internal Result<Updated> UpdateDetails(
|
internal Result<Updated> UpdateDetails(
|
||||||
string path,
|
|
||||||
AudioMetadata metadata,
|
AudioMetadata metadata,
|
||||||
Optional<string> disambiguation,
|
Optional<string> disambiguation,
|
||||||
int trackNumber,
|
int trackNumber,
|
||||||
@@ -372,7 +374,6 @@ public sealed class Track : Entity<TrackId>
|
|||||||
Optional<MusicBrainzId> musicBrainzRecordingId,
|
Optional<MusicBrainzId> musicBrainzRecordingId,
|
||||||
Optional<MusicBrainzId> musicBrainzTrackId)
|
Optional<MusicBrainzId> musicBrainzTrackId)
|
||||||
{
|
{
|
||||||
Path = path;
|
|
||||||
Metadata = metadata;
|
Metadata = metadata;
|
||||||
Disambiguation = disambiguation;
|
Disambiguation = disambiguation;
|
||||||
TrackNumber = trackNumber;
|
TrackNumber = trackNumber;
|
||||||
|
|||||||
+2
-7
@@ -31,7 +31,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
|||||||
Description = "Updates the details of the track identified by the route, returning the full details of the updated track. The track is updated by an Admin, who can update the tracks of all libraries, or by the owner of the library of the track.";
|
Description = "Updates the details of the track identified by the route, returning the full details of the updated track. The track is updated by an Admin, who can update the tracks of all libraries, or by the owner of the library of the track.";
|
||||||
|
|
||||||
ExampleRequest = new UpdateTrackRequest(
|
ExampleRequest = new UpdateTrackRequest(
|
||||||
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
|
||||||
Metadata: new MusicTrackMetadataDto(
|
Metadata: new MusicTrackMetadataDto(
|
||||||
Title: "Bohemian Rhapsody",
|
Title: "Bohemian Rhapsody",
|
||||||
OriginalTitle: "Bohemian Rhapsody",
|
OriginalTitle: "Bohemian Rhapsody",
|
||||||
@@ -124,7 +123,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
|||||||
DiscNumber: 1
|
DiscNumber: 1
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestParam(r => r.Path, "The file system path of the track. Required.");
|
|
||||||
RequestParam(r => r.Metadata, "The audio metadata of the track. Required.");
|
RequestParam(r => r.Metadata, "The audio metadata of the track. Required.");
|
||||||
RequestParam(r => r.Metadata!.Title, "The title of the track. Required.");
|
RequestParam(r => r.Metadata!.Title, "The title of the track. Required.");
|
||||||
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the track. Optional.");
|
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the track. Optional.");
|
||||||
@@ -397,7 +395,7 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Response(409, "The request failed because the new file system path already belongs to another track in the library, or because a unique constraint was violated.", "application/problem+json",
|
Response(409, "The request failed because a unique constraint was violated.", "application/problem+json",
|
||||||
example: new
|
example: new
|
||||||
{
|
{
|
||||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||||
@@ -426,8 +424,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
|||||||
"ArtistIdCannotBeEmpty",
|
"ArtistIdCannotBeEmpty",
|
||||||
"AlbumIdCannotBeEmpty",
|
"AlbumIdCannotBeEmpty",
|
||||||
"TrackIdCannotBeEmpty",
|
"TrackIdCannotBeEmpty",
|
||||||
"TrackPathCannotBeEmpty",
|
|
||||||
"TrackPathMustBeMaximum2048CharactersLong",
|
|
||||||
"MetadataCannotBeNull",
|
"MetadataCannotBeNull",
|
||||||
"TitleCannotBeEmpty",
|
"TitleCannotBeEmpty",
|
||||||
"TitleMustBeMaximum255CharactersLong",
|
"TitleMustBeMaximum255CharactersLong",
|
||||||
@@ -468,8 +464,7 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
|||||||
"RatingValueMustBePositive",
|
"RatingValueMustBePositive",
|
||||||
"RatingValueCannotBeGreaterThanMaxValue",
|
"RatingValueCannotBeGreaterThanMaxValue",
|
||||||
"RatingMaxValueMustBePositive",
|
"RatingMaxValueMustBePositive",
|
||||||
"RatingVoteCountMustBePositive",
|
"RatingVoteCountMustBePositive"
|
||||||
"TrackPathMustBeWithinLibraryContentLocations"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
-2
@@ -14,7 +14,6 @@ namespace Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibr
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a request to update an existing track of an album of a music artist.
|
/// Represents a request to update an existing track of an album of a music artist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Path">The file system path of the track. Required.</param>
|
|
||||||
/// <param name="Metadata">The audio metadata of the track. Required.</param>
|
/// <param name="Metadata">The audio metadata of the track. Required.</param>
|
||||||
/// <param name="TrackNumber">The number of the track on its disc. Required.</param>
|
/// <param name="TrackNumber">The number of the track on its disc. Required.</param>
|
||||||
/// <param name="DiscNumber">The number of the disc the track belongs to. Optional.</param>
|
/// <param name="DiscNumber">The number of the disc the track belongs to. Optional.</param>
|
||||||
@@ -30,7 +29,6 @@ namespace Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibr
|
|||||||
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
||||||
[DebuggerDisplay("Title: {Metadata?.Title}")]
|
[DebuggerDisplay("Title: {Metadata?.Title}")]
|
||||||
public record UpdateMusicTrackRequest(
|
public record UpdateMusicTrackRequest(
|
||||||
string? Path,
|
|
||||||
MusicTrackMetadataDto? Metadata,
|
MusicTrackMetadataDto? Metadata,
|
||||||
int? TrackNumber,
|
int? TrackNumber,
|
||||||
int? DiscNumber,
|
int? DiscNumber,
|
||||||
|
|||||||
+4
-4
@@ -95,10 +95,10 @@
|
|||||||
<div class="book-details-form">
|
<div class="book-details-form">
|
||||||
<!-- General information. -->
|
<!-- General information. -->
|
||||||
<h3 class="text-light-two">@_localizer["GeneralInformation"]</h3>
|
<h3 class="text-light-two">@_localizer["GeneralInformation"]</h3>
|
||||||
<!-- Path. -->
|
<!-- Path (read-only: a track path is set only by the scanner, it can never be edited). -->
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-label"><label for="track-path">@_localizer["TrackPath"]</label>:</div>
|
<div class="form-label">@_localizer["TrackPath"]:</div>
|
||||||
<div class="form-field"><input id="track-path" type="text" class="enlightenment-input" value="@(Model.Path ?? string.Empty)" /></div>
|
<div class="form-field"><span id="track-path" style="word-break: break-all;">@(Model.Path ?? string.Empty)</span></div>
|
||||||
<small class="form-label text-disabled form-description">@_localizer["TrackPathDescription"]</small>
|
<small class="form-label text-disabled form-description">@_localizer["TrackPathDescription"]</small>
|
||||||
</div>
|
</div>
|
||||||
<!-- Title. -->
|
<!-- Title. -->
|
||||||
@@ -793,9 +793,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Builds the payload of the edited track, matching the update request of the API.
|
// Builds the payload of the edited track, matching the update request of the API.
|
||||||
|
// The file system path is not included: a track path is set only by the scanner and can never be edited.
|
||||||
function buildPayload() {
|
function buildPayload() {
|
||||||
return {
|
return {
|
||||||
Path: readValue('track-path') || null,
|
|
||||||
Metadata: {
|
Metadata: {
|
||||||
Title: readValue('track-title'),
|
Title: readValue('track-title'),
|
||||||
OriginalTitle: readValue('track-original-title') || null,
|
OriginalTitle: readValue('track-original-title') || null,
|
||||||
|
|||||||
-5
@@ -39,7 +39,6 @@ public class UpdateTrackCommandFixture
|
|||||||
/// <param name="artistId">Optional. The Id of the artist the track belongs to.</param>
|
/// <param name="artistId">Optional. The Id of the artist the track belongs to.</param>
|
||||||
/// <param name="albumId">Optional. The Id of the album the track belongs to.</param>
|
/// <param name="albumId">Optional. The Id of the album the track belongs to.</param>
|
||||||
/// <param name="trackId">Optional. The Id of the track to update.</param>
|
/// <param name="trackId">Optional. The Id of the track to update.</param>
|
||||||
/// <param name="path">Optional. The file system path of the track.</param>
|
|
||||||
/// <param name="metadata">Optional. The audio metadata of the track.</param>
|
/// <param name="metadata">Optional. The audio metadata of the track.</param>
|
||||||
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
||||||
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
|
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
|
||||||
@@ -69,7 +68,6 @@ public class UpdateTrackCommandFixture
|
|||||||
/// <param name="includeArtistId">Whether the artist Id should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeArtistId">Whether the artist Id should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includeAlbumId">Whether the album Id should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeAlbumId">Whether the album Id should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includeTrackId">Whether the track Id should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeTrackId">Whether the track Id should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includePath">Whether the path should be included, or forced to <see langword="null"/>.</param>
|
|
||||||
/// <param name="includeTrackNumber">Whether the track number should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeTrackNumber">Whether the track number should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <returns>The created command to update a track.</returns>
|
/// <returns>The created command to update a track.</returns>
|
||||||
public UpdateTrackCommand Create(
|
public UpdateTrackCommand Create(
|
||||||
@@ -77,7 +75,6 @@ public class UpdateTrackCommandFixture
|
|||||||
string? artistId = null,
|
string? artistId = null,
|
||||||
string? albumId = null,
|
string? albumId = null,
|
||||||
string? trackId = null,
|
string? trackId = null,
|
||||||
string? path = null,
|
|
||||||
MusicTrackMetadataDto? metadata = null,
|
MusicTrackMetadataDto? metadata = null,
|
||||||
int? trackNumber = null,
|
int? trackNumber = null,
|
||||||
int? discNumber = null,
|
int? discNumber = null,
|
||||||
@@ -107,7 +104,6 @@ public class UpdateTrackCommandFixture
|
|||||||
bool includeArtistId = true,
|
bool includeArtistId = true,
|
||||||
bool includeAlbumId = true,
|
bool includeAlbumId = true,
|
||||||
bool includeTrackId = true,
|
bool includeTrackId = true,
|
||||||
bool includePath = true,
|
|
||||||
bool includeTrackNumber = true)
|
bool includeTrackNumber = true)
|
||||||
{
|
{
|
||||||
return new UpdateTrackCommand(
|
return new UpdateTrackCommand(
|
||||||
@@ -115,7 +111,6 @@ public class UpdateTrackCommandFixture
|
|||||||
includeArtistId ? (artistId ?? _faker.Random.Guid().ToString()) : null,
|
includeArtistId ? (artistId ?? _faker.Random.Guid().ToString()) : null,
|
||||||
includeAlbumId ? (albumId ?? _faker.Random.Guid().ToString()) : null,
|
includeAlbumId ? (albumId ?? _faker.Random.Guid().ToString()) : null,
|
||||||
includeTrackId ? (trackId ?? _faker.Random.Guid().ToString()) : null,
|
includeTrackId ? (trackId ?? _faker.Random.Guid().ToString()) : null,
|
||||||
includePath ? (path ?? _faker.System.FilePath()) : null,
|
|
||||||
includeMetadata ? (metadata ?? _musicTrackMetadataDtoFixture.Create()) : null,
|
includeMetadata ? (metadata ?? _musicTrackMetadataDtoFixture.Create()) : null,
|
||||||
includeTrackNumber ? (trackNumber ?? _faker.Random.Int(1, 20)) : null,
|
includeTrackNumber ? (trackNumber ?? _faker.Random.Int(1, 20)) : null,
|
||||||
includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null,
|
includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null,
|
||||||
|
|||||||
-5
@@ -35,7 +35,6 @@ public class UpdateTrackRequestFixture
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a random valid request to update a track.
|
/// Creates a random valid request to update a track.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Optional. The file system path of the track.</param>
|
|
||||||
/// <param name="metadata">Optional. The audio metadata of the track.</param>
|
/// <param name="metadata">Optional. The audio metadata of the track.</param>
|
||||||
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
||||||
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
|
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
|
||||||
@@ -60,12 +59,10 @@ public class UpdateTrackRequestFixture
|
|||||||
/// <param name="includeIsrcs">Whether the ISRC codes should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeIsrcs">Whether the ISRC codes should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includeContributors">Whether the contributors list should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeContributors">Whether the contributors list should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includeRatings">Whether the ratings list should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeRatings">Whether the ratings list should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includePath">Whether the path should be included, or forced to <see langword="null"/>.</param>
|
|
||||||
/// <param name="includeMetadata">Whether the metadata should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeMetadata">Whether the metadata should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includeTrackNumber">Whether the track number should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeTrackNumber">Whether the track number should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <returns>The created request to update a track.</returns>
|
/// <returns>The created request to update a track.</returns>
|
||||||
public UpdateTrackRequest Create(
|
public UpdateTrackRequest Create(
|
||||||
string? path = null,
|
|
||||||
MusicTrackMetadataDto? metadata = null,
|
MusicTrackMetadataDto? metadata = null,
|
||||||
int? trackNumber = null,
|
int? trackNumber = null,
|
||||||
int? discNumber = null,
|
int? discNumber = null,
|
||||||
@@ -90,12 +87,10 @@ public class UpdateTrackRequestFixture
|
|||||||
bool includeIsrcs = true,
|
bool includeIsrcs = true,
|
||||||
bool includeContributors = true,
|
bool includeContributors = true,
|
||||||
bool includeRatings = true,
|
bool includeRatings = true,
|
||||||
bool includePath = true,
|
|
||||||
bool includeMetadata = true,
|
bool includeMetadata = true,
|
||||||
bool includeTrackNumber = true)
|
bool includeTrackNumber = true)
|
||||||
{
|
{
|
||||||
return new UpdateTrackRequest(
|
return new UpdateTrackRequest(
|
||||||
includePath ? (path ?? _faker.System.FilePath()) : null,
|
|
||||||
includeMetadata ? (metadata ?? _musicTrackMetadataDtoFixture.Create()) : null,
|
includeMetadata ? (metadata ?? _musicTrackMetadataDtoFixture.Create()) : null,
|
||||||
includeTrackNumber ? (trackNumber ?? _faker.Random.Int(1, 20)) : null,
|
includeTrackNumber ? (trackNumber ?? _faker.Random.Int(1, 20)) : null,
|
||||||
includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null,
|
includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null,
|
||||||
|
|||||||
-5
@@ -35,7 +35,6 @@ public class UpdateMusicTrackRequestFixture
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="UpdateMusicTrackRequest"/> instance with randomized test data.
|
/// Creates a new <see cref="UpdateMusicTrackRequest"/> instance with randomized test data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Optional. The file system path of the track.</param>
|
|
||||||
/// <param name="metadata">Optional. The audio metadata of the track.</param>
|
/// <param name="metadata">Optional. The audio metadata of the track.</param>
|
||||||
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
||||||
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
|
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
|
||||||
@@ -49,7 +48,6 @@ public class UpdateMusicTrackRequestFixture
|
|||||||
/// <param name="isrcs">Optional. The ISRC codes of the track.</param>
|
/// <param name="isrcs">Optional. The ISRC codes of the track.</param>
|
||||||
/// <param name="contributors">Optional. The references to the media contributors that performed on the track.</param>
|
/// <param name="contributors">Optional. The references to the media contributors that performed on the track.</param>
|
||||||
/// <param name="ratings">Optional. The ratings of the track.</param>
|
/// <param name="ratings">Optional. The ratings of the track.</param>
|
||||||
/// <param name="includePath">Whether the path should be included, or forced to <see langword="null"/>.</param>
|
|
||||||
/// <param name="includeMetadata">Whether the metadata should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeMetadata">Whether the metadata should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includeTrackNumber">Whether the track number should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeTrackNumber">Whether the track number should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <param name="includeDiscNumber">Whether the disc number should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeDiscNumber">Whether the disc number should be included, or forced to <see langword="null"/>.</param>
|
||||||
@@ -65,7 +63,6 @@ public class UpdateMusicTrackRequestFixture
|
|||||||
/// <param name="includeRatings">Whether the ratings should be included, or forced to <see langword="null"/>.</param>
|
/// <param name="includeRatings">Whether the ratings should be included, or forced to <see langword="null"/>.</param>
|
||||||
/// <returns>A configured <see cref="UpdateMusicTrackRequest"/> instance.</returns>
|
/// <returns>A configured <see cref="UpdateMusicTrackRequest"/> instance.</returns>
|
||||||
public UpdateMusicTrackRequest Create(
|
public UpdateMusicTrackRequest Create(
|
||||||
string? path = null,
|
|
||||||
MusicTrackMetadataDto? metadata = null,
|
MusicTrackMetadataDto? metadata = null,
|
||||||
int? trackNumber = null,
|
int? trackNumber = null,
|
||||||
int? discNumber = null,
|
int? discNumber = null,
|
||||||
@@ -79,7 +76,6 @@ public class UpdateMusicTrackRequestFixture
|
|||||||
List<IsrcDto>? isrcs = null,
|
List<IsrcDto>? isrcs = null,
|
||||||
List<MediaContributorReferenceDto>? contributors = null,
|
List<MediaContributorReferenceDto>? contributors = null,
|
||||||
List<AudioRatingDto>? ratings = null,
|
List<AudioRatingDto>? ratings = null,
|
||||||
bool includePath = true,
|
|
||||||
bool includeMetadata = true,
|
bool includeMetadata = true,
|
||||||
bool includeTrackNumber = true,
|
bool includeTrackNumber = true,
|
||||||
bool includeDiscNumber = true,
|
bool includeDiscNumber = true,
|
||||||
@@ -95,7 +91,6 @@ public class UpdateMusicTrackRequestFixture
|
|||||||
bool includeRatings = true)
|
bool includeRatings = true)
|
||||||
{
|
{
|
||||||
return new UpdateMusicTrackRequest(
|
return new UpdateMusicTrackRequest(
|
||||||
Path: includePath ? (path ?? _faker.System.FilePath()) : null,
|
|
||||||
Metadata: includeMetadata ? (metadata ?? _musicTrackMetadataDtoFixture.Create()) : null,
|
Metadata: includeMetadata ? (metadata ?? _musicTrackMetadataDtoFixture.Create()) : null,
|
||||||
TrackNumber: includeTrackNumber ? (trackNumber ?? _faker.Random.Number(1, 30)) : null,
|
TrackNumber: includeTrackNumber ? (trackNumber ?? _faker.Random.Number(1, 30)) : null,
|
||||||
DiscNumber: includeDiscNumber ? (discNumber ?? _faker.Random.Number(1, 4)) : null,
|
DiscNumber: includeDiscNumber ? (discNumber ?? _faker.Random.Number(1, 4)) : null,
|
||||||
|
|||||||
+6
-52
@@ -56,7 +56,6 @@ namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.Library.AudioL
|
|||||||
public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>, IAsyncLifetime
|
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_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 HttpClient _client;
|
||||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||||
@@ -115,10 +114,9 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
// Arrange
|
// Arrange
|
||||||
Guid userId = GetCurrentUserId();
|
Guid userId = GetCurrentUserId();
|
||||||
Guid libraryId = await SeedLibraryAsync(userId);
|
Guid libraryId = await SeedLibraryAsync(userId);
|
||||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
string originalPath = Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac");
|
||||||
string updatedPath = Path.Combine(s_contentRootPath, $"love-of-my-life-{Guid.NewGuid():N}.flac");
|
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, originalPath);
|
||||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||||
path: updatedPath,
|
|
||||||
metadata: _musicTrackMetadataDtoFixture.Create(title: "Somebody to Love"),
|
metadata: _musicTrackMetadataDtoFixture.Create(title: "Somebody to Love"),
|
||||||
moods: [],
|
moods: [],
|
||||||
isrcs: [],
|
isrcs: [],
|
||||||
@@ -142,14 +140,15 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
Assert.NotNull(trackResponse);
|
Assert.NotNull(trackResponse);
|
||||||
Assert.Equal(trackId, trackResponse!.Id);
|
Assert.Equal(trackId, trackResponse!.Id);
|
||||||
Assert.Equal(libraryId, trackResponse.LibraryId);
|
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);
|
Assert.Equal("Somebody to Love", trackResponse.Metadata!.Title);
|
||||||
|
|
||||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||||
TrackEntity storedTrack = dbContext.Tracks.Single(track => track.Id == trackId);
|
TrackEntity storedTrack = dbContext.Tracks.Single(track => track.Id == trackId);
|
||||||
Assert.Equal("Somebody to Love", storedTrack.Title);
|
Assert.Equal("Somebody to Love", storedTrack.Title);
|
||||||
Assert.Equal(updatedPath, storedTrack.Path);
|
Assert.Equal(originalPath, storedTrack.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -160,7 +159,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
Guid libraryId = await SeedLibraryAsync(otherUserId);
|
Guid libraryId = await SeedLibraryAsync(otherUserId);
|
||||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
||||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||||
path: Path.Combine(s_contentRootPath, "dont-stop-me-now.flac"),
|
|
||||||
metadata: _musicTrackMetadataDtoFixture.Create(title: "Don't Stop Me Now"),
|
metadata: _musicTrackMetadataDtoFixture.Create(title: "Don't Stop Me Now"),
|
||||||
moods: [],
|
moods: [],
|
||||||
isrcs: [],
|
isrcs: [],
|
||||||
@@ -301,22 +299,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
await AssertNotFoundAsync(response, "LibraryNotFound");
|
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]
|
[Fact]
|
||||||
public async Task UpdateTrack_WhenAReferencedContributorDoesNotExist_ShouldReturnMediaContributorNotFoundProblem()
|
public async Task UpdateTrack_WhenAReferencedContributorDoesNotExist_ShouldReturnMediaContributorNotFoundProblem()
|
||||||
{
|
{
|
||||||
@@ -325,7 +307,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
Guid libraryId = await SeedLibraryAsync(userId);
|
Guid libraryId = await SeedLibraryAsync(userId);
|
||||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
||||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||||
path: Path.Combine(s_contentRootPath, "somebody-to-love.flac"),
|
|
||||||
contributors: [_mediaContributorReferenceDtoFixture.Create(contributorId: Guid.NewGuid(), role: MediaContributorRole.Vocals)]);
|
contributors: [_mediaContributorReferenceDtoFixture.Create(contributorId: Guid.NewGuid(), role: MediaContributorRole.Vocals)]);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -350,7 +331,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
];
|
];
|
||||||
await SeedContributorsAsync(duplicatedContributors);
|
await SeedContributorsAsync(duplicatedContributors);
|
||||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||||
path: Path.Combine(s_contentRootPath, "another-one-bites-the-dust.flac"),
|
|
||||||
moods: [],
|
moods: [],
|
||||||
isrcs: [],
|
isrcs: [],
|
||||||
contributors: duplicatedContributors,
|
contributors: duplicatedContributors,
|
||||||
@@ -373,32 +353,6 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
Assert.Contains(links, link => link.Role == MediaContributorRole.Guitar);
|
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]
|
[Fact]
|
||||||
public async Task UpdateTrack_WhenMetadataIsNull_ShouldReturnUnprocessableEntity()
|
public async Task UpdateTrack_WhenMetadataIsNull_ShouldReturnUnprocessableEntity()
|
||||||
{
|
{
|
||||||
@@ -1004,7 +958,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
Guid userId = GetCurrentUserId();
|
Guid userId = GetCurrentUserId();
|
||||||
Guid libraryId = await SeedLibraryAsync(userId);
|
Guid libraryId = await SeedLibraryAsync(userId);
|
||||||
(Guid artistId, Guid albumId, Guid trackId) = await SeedArtistGraphAsync(libraryId, Path.Combine(s_contentRootPath, "bohemian-rhapsody.flac"));
|
(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));
|
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
|
|||||||
+1
-1
@@ -63,7 +63,7 @@ public class SaveMusicTrackEndpointTests : IClassFixture<LuminaWebFactory>
|
|||||||
using JsonDocument json = JsonDocument.Parse(content);
|
using JsonDocument json = JsonDocument.Parse(content);
|
||||||
Assert.True(json.RootElement.GetProperty("success").GetBoolean());
|
Assert.True(json.RootElement.GetProperty("success").GetBoolean());
|
||||||
Assert.Equal(trackId, json.RootElement.GetProperty("data").GetProperty("id").GetGuid());
|
Assert.Equal(trackId, json.RootElement.GetProperty("data").GetProperty("id").GetGuid());
|
||||||
Assert.Contains(_apiFactory.ApiClientStub.PutRequests, putRequest => putRequest.Endpoint == $"libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}" && putRequest.Data is UpdateMusicTrackRequest forwarded && forwarded.Metadata!.Title == request.Metadata!.Title && forwarded.Path == request.Path);
|
Assert.Contains(_apiFactory.ApiClientStub.PutRequests, putRequest => putRequest.Endpoint == $"libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}" && putRequest.Data is UpdateMusicTrackRequest forwarded && forwarded.Metadata!.Title == request.Metadata!.Title);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
-1
@@ -94,7 +94,6 @@ public class UpdateTrackEndpointTests : IClassFixture<LuminaApiFactory>, IDispos
|
|||||||
SeedLibrary(libraryId, userId);
|
SeedLibrary(libraryId, userId);
|
||||||
(Guid artistId, Guid albumId, Guid trackId) = SeedArtistGraph(libraryId);
|
(Guid artistId, Guid albumId, Guid trackId) = SeedArtistGraph(libraryId);
|
||||||
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
UpdateTrackRequest request = _updateTrackRequestFixture.Create(
|
||||||
path: Path.Combine(s_contentRootPath, $"injected-{Guid.NewGuid():N}.flac"),
|
|
||||||
metadata: _musicTrackMetadataDtoFixture.Create(title: maliciousTitle),
|
metadata: _musicTrackMetadataDtoFixture.Create(title: maliciousTitle),
|
||||||
moods: [],
|
moods: [],
|
||||||
isrcs: [],
|
isrcs: [],
|
||||||
|
|||||||
+6
-3
@@ -44,8 +44,9 @@ public class UpdateArtistCommandMappingTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
Guid libraryId = Guid.NewGuid();
|
Guid libraryId = Guid.NewGuid();
|
||||||
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
||||||
string updatedPath = "/music/queen/a-night-at-the-opera/03-you-re-my-best-friend.flac";
|
string originalPath = artist.Albums.SelectMany(album => album.Tracks).First(track => track.Id.Value == trackId).Path;
|
||||||
AddTrackCommand trackCommand = _addTrackCommandFixture.Create(trackId: trackId, path: updatedPath, trackNumber: 7);
|
string attemptedPath = "/music/queen/a-night-at-the-opera/03-you-re-my-best-friend.flac";
|
||||||
|
AddTrackCommand trackCommand = _addTrackCommandFixture.Create(trackId: trackId, path: attemptedPath, trackNumber: 7);
|
||||||
AddAlbumCommand albumCommand = _addAlbumCommandFixture.Create(albumId: albumId, tracks: [trackCommand]);
|
AddAlbumCommand albumCommand = _addAlbumCommandFixture.Create(albumId: albumId, tracks: [trackCommand]);
|
||||||
UpdateArtistCommand command = _updateArtistCommandFixture.Create(
|
UpdateArtistCommand command = _updateArtistCommandFixture.Create(
|
||||||
libraryId: libraryId.ToString(),
|
libraryId: libraryId.ToString(),
|
||||||
@@ -67,7 +68,9 @@ public class UpdateArtistCommandMappingTests
|
|||||||
Album updatedAlbum = result.Value.Albums.First(album => album.Id.Value == albumId);
|
Album updatedAlbum = result.Value.Albums.First(album => album.Id.Value == albumId);
|
||||||
Assert.Equal(albumCommand.Metadata!.Title, updatedAlbum.Metadata.Title);
|
Assert.Equal(albumCommand.Metadata!.Title, updatedAlbum.Metadata.Title);
|
||||||
Track updatedTrack = updatedAlbum.Tracks.First(track => track.Id.Value == trackId);
|
Track updatedTrack = updatedAlbum.Tracks.First(track => track.Id.Value == trackId);
|
||||||
Assert.Equal(updatedPath, updatedTrack.Path);
|
// the file system path of an existing track is never changed by the update, it is set only when the track is created
|
||||||
|
Assert.Equal(originalPath, updatedTrack.Path);
|
||||||
|
Assert.NotEqual(attemptedPath, updatedTrack.Path);
|
||||||
Assert.Equal(7, updatedTrack.TrackNumber);
|
Assert.Equal(7, updatedTrack.TrackNumber);
|
||||||
Assert.True(updatedTrack.DiscNumber.HasValue);
|
Assert.True(updatedTrack.DiscNumber.HasValue);
|
||||||
Assert.Equal(trackCommand.DiscNumber, updatedTrack.DiscNumber.Value);
|
Assert.Equal(trackCommand.DiscNumber, updatedTrack.DiscNumber.Value);
|
||||||
|
|||||||
+8
-6
@@ -45,8 +45,8 @@ public class UpdateTrackCommandMappingTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
Guid libraryId = Guid.NewGuid();
|
Guid libraryId = Guid.NewGuid();
|
||||||
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
||||||
string updatedPath = "/music/queen/a-night-at-the-opera/02-love-of-my-life.flac";
|
string originalPath = artist.Albums.SelectMany(album => album.Tracks).First(track => track.Id.Value == trackId).Path;
|
||||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: artist.Id.Value.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString(), path: updatedPath);
|
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: artist.Id.Value.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Artist> result = command.ToDomainEntity(artist);
|
Result<Artist> result = command.ToDomainEntity(artist);
|
||||||
@@ -55,7 +55,8 @@ public class UpdateTrackCommandMappingTests
|
|||||||
Assert.False(result.IsFailure);
|
Assert.False(result.IsFailure);
|
||||||
Assert.Same(artist, result.Value);
|
Assert.Same(artist, result.Value);
|
||||||
Track updatedTrack = result.Value.Albums.First(album => album.Id.Value == albumId).Tracks.First(track => track.Id.Value == trackId);
|
Track updatedTrack = result.Value.Albums.First(album => album.Id.Value == albumId).Tracks.First(track => track.Id.Value == trackId);
|
||||||
Assert.Equal(updatedPath, updatedTrack.Path);
|
// The file system path is never changed by the update, it is set only when the track is created.
|
||||||
|
Assert.Equal(originalPath, updatedTrack.Path);
|
||||||
Assert.Equal(command.Metadata!.Title, updatedTrack.Metadata.Title);
|
Assert.Equal(command.Metadata!.Title, updatedTrack.Metadata.Title);
|
||||||
Assert.Equal(command.TrackNumber, updatedTrack.TrackNumber);
|
Assert.Equal(command.TrackNumber, updatedTrack.TrackNumber);
|
||||||
Assert.True(updatedTrack.DiscNumber.HasValue);
|
Assert.True(updatedTrack.DiscNumber.HasValue);
|
||||||
@@ -83,8 +84,8 @@ public class UpdateTrackCommandMappingTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
Guid libraryId = Guid.NewGuid();
|
Guid libraryId = Guid.NewGuid();
|
||||||
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
(Artist artist, Guid albumId, Guid trackId) = CreateDomainArtist(libraryId);
|
||||||
string updatedPath = "/music/queen/a-night-at-the-opera/03-you-re-my-best-friend.flac";
|
string originalPath = artist.Albums.SelectMany(album => album.Tracks).First(track => track.Id.Value == trackId).Path;
|
||||||
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: artist.Id.Value.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString(), path: updatedPath, includeDiscNumber: false, includeScript: false, includeKey: false, includeBpm: false, includeWork: false, includeMusicBrainzRecordingId: false, includeMusicBrainzTrackId: false, includeMoods: false, includeIsrcs: false, contributors: [], ratings: []);
|
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: artist.Id.Value.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString(), includeDiscNumber: false, includeScript: false, includeKey: false, includeBpm: false, includeWork: false, includeMusicBrainzRecordingId: false, includeMusicBrainzTrackId: false, includeMoods: false, includeIsrcs: false, contributors: [], ratings: []);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Artist> result = command.ToDomainEntity(artist);
|
Result<Artist> result = command.ToDomainEntity(artist);
|
||||||
@@ -92,7 +93,8 @@ public class UpdateTrackCommandMappingTests
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.False(result.IsFailure);
|
Assert.False(result.IsFailure);
|
||||||
Track updatedTrack = result.Value.Albums.First(album => album.Id.Value == albumId).Tracks.First(track => track.Id.Value == trackId);
|
Track updatedTrack = result.Value.Albums.First(album => album.Id.Value == albumId).Tracks.First(track => track.Id.Value == trackId);
|
||||||
Assert.Equal(updatedPath, updatedTrack.Path);
|
// the file system path is never changed by the update, it is set only when the track is created
|
||||||
|
Assert.Equal(originalPath, updatedTrack.Path);
|
||||||
Assert.Equal(command.TrackNumber, updatedTrack.TrackNumber);
|
Assert.Equal(command.TrackNumber, updatedTrack.TrackNumber);
|
||||||
Assert.False(updatedTrack.DiscNumber.HasValue);
|
Assert.False(updatedTrack.DiscNumber.HasValue);
|
||||||
Assert.False(updatedTrack.Script.HasValue);
|
Assert.False(updatedTrack.Script.HasValue);
|
||||||
|
|||||||
-1
@@ -38,7 +38,6 @@ public class UpdateTrackRequestMappingTests
|
|||||||
Assert.Equal(artistId.ToString(), result.ArtistId);
|
Assert.Equal(artistId.ToString(), result.ArtistId);
|
||||||
Assert.Equal(albumId.ToString(), result.AlbumId);
|
Assert.Equal(albumId.ToString(), result.AlbumId);
|
||||||
Assert.Equal(trackId.ToString(), result.TrackId);
|
Assert.Equal(trackId.ToString(), result.TrackId);
|
||||||
Assert.Equal(request.Path, result.Path);
|
|
||||||
Assert.Equal(request.Metadata, result.Metadata);
|
Assert.Equal(request.Metadata, result.Metadata);
|
||||||
Assert.Equal(request.TrackNumber, result.TrackNumber);
|
Assert.Equal(request.TrackNumber, result.TrackNumber);
|
||||||
Assert.Equal(request.DiscNumber, result.DiscNumber);
|
Assert.Equal(request.DiscNumber, result.DiscNumber);
|
||||||
|
|||||||
+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.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
using Lumina.Domain.Common.Primitives;
|
using Lumina.Domain.Common.Primitives;
|
||||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using System;
|
using System;
|
||||||
@@ -54,7 +53,6 @@ public class UpdateTrackCommandHandlerTests
|
|||||||
private readonly IAuthorizationService _mockAuthorizationService;
|
private readonly IAuthorizationService _mockAuthorizationService;
|
||||||
private readonly ICurrentUserService _mockCurrentUserService;
|
private readonly ICurrentUserService _mockCurrentUserService;
|
||||||
private readonly IValidator<UpdateTrackCommand> _mockValidator;
|
private readonly IValidator<UpdateTrackCommand> _mockValidator;
|
||||||
private readonly IPathService _mockPathService;
|
|
||||||
private readonly UpdateTrackCommandHandler _sut;
|
private readonly UpdateTrackCommandHandler _sut;
|
||||||
private readonly Guid _userId;
|
private readonly Guid _userId;
|
||||||
private readonly UpdateTrackCommandFixture _updateTrackCommandFixture = new();
|
private readonly UpdateTrackCommandFixture _updateTrackCommandFixture = new();
|
||||||
@@ -86,16 +84,14 @@ public class UpdateTrackCommandHandlerTests
|
|||||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||||
_mockValidator = Substitute.For<IValidator<UpdateTrackCommand>>();
|
_mockValidator = Substitute.For<IValidator<UpdateTrackCommand>>();
|
||||||
_mockPathService = Substitute.For<IPathService>();
|
|
||||||
_userId = Guid.NewGuid();
|
_userId = Guid.NewGuid();
|
||||||
|
|
||||||
// Default stubs: the current user is authenticated, the library ownership policy allows access, the validator passes,
|
// 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);
|
_mockCurrentUserService.UserId.Returns(_userId);
|
||||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
_mockValidator.Validate(Arg.Any<UpdateTrackCommand>()).Returns([]);
|
_mockValidator.Validate(Arg.Any<UpdateTrackCommand>()).Returns([]);
|
||||||
_mockPathService.IsPathWithin(Arg.Any<string>(), Arg.Any<string>()).Returns(true);
|
|
||||||
_mockArtistRepository.UpdateAsync(Arg.Any<ArtistEntity>(), Arg.Any<CancellationToken>())
|
_mockArtistRepository.UpdateAsync(Arg.Any<ArtistEntity>(), Arg.Any<CancellationToken>())
|
||||||
.Returns(Result.Updated);
|
.Returns(Result.Updated);
|
||||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<CancellationToken>())
|
_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()))]);
|
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]
|
[Fact]
|
||||||
@@ -118,6 +114,7 @@ public class UpdateTrackCommandHandlerTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
Guid libraryId = Guid.NewGuid();
|
Guid libraryId = Guid.NewGuid();
|
||||||
(ArtistEntity existingArtist, Guid albumId, Guid trackId) = CreateArtistWithTrack(libraryId);
|
(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());
|
UpdateTrackCommand command = _updateTrackCommandFixture.Create(libraryId: libraryId.ToString(), artistId: existingArtist.Id.ToString(), albumId: albumId.ToString(), trackId: trackId.ToString());
|
||||||
ArtistEntity? updatedArtist = null;
|
ArtistEntity? updatedArtist = null;
|
||||||
TrackEntity? updatedTrack = null;
|
TrackEntity? updatedTrack = null;
|
||||||
@@ -139,7 +136,8 @@ public class UpdateTrackCommandHandlerTests
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.False(result.IsFailure);
|
Assert.False(result.IsFailure);
|
||||||
Assert.Equal(trackId, result.Value.Id);
|
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.Metadata!.Title, result.Value.Metadata!.Title);
|
||||||
Assert.Equal(command.Contributors!.Count, result.Value.Contributors!.Count);
|
Assert.Equal(command.Contributors!.Count, result.Value.Contributors!.Count);
|
||||||
await _mockArtistRepository.Received(1).UpdateAsync(Arg.Any<ArtistEntity>(), Arg.Any<CancellationToken>());
|
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>());
|
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]
|
[Fact]
|
||||||
public async Task HandleAsync_WhenNoContributorsAreReferenced_ShouldNotQueryTheContributorRepository()
|
public async Task HandleAsync_WhenNoContributorsAreReferenced_ShouldNotQueryTheContributorRepository()
|
||||||
{
|
{
|
||||||
|
|||||||
-65
@@ -353,71 +353,6 @@ public class UpdateTrackCommandValidatorTests
|
|||||||
result.ShouldNotHaveValidationError(Errors.Music.TrackIdCannotBeEmpty);
|
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]
|
[Fact]
|
||||||
public void Validate_WhenMetadataIsNull_ShouldHaveValidationError()
|
public void Validate_WhenMetadataIsNull_ShouldHaveValidationError()
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-5
@@ -661,7 +661,7 @@ public class ArtistTests
|
|||||||
Track track = _trackFixture.Create();
|
Track track = _trackFixture.Create();
|
||||||
Album album = _albumFixture.Create(tracks: [track]);
|
Album album = _albumFixture.Create(tracks: [track]);
|
||||||
Artist artist = _artistFixture.Create(albums: [album]);
|
Artist artist = _artistFixture.Create(albums: [album]);
|
||||||
string path = "C:\\Music\\queen\\bohemian-rhapsody.flac";
|
string originalPath = track.Path;
|
||||||
AudioMetadata metadata = _audioMetadataFixture.Create();
|
AudioMetadata metadata = _audioMetadataFixture.Create();
|
||||||
Optional<string> disambiguation = Optional<string>.Some("remastered");
|
Optional<string> disambiguation = Optional<string>.Some("remastered");
|
||||||
Optional<int> discNumber = Optional<int>.Some(1);
|
Optional<int> discNumber = Optional<int>.Some(1);
|
||||||
@@ -681,7 +681,6 @@ public class ArtistTests
|
|||||||
Result<Updated> result = artist.UpdateTrackInAlbum(
|
Result<Updated> result = artist.UpdateTrackInAlbum(
|
||||||
album,
|
album,
|
||||||
track,
|
track,
|
||||||
path,
|
|
||||||
metadata,
|
metadata,
|
||||||
disambiguation,
|
disambiguation,
|
||||||
11,
|
11,
|
||||||
@@ -700,7 +699,8 @@ public class ArtistTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(result.IsFailure);
|
Assert.False(result.IsFailure);
|
||||||
Assert.Equal(path, track.Path);
|
// The file system path is not part of the track update, it is set only when the track is created.
|
||||||
|
Assert.Equal(originalPath, track.Path);
|
||||||
Assert.Equal(metadata, track.Metadata);
|
Assert.Equal(metadata, track.Metadata);
|
||||||
Assert.Equal(disambiguation, track.Disambiguation);
|
Assert.Equal(disambiguation, track.Disambiguation);
|
||||||
Assert.Equal(11, track.TrackNumber);
|
Assert.Equal(11, track.TrackNumber);
|
||||||
@@ -735,7 +735,6 @@ public class ArtistTests
|
|||||||
Result<Updated> result = artist.UpdateTrackInAlbum(
|
Result<Updated> result = artist.UpdateTrackInAlbum(
|
||||||
foreignAlbum,
|
foreignAlbum,
|
||||||
track,
|
track,
|
||||||
"C:\\Music\\queen\\bohemian-rhapsody.flac",
|
|
||||||
_audioMetadataFixture.Create(),
|
_audioMetadataFixture.Create(),
|
||||||
Optional<string>.None(),
|
Optional<string>.None(),
|
||||||
11,
|
11,
|
||||||
@@ -773,7 +772,6 @@ public class ArtistTests
|
|||||||
Result<Updated> result = artist.UpdateTrackInAlbum(
|
Result<Updated> result = artist.UpdateTrackInAlbum(
|
||||||
album,
|
album,
|
||||||
track,
|
track,
|
||||||
"C:\\Music\\queen\\bohemian-rhapsody.flac",
|
|
||||||
_audioMetadataFixture.Create(),
|
_audioMetadataFixture.Create(),
|
||||||
Optional<string>.None(),
|
Optional<string>.None(),
|
||||||
11,
|
11,
|
||||||
|
|||||||
+4
-5
@@ -190,8 +190,8 @@ public class TrackTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Track track = _trackFixture.Create();
|
Track track = _trackFixture.Create();
|
||||||
|
string originalPath = track.Path;
|
||||||
List<Mood> originalMoods = [.. track.Moods];
|
List<Mood> originalMoods = [.. track.Moods];
|
||||||
string path = "C:\\Music\\queen\\bohemian-rhapsody.flac";
|
|
||||||
AudioMetadata metadata = _audioMetadataFixture.Create();
|
AudioMetadata metadata = _audioMetadataFixture.Create();
|
||||||
Optional<string> disambiguation = Optional<string>.Some("remastered");
|
Optional<string> disambiguation = Optional<string>.Some("remastered");
|
||||||
Optional<int> discNumber = Optional<int>.Some(2);
|
Optional<int> discNumber = Optional<int>.Some(2);
|
||||||
@@ -206,7 +206,6 @@ public class TrackTests
|
|||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Updated> result = track.UpdateDetails(
|
Result<Updated> result = track.UpdateDetails(
|
||||||
path,
|
|
||||||
metadata,
|
metadata,
|
||||||
disambiguation,
|
disambiguation,
|
||||||
7,
|
7,
|
||||||
@@ -221,7 +220,6 @@ public class TrackTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(result.IsFailure);
|
Assert.False(result.IsFailure);
|
||||||
Assert.Equal(path, track.Path);
|
|
||||||
Assert.Equal(metadata, track.Metadata);
|
Assert.Equal(metadata, track.Metadata);
|
||||||
Assert.Equal(disambiguation, track.Disambiguation);
|
Assert.Equal(disambiguation, track.Disambiguation);
|
||||||
Assert.Equal(7, track.TrackNumber);
|
Assert.Equal(7, track.TrackNumber);
|
||||||
@@ -235,7 +233,9 @@ public class TrackTests
|
|||||||
Assert.Equal(trackId, track.MusicBrainzTrackId);
|
Assert.Equal(trackId, track.MusicBrainzTrackId);
|
||||||
Assert.True(track.UpdatedOnUtc.HasValue);
|
Assert.True(track.UpdatedOnUtc.HasValue);
|
||||||
Assert.True(track.UpdatedOnUtc.Value >= beforeUpdate);
|
Assert.True(track.UpdatedOnUtc.Value >= beforeUpdate);
|
||||||
// the collections are not part of the details update
|
// The file system path is not part of the details update, it is set only when the track is created.
|
||||||
|
Assert.Equal(originalPath, track.Path);
|
||||||
|
// The collections are not part of the details update.
|
||||||
Assert.Equal(originalMoods, track.Moods);
|
Assert.Equal(originalMoods, track.Moods);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,6 @@ public class TrackTests
|
|||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Updated> result = track.UpdateDetails(
|
Result<Updated> result = track.UpdateDetails(
|
||||||
"C:\\Music\\queen\\bohemian-rhapsody.flac",
|
|
||||||
_audioMetadataFixture.Create(),
|
_audioMetadataFixture.Create(),
|
||||||
Optional<string>.None(),
|
Optional<string>.None(),
|
||||||
11,
|
11,
|
||||||
|
|||||||
-1
@@ -158,7 +158,6 @@ public class UpdateTrackEndpointTests
|
|||||||
command.ArtistId == artistId.ToString() &&
|
command.ArtistId == artistId.ToString() &&
|
||||||
command.AlbumId == albumId.ToString() &&
|
command.AlbumId == albumId.ToString() &&
|
||||||
command.TrackId == trackId.ToString() &&
|
command.TrackId == trackId.ToString() &&
|
||||||
command.Path == request.Path &&
|
|
||||||
command.Metadata == request.Metadata &&
|
command.Metadata == request.Metadata &&
|
||||||
command.TrackNumber == request.TrackNumber &&
|
command.TrackNumber == request.TrackNumber &&
|
||||||
command.DiscNumber == request.DiscNumber &&
|
command.DiscNumber == request.DiscNumber &&
|
||||||
|
|||||||
Reference in new issue
Block a user