Files
Musify/backend/Tests/Musify.Application.Tests/TestSupport/TestEntities.cs
T
Admin ebfd41b160 Add track publication, album types, optional track pictures and batch upload URLs
Tracks
- Track.IsPublished (migration marks existing tracks as published). New
  tracks are created unpublished.
- PUT /tracks/{id}/published and PUT /tracks/published change the flag;
  publishing requires completed audio processing (the batch endpoint
  reports skipped tracks).
- An unpublished track is only visible to its owner. A WherePublished /
  VisibleTo filter is applied to search, genres, listening history, last
  listened, likes, mixes, album and playlist contents and counts, recently
  listened albums, public user tracks, track details and stream tickets.
- isPublished is part of the track responses, GET /tracks/users/{userId}
  accepts a published filter and status-counts reports published and
  unpublished totals.
- CreateTrackRequest.pictureIntentId is optional: without it the track
  uses the album cover or the preset picture and no picture processing
  runs. CreateTrackResourcesEvent carries nullable picture fields, so
  queues must be drained before deploying.
- POST /tracks/upload-urls accepts an audios list and one optional picture
  shared by all of them, and returns an intent per file. The upload intent
  limits are raised so a batch fits.

Albums
- AlbumType (Album, EP, Single) on create, update and responses.
- CreateAlbumRequest.trackIds creates the album and links the tracks in a
  single save.
2026-09-25 01:37:55 +02:00

195 lines
6.3 KiB
C#

using Musify.Domain.Entities;
using Musify.Domain.ValueObjects;
namespace Musify.Application.Tests.TestSupport
{
public static class TestEntities
{
public static User User(
long id = 1,
string name = "test-user",
string? firstName = "Test",
string? secondName = "User",
string? profilePictureUrl = null) =>
new()
{
Id = id,
Name = name,
NormalizedName = name.ToUpperInvariant(),
FirstName = firstName,
SecondName = secondName,
ProfilePictureUrl = profilePictureUrl
};
public static TrackPictures ProcessedPictures() => new()
{
OriginalName = "original.webp",
SmallName = "small.webp",
MediumName = "medium.webp",
LargeName = "large.webp",
ProcessingStatus = ProcessingStatus.Completed
};
public static TrackPictures PendingPictures() => new()
{
OriginalName = "original.webp",
ProcessingStatus = ProcessingStatus.Pending
};
public static TrackAudio ProcessedAudio(string folderName = "audio-folder") => new()
{
OriginalName = "original.mp3",
FolderName = folderName,
TranscodeStatus = ProcessingStatus.Completed
};
public static TrackAudio PendingAudio() => new()
{
OriginalName = "original.mp3",
TranscodeStatus = ProcessingStatus.Pending
};
public static Track Track(
User owner,
string title = "Test Track",
double durationSeconds = 180,
TrackPictures? pictures = null,
TrackAudio? audio = null,
LifeCycleStatus lifeCycleStatus = LifeCycleStatus.Active,
IEnumerable<Genre>? tags = null,
bool isExplicit = false,
bool isPublished = true)
{
var track = new Track
{
Title = title,
NormalizedTitle = title.ToUpperInvariant(),
DurationSeconds = durationSeconds,
LifeCycleStatus = lifeCycleStatus,
IsExplicit = isExplicit,
IsPublished = isPublished,
OwnerUserId = owner.Id,
Owner = owner,
Pictures = pictures ?? ProcessedPictures(),
Audio = audio ?? ProcessedAudio()
};
track.Tags = (tags ?? [Genre.Pop])
.Select(tag => new TrackTag { TrackId = track.Id, Tag = tag })
.ToList();
return track;
}
public static EntityPictures PlayListPictures() => new()
{
OriginalName = "original.webp",
SmallName = "small.webp",
MediumName = "medium.webp",
LargeName = "large.webp"
};
public static PlayList PlayList(
long userId,
string name = "Test Playlist",
string? description = null,
EntityPictures? pictures = null,
LifeCycleStatus lifeCycleStatus = LifeCycleStatus.Active,
PlayListVisibility visibility = PlayListVisibility.Private) =>
new()
{
OwnerUserId = userId,
Name = name,
NormalizedName = name.ToUpperInvariant(),
Description = description,
Pictures = pictures ?? PlayListPictures(),
LifeCycleStatus = lifeCycleStatus,
Visibility = visibility
};
public static EntityPictures AlbumPictures() => new()
{
OriginalName = "original.webp",
SmallName = "small.webp",
MediumName = "medium.webp",
LargeName = "large.webp"
};
public static Album Album(
long ownerUserId,
string title = "Test Album",
string? description = null,
int? releaseYear = 2024,
EntityPictures? pictures = null) =>
new()
{
Title = title,
NormalizedTitle = title.ToUpperInvariant(),
Description = description,
ReleaseYear = releaseYear,
OwnerUserId = ownerUserId,
Pictures = pictures ?? AlbumPictures()
};
public static UploadIntent UploadIntent(
long userId,
UploadIntentPurpose purpose = UploadIntentPurpose.TrackPicture,
string bucket = "test-bucket",
string key = "temp/object.webp",
string objectName = "object.webp",
string contentType = "image/webp",
long? expectedSizeBytes = 1024,
UploadIntentStatus status = UploadIntentStatus.Issued,
DateTime? expiresAt = null) =>
new()
{
UserId = userId,
Bucket = bucket,
Key = key,
ObjectName = objectName,
ContentType = contentType,
ExpectedSizeBytes = expectedSizeBytes,
Purpose = purpose,
Status = status,
ExpiresAt = expiresAt ?? DateTime.UtcNow.AddMinutes(5)
};
public static Mix Mix(
long userId,
MixKind kind = MixKind.Discovery,
int position = 0) =>
new()
{
UserId = userId,
Kind = kind,
Position = position
};
public static MixItem MixItem(
Guid mixId,
Guid trackId,
int position = 0) =>
new()
{
MixId = mixId,
Position = position,
TrackId = trackId
};
public static ListeningHistory ListeningHistory(
long userId,
Guid trackId,
DateTime? listenedAt = null,
double? playedSeconds = null,
bool isCounted = true) =>
new()
{
UserId = userId,
TrackId = trackId,
ListenedAt = listenedAt ?? DateTime.UtcNow,
PlayedSeconds = playedSeconds,
IsCounted = isCounted
};
}
}