A lot of changes

This commit is contained in:
2026-09-24 17:54:16 +02:00
parent ece6ce2a43
commit e84c16cf92
35 changed files with 1815 additions and 222 deletions
@@ -111,6 +111,37 @@ namespace Musify.Api.Tests.Endpoints
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
}
[Fact]
public async Task UpdateAlbumPicture_NotTheOwner_ReturnsForbidden()
{
var owner = await CreateUserAsync();
var stranger = await CreateUserAsync();
var ownerClient = fixture.CreateAuthenticatedClient(owner);
var pictureIntentId = await CreatePictureIntentAsync(ownerClient);
var created = await (await ownerClient.PostAsJsonAsync("/albums", new CreateAlbumRequest("Owned", null, null, pictureIntentId), TestContext.Current.CancellationToken))
.Content.ReadFromJsonAsync<AlbumApplicationResponse>(TestContext.Current.CancellationToken);
var response = await fixture.CreateAuthenticatedClient(stranger).PutAsJsonAsync(
$"/albums/{created!.Id}/picture", new UpdateAlbumPictureRequest(Guid.NewGuid()), TestContext.Current.CancellationToken);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
}
[Fact]
public async Task UpdateAlbumPicture_EmptyIntent_ReturnsBadRequest()
{
var owner = await CreateUserAsync();
var ownerClient = fixture.CreateAuthenticatedClient(owner);
var pictureIntentId = await CreatePictureIntentAsync(ownerClient);
var created = await (await ownerClient.PostAsJsonAsync("/albums", new CreateAlbumRequest("Owned", null, null, pictureIntentId), TestContext.Current.CancellationToken))
.Content.ReadFromJsonAsync<AlbumApplicationResponse>(TestContext.Current.CancellationToken);
var response = await ownerClient.PutAsJsonAsync(
$"/albums/{created!.Id}/picture", new UpdateAlbumPictureRequest(Guid.Empty), TestContext.Current.CancellationToken);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
[Fact]
public async Task DeleteAlbum_Owner_ReturnsNoContentAndAlbumIsGone()
{
@@ -63,7 +63,7 @@ namespace Musify.Api.Tests.Endpoints
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadFromJsonAsync<List<AvailableGenreResponse>>(JsonOptions, TestContext.Current.CancellationToken);
Assert.Equal(Enum.GetValues<Genre>().Length, body!.Count);
Assert.Equal(Enum.GetValues<Genre>().Count(genre => genre != Genre.None), body!.Count);
Assert.Contains(Genre.Lofi, body.Single(g => g.Genre == Genre.Metal).IncompatibleWith);
}
@@ -96,7 +96,7 @@ namespace Musify.Api.Tests.Endpoints
var playList = await CreatePlayListAsync(owner, PlayListVisibility.Public);
var response = await fixture.CreateAuthenticatedClient(stranger).PutAsJsonAsync(
$"/playlists/{playList.Id}", new UpdatePlayListRequest("Hijacked", null, null), Ct);
$"/playlists/{playList.Id}", new UpdatePlayListRequest("Hijacked", null, PlayListVisibility.Public), Ct);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
}
@@ -120,13 +120,50 @@ namespace Musify.Api.Tests.Endpoints
var playList = await CreatePlayListAsync(owner, PlayListVisibility.Private);
var response = await fixture.CreateAuthenticatedClient(owner).PutAsJsonAsync(
$"/playlists/{playList.Id}", new UpdatePlayListRequest("Renamed", null, null), Ct);
$"/playlists/{playList.Id}", new UpdatePlayListRequest("Renamed", null, PlayListVisibility.Private), Ct);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadFromJsonAsync<PlayListApplicationResponse>(JsonOptions, Ct);
Assert.Equal("Renamed", body!.Name);
}
[Fact]
public async Task UpdatePlayList_MissingVisibility_ReturnsBadRequest()
{
var owner = await fixture.SeedUserAsync();
var playList = await CreatePlayListAsync(owner, PlayListVisibility.Public);
var response = await fixture.CreateAuthenticatedClient(owner).PutAsJsonAsync(
$"/playlists/{playList.Id}", new UpdatePlayListRequest("Renamed", null, null), Ct);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
[Fact]
public async Task UpdatePlayListPicture_NotTheOwner_ReturnsForbidden()
{
var owner = await fixture.SeedUserAsync();
var stranger = await fixture.SeedUserAsync();
var playList = await CreatePlayListAsync(owner, PlayListVisibility.Public);
var response = await fixture.CreateAuthenticatedClient(stranger).PutAsJsonAsync(
$"/playlists/{playList.Id}/picture", new UpdatePlayListPictureRequest(Guid.NewGuid()), Ct);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
}
[Fact]
public async Task UpdatePlayListPicture_EmptyIntent_ReturnsBadRequest()
{
var owner = await fixture.SeedUserAsync();
var playList = await CreatePlayListAsync(owner, PlayListVisibility.Public);
var response = await fixture.CreateAuthenticatedClient(owner).PutAsJsonAsync(
$"/playlists/{playList.Id}/picture", new UpdatePlayListPictureRequest(Guid.Empty), Ct);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
[Fact]
public async Task GetPlayListById_NotAGuid_ReturnsNotFound()
{