mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Updates the provider configuration and ownership tests
Covers the provider and reader choices saved with a library, the reconciliation and stale configuration deletion in the provider store, the library type lookups, the ownership and permission checks for update and delete, and the validator behavior for enum names.
This commit is contained in:
1 parent
48ad8692af
commit
64e5163229
127 files changed
+5541
-5296
No files matched your search
+126
-2
@@ -10,6 +10,7 @@ using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -32,6 +33,7 @@ public class AddLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
||||
private HttpClient _client;
|
||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||
private readonly AddLibraryRequestFixture _addLibraryRequestFixture = new();
|
||||
private readonly LibraryProviderSelectionRequestFixture _libraryProviderSelectionRequestFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
@@ -359,6 +361,128 @@ public class AddLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
||||
Assert.False(await dbContext.Libraries.AnyAsync(candidate => candidate.Title == title));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLibrary_WhenAProviderChoiceNamesAnUnsupportedPlugin_ShouldReturnValidationProblemAndNotPersist()
|
||||
{
|
||||
// Arrange
|
||||
string title = "Unsupported Provider Library";
|
||||
AddLibraryRequest request = _addLibraryRequestFixture.Create(
|
||||
title: title,
|
||||
libraryType: "Book",
|
||||
contentLocations: ["C:/Media"],
|
||||
coverImage: null,
|
||||
metadataProviders: [_libraryProviderSelectionRequestFixture.Create(isEnabled: true)]
|
||||
);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/libraries", request);
|
||||
|
||||
// Assert
|
||||
await AssertValidationProblemAsync(response, "PluginNotSupportedForLibraryType");
|
||||
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
Assert.False(await dbContext.Libraries.AnyAsync(candidate => candidate.Title == title));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLibrary_WhenAProviderChoiceIsNull_ShouldReturnValidationProblemAndNotPersist()
|
||||
{
|
||||
// Arrange
|
||||
string title = "Null Provider Choice Library";
|
||||
AddLibraryRequest request = _addLibraryRequestFixture.Create(
|
||||
title: title,
|
||||
libraryType: "Book",
|
||||
contentLocations: ["C:/Media"],
|
||||
coverImage: null,
|
||||
bookReaders: [null]
|
||||
);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/libraries", request);
|
||||
|
||||
// Assert
|
||||
await AssertValidationProblemAsync(response, "PluginIdCannotBeEmpty");
|
||||
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
Assert.False(await dbContext.Libraries.AnyAsync(candidate => candidate.Title == title));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLibrary_WhenAPathTemplatePartIsNull_ShouldReturnValidationProblemAndNotPersist()
|
||||
{
|
||||
// Arrange
|
||||
string title = "Null Path Template Part Library";
|
||||
AddLibraryRequest request = _addLibraryRequestFixture.Create(
|
||||
title: title,
|
||||
libraryType: "Book",
|
||||
contentLocations: ["C:/Media"],
|
||||
coverImage: null,
|
||||
pathTemplateParts: [null]
|
||||
);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/libraries", request);
|
||||
|
||||
// Assert
|
||||
await AssertValidationProblemAsync(response, "PathTemplatePartKindNotSupportedForLibraryType");
|
||||
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
Assert.False(await dbContext.Libraries.AnyAsync(candidate => candidate.Title == title));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLibrary_WhenProviderPluginIdsAreDuplicated_ShouldReturnValidationProblemAndNotPersist()
|
||||
{
|
||||
// Arrange
|
||||
string title = "Duplicated Provider Library";
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
AddLibraryRequest request = _addLibraryRequestFixture.Create(
|
||||
title: title,
|
||||
libraryType: "Book",
|
||||
contentLocations: ["C:/Media"],
|
||||
coverImage: null,
|
||||
bookReaders: [_libraryProviderSelectionRequestFixture.Create(pluginId: pluginId), _libraryProviderSelectionRequestFixture.Create(pluginId: pluginId, isEnabled: false)]
|
||||
);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/libraries", request);
|
||||
|
||||
// Assert
|
||||
await AssertValidationProblemAsync(response, "PluginIdsMustBeUnique");
|
||||
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
Assert.False(await dbContext.Libraries.AnyAsync(candidate => candidate.Title == title));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLibrary_WhenProviderChoicesAreEmpty_ShouldCreateLibrary()
|
||||
{
|
||||
// Arrange
|
||||
string title = "Empty Provider Choices Library";
|
||||
AddLibraryRequest request = _addLibraryRequestFixture.Create(
|
||||
title: title,
|
||||
libraryType: "Book",
|
||||
contentLocations: ["C:/Media"],
|
||||
coverImage: null,
|
||||
metadataProviders: [],
|
||||
artworkProviders: [],
|
||||
bookReaders: []
|
||||
);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/libraries", request);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
Assert.True(await dbContext.Libraries.AnyAsync(candidate => candidate.Title == title));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that <paramref name="response"/> carries the standard validation problem of the add library route.
|
||||
/// </summary>
|
||||
@@ -395,12 +519,12 @@ public class AddLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// clear junction tables first
|
||||
// Clear junction tables first.
|
||||
await dbContext.Set<Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
// then clear main tables
|
||||
// Then clear main tables.
|
||||
await dbContext.Set<Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.Management.DeleteLibrary;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
@@ -54,7 +55,7 @@ public class DeleteLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
/// </summary>
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_client = await _apiFactory.CreateAuthenticatedClientAsync();
|
||||
_client = await _apiFactory.CreateAuthenticatedClientAsync(AuthorizationPermission.CanCreateLibraries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+66
-9
@@ -6,6 +6,7 @@ using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.Management.UpdateLibrary;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
@@ -41,6 +42,7 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
};
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly UpdateLibraryRequestFixture _updateLibraryRequestFixture = new();
|
||||
private readonly LibraryProviderSelectionRequestFixture _libraryProviderSelectionRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateLibraryEndpointTests"/> class.
|
||||
@@ -57,7 +59,7 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
/// </summary>
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_client = await _apiFactory.CreateAuthenticatedClientAsync();
|
||||
_client = await _apiFactory.CreateAuthenticatedClientAsync(AuthorizationPermission.CanCreateLibraries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -69,7 +71,6 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title");
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
userId: userId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
@@ -105,7 +106,6 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
userId: Guid.NewGuid(),
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
@@ -144,7 +144,6 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title", shouldTrackConsumptionProgress: false, completionThresholdPercentage: null);
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
userId: userId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
@@ -185,7 +184,6 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title", shouldTrackConsumptionProgress: true, completionThresholdPercentage: 70);
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
userId: userId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
@@ -226,7 +224,6 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title", shouldTrackConsumptionProgress: true, completionThresholdPercentage: 70);
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
userId: userId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
@@ -267,7 +264,6 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title", shouldTrackConsumptionProgress: false, completionThresholdPercentage: null);
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
userId: userId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
@@ -308,7 +304,6 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title", shouldTrackConsumptionProgress: true, completionThresholdPercentage: 70);
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
userId: userId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
@@ -345,7 +340,6 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title", shouldTrackConsumptionProgress: true, completionThresholdPercentage: 70);
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
userId: userId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
@@ -373,6 +367,69 @@ public class UpdateLibraryEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
|
||||
Assert.Equal(70, storedLibrary.CompletionThresholdPercentage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateLibrary_WhenAProviderChoiceNamesAnUnsupportedPlugin_ShouldReturnValidationProblemAndKeepTheStoredLibrary()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title", shouldTrackConsumptionProgress: true, completionThresholdPercentage: 70);
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
coverImage: null,
|
||||
shouldTrackConsumptionProgress: true,
|
||||
completionThresholdPercentage: 70,
|
||||
artworkProviders: [_libraryProviderSelectionRequestFixture.Create(isEnabled: true)]
|
||||
);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/libraries/{libraryId}", request);
|
||||
|
||||
// Assert
|
||||
await AssertValidationProblemAsync(response, $"/api/v1/libraries/{libraryId}", "PluginNotSupportedForLibraryType");
|
||||
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
LibraryEntity? storedLibrary = await dbContext.Libraries.FirstOrDefaultAsync(candidate => candidate.Id == libraryId);
|
||||
Assert.NotNull(storedLibrary);
|
||||
Assert.Equal("Original Title", storedLibrary!.Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateLibrary_WhenProviderChoicesAreEmpty_ShouldUpdateTheLibrary()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
await SeedLibraryAsync(libraryId, userId, "Original Title", shouldTrackConsumptionProgress: true, completionThresholdPercentage: 70);
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
id: libraryId,
|
||||
title: "Updated Title",
|
||||
libraryType: "EBook",
|
||||
contentLocations: ["C:/Media"],
|
||||
coverImage: null,
|
||||
shouldTrackConsumptionProgress: true,
|
||||
completionThresholdPercentage: 70,
|
||||
metadataProviders: [],
|
||||
artworkProviders: [],
|
||||
bookReaders: []
|
||||
);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/libraries/{libraryId}", request);
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
LibraryEntity? storedLibrary = await dbContext.Libraries.FirstOrDefaultAsync(candidate => candidate.Id == libraryId);
|
||||
Assert.NotNull(storedLibrary);
|
||||
Assert.Equal("Updated Title", storedLibrary!.Title);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that <paramref name="response"/> carries the standard validation problem of the update library route.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user