mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Refactors the book, artist, and album slices across the stack
This commit is contained in:
1 parent
8aaf9fe64e
commit
ea6eb9f796
439 files changed
+28235
-3156
No files matched your search
+3
-3
@@ -44,7 +44,7 @@ public class GetBookDetailsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
GetBookRequest request = _getBookRequestFixture.Create();
|
||||
BookDetailsDto expectedBook = _bookDetailsDtoFixture.Create(id: Guid.Parse(request.Id));
|
||||
BookDetailsDto expectedBook = _bookDetailsDtoFixture.Create(id: Guid.Parse(request.BookId));
|
||||
_mockApiHttpClient.GetAsync<BookDetailsDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedBook);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class GetBookDetailsEndpointTests
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).GetAsync<BookDetailsDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.GET_BOOK.Replace("{id}", request.Id)),
|
||||
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.GET_BOOK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId)),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class GetBookDetailsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
GetBookRequest request = _getBookRequestFixture.Create();
|
||||
BookDetailsDto expectedBook = _bookDetailsDtoFixture.Create(id: Guid.Parse(request.Id));
|
||||
BookDetailsDto expectedBook = _bookDetailsDtoFixture.Create(id: Guid.Parse(request.BookId));
|
||||
_mockApiHttpClient.GetAsync<BookDetailsDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedBook);
|
||||
|
||||
|
||||
+3
-4
@@ -63,8 +63,7 @@ public class GetLibraryItemsEndpointTests
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).GetAsync<PaginatedBookLiteDto>(
|
||||
Arg.Is<string>(endpoint =>
|
||||
endpoint.StartsWith(ApiRoutes.Books.GET_BOOKS_LITE, StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.Contains($"libraryId={request.LibraryId}") &&
|
||||
endpoint.StartsWith(ApiRoutes.Books.GET_BOOKS_LITE.Replace("{libraryId}", request.LibraryId.ToString()), StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.Contains("currentPage=2") &&
|
||||
endpoint.Contains("perPage=48") &&
|
||||
endpoint.Contains("searchTerm=the%20hobbit") &&
|
||||
@@ -89,8 +88,8 @@ public class GetLibraryItemsEndpointTests
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).GetAsync<PaginatedBookLiteDto>(
|
||||
Arg.Is<string>(endpoint =>
|
||||
endpoint.StartsWith(ApiRoutes.Books.GET_BOOKS_LITE, StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.EndsWith($"libraryId={request.LibraryId}&shouldIgnoreThePrefixForAlphaPicker=False", StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.StartsWith(ApiRoutes.Books.GET_BOOKS_LITE.Replace("{libraryId}", request.LibraryId.ToString()), StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.EndsWith("?shouldIgnoreThePrefixForAlphaPicker=False", StringComparison.OrdinalIgnoreCase) &&
|
||||
!endpoint.Contains("currentPage=") &&
|
||||
!endpoint.Contains("searchTerm=") &&
|
||||
!endpoint.Contains("sortBy=")),
|
||||
|
||||
+5
-5
@@ -45,7 +45,7 @@ public class GetReadingAvailabilityEndpointTests
|
||||
// Arrange
|
||||
GetBookReadingAvailabilityRequest request = _requestFixture.Create();
|
||||
ReadingAvailabilityDto availability = _readingAvailabilityDtoFixture.Create(bookId: request.BookId, isAvailable: true);
|
||||
_mockApiHttpClient.GetAsync<ReadingAvailabilityDto>(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY.Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.GetAsync<ReadingAvailabilityDto>(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
.Returns(availability);
|
||||
|
||||
// Act
|
||||
@@ -64,7 +64,7 @@ public class GetReadingAvailabilityEndpointTests
|
||||
// Arrange
|
||||
GetBookReadingAvailabilityRequest request = _requestFixture.Create();
|
||||
ReadingAvailabilityDto availability = _readingAvailabilityDtoFixture.Create(bookId: request.BookId, isAvailable: false, errorCode: "ReaderDisabled");
|
||||
_mockApiHttpClient.GetAsync<ReadingAvailabilityDto>(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY.Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.GetAsync<ReadingAvailabilityDto>(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
.Returns(availability);
|
||||
|
||||
// Act
|
||||
@@ -81,15 +81,15 @@ public class GetReadingAvailabilityEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldRequestReadingAvailabilityFromApi()
|
||||
{
|
||||
// Arrange
|
||||
GetBookReadingAvailabilityRequest request = new(BookId: Guid.NewGuid());
|
||||
GetBookReadingAvailabilityRequest request = _requestFixture.Create();
|
||||
ReadingAvailabilityDto availability = _readingAvailabilityDtoFixture.Create(bookId: request.BookId, isAvailable: true);
|
||||
_mockApiHttpClient.GetAsync<ReadingAvailabilityDto>(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY.Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.GetAsync<ReadingAvailabilityDto>(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
.Returns(availability);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).GetAsync<ReadingAvailabilityDto>(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY.Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.Received(1).GetAsync<ReadingAvailabilityDto>(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -49,7 +49,7 @@ public class GetReadingManifestEndpointTests
|
||||
// Arrange
|
||||
GetBookReadingManifestRequest request = _requestFixture.Create();
|
||||
ReadingManifestDto manifest = _readingManifestDtoFixture.Create();
|
||||
_mockApiHttpClient.GetAsync<ReadingManifestDto>(ApiRoutes.Books.GET_BOOK_READING_MANIFEST.Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.GetAsync<ReadingManifestDto>(ApiRoutes.Books.GET_BOOK_READING_MANIFEST.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
.Returns(manifest);
|
||||
|
||||
// Act
|
||||
@@ -119,13 +119,13 @@ public class GetReadingManifestEndpointTests
|
||||
// Arrange
|
||||
GetBookReadingManifestRequest request = _requestFixture.Create();
|
||||
ReadingManifestDto manifest = _readingManifestDtoFixture.Create();
|
||||
_mockApiHttpClient.GetAsync<ReadingManifestDto>(ApiRoutes.Books.GET_BOOK_READING_MANIFEST.Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.GetAsync<ReadingManifestDto>(ApiRoutes.Books.GET_BOOK_READING_MANIFEST.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>())
|
||||
.Returns(manifest);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).GetAsync<ReadingManifestDto>(ApiRoutes.Books.GET_BOOK_READING_MANIFEST.Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.Received(1).GetAsync<ReadingManifestDto>(ApiRoutes.Books.GET_BOOK_READING_MANIFEST.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{bookId}", request.BookId.ToString()), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+1
@@ -65,6 +65,7 @@ public class GetReadingResourceEndpointTests
|
||||
_mockApiHttpClient.GetBlobAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(blob);
|
||||
string expectedEndpoint = ApiRoutes.Books.GET_BOOK_READING_RESOURCE
|
||||
.Replace("{libraryId}", request.LibraryId.ToString())
|
||||
.Replace("{bookId}", request.BookId.ToString())
|
||||
.Replace("{resourceKey}", Uri.EscapeDataString(request.ResourceKey));
|
||||
|
||||
|
||||
+1
@@ -67,6 +67,7 @@ public class GetReadingSectionEndpointTests
|
||||
_mockApiHttpClient.GetAsync<ReadingSectionDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(section);
|
||||
string expectedEndpoint = ApiRoutes.Books.GET_BOOK_READING_SECTION
|
||||
.Replace("{libraryId}", request.LibraryId.ToString())
|
||||
.Replace("{bookId}", request.BookId.ToString())
|
||||
.Replace("{locationRef}", Uri.EscapeDataString(request.LocationRef));
|
||||
|
||||
|
||||
+61
-18
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.UpdateBookCover;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
@@ -26,6 +28,8 @@ public class UpdateBookCoverEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly UpdateBookCoverEndpoint _sut;
|
||||
private readonly UpdateBookCoverDtoFixture _updateBookCoverDtoFixture = new();
|
||||
private static readonly Guid s_libraryId = Guid.NewGuid();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateBookCoverEndpointTests"/> class.
|
||||
@@ -41,16 +45,16 @@ public class UpdateBookCoverEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid bookId = Guid.NewGuid();
|
||||
_mockApiHttpClient.PutMultipartAsync<string>(Arg.Any<string>(), Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns("/media/books/cover.jpg");
|
||||
_mockApiHttpClient.PutMultipartAsync<UpdateBookCoverDto>(Arg.Any<string>(), Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_updateBookCoverDtoFixture.Create(coverPath: "/media/books/cover.jpg"));
|
||||
ConfigureRequest(bookId, [1, 2, 3], "cover.jpg");
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutMultipartAsync<string>(
|
||||
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK_COVER.Replace("{id}", bookId.ToString())),
|
||||
await _mockApiHttpClient.Received(1).PutMultipartAsync<UpdateBookCoverDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK_COVER.Replace("{libraryId}", s_libraryId.ToString()).Replace("{bookId}", bookId.ToString())),
|
||||
Arg.Any<Stream>(),
|
||||
Arg.Is<string>(fileName => fileName == "cover.jpg"),
|
||||
Arg.Is<string>(fieldName => fieldName == "cover"),
|
||||
@@ -61,16 +65,16 @@ public class UpdateBookCoverEndpointTests
|
||||
public async Task ExecuteAsync_WhenRouteIdIsNotParseable_ShouldUploadCoverWithEmptyBookId()
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.PutMultipartAsync<string>(Arg.Any<string>(), Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns("/media/books/cover.jpg");
|
||||
_mockApiHttpClient.PutMultipartAsync<UpdateBookCoverDto>(Arg.Any<string>(), Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_updateBookCoverDtoFixture.Create(coverPath: "/media/books/cover.jpg"));
|
||||
ConfigureRequest("not-a-guid", [1, 2, 3], "cover.jpg");
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutMultipartAsync<string>(
|
||||
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK_COVER.Replace("{id}", Guid.Empty.ToString())),
|
||||
await _mockApiHttpClient.Received(1).PutMultipartAsync<UpdateBookCoverDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK_COVER.Replace("{libraryId}", s_libraryId.ToString()).Replace("{bookId}", Guid.Empty.ToString())),
|
||||
Arg.Any<Stream>(),
|
||||
Arg.Any<string>(),
|
||||
Arg.Any<string>(),
|
||||
@@ -83,8 +87,8 @@ public class UpdateBookCoverEndpointTests
|
||||
// Arrange
|
||||
Guid bookId = Guid.NewGuid();
|
||||
string expectedPath = "/media/books/cover.jpg";
|
||||
_mockApiHttpClient.PutMultipartAsync<string>(Arg.Any<string>(), Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedPath);
|
||||
_mockApiHttpClient.PutMultipartAsync<UpdateBookCoverDto>(Arg.Any<string>(), Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_updateBookCoverDtoFixture.Create(coverPath: expectedPath));
|
||||
ConfigureRequest(bookId, [1, 2, 3], "cover.jpg");
|
||||
|
||||
// Act
|
||||
@@ -98,20 +102,57 @@ public class UpdateBookCoverEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenFormHasNoFile_ShouldReturnBadRequestProblem()
|
||||
public async Task ExecuteAsync_WhenFormHasNoFile_ShouldForwardRequestWithoutFileToApi()
|
||||
{
|
||||
// Arrange
|
||||
Guid bookId = Guid.NewGuid();
|
||||
string expectedPath = "/media/books/cover.jpg";
|
||||
_mockApiHttpClient.PutMultipartAsync<UpdateBookCoverDto>(Arg.Any<string>(), Arg.Any<Stream?>(), Arg.Any<string?>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_updateBookCoverDtoFixture.Create(coverPath: expectedPath));
|
||||
ConfigureRequestWithoutFiles(bookId);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemDetails = Assert.IsType<ProblemHttpResult>(result);
|
||||
Assert.Equal(StatusCodes.Status400BadRequest, problemDetails.StatusCode);
|
||||
Assert.Equal("The uploaded cover image is missing.", problemDetails.ProblemDetails.Detail);
|
||||
await _mockApiHttpClient.DidNotReceive().PutMultipartAsync<string>(Arg.Any<string>(), Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.Received(1).PutMultipartAsync<UpdateBookCoverDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK_COVER.Replace("{libraryId}", s_libraryId.ToString()).Replace("{bookId}", bookId.ToString())),
|
||||
Arg.Is<Stream?>(stream => stream == null),
|
||||
Arg.Is<string?>(fileName => fileName == null),
|
||||
Arg.Is<string>(fieldName => fieldName == "cover"),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
Assert.Equal(expectedPath, jsonDocument.RootElement.GetProperty("data").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenRequestIsNotMultipart_ShouldForwardRequestWithoutFileToApi()
|
||||
{
|
||||
// Arrange
|
||||
Guid bookId = Guid.NewGuid();
|
||||
string expectedPath = "/media/books/cover.jpg";
|
||||
_mockApiHttpClient.PutMultipartAsync<UpdateBookCoverDto>(Arg.Any<string>(), Arg.Any<Stream?>(), Arg.Any<string?>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_updateBookCoverDtoFixture.Create(coverPath: expectedPath));
|
||||
_sut.HttpContext.Request.RouteValues["bookId"] = bookId.ToString();
|
||||
_sut.HttpContext.Request.QueryString = new QueryString($"?libraryId={s_libraryId}");
|
||||
_sut.HttpContext.Request.ContentType = "application/json";
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutMultipartAsync<UpdateBookCoverDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == ApiRoutes.Books.UPDATE_BOOK_COVER.Replace("{libraryId}", s_libraryId.ToString()).Replace("{bookId}", bookId.ToString())),
|
||||
Arg.Is<Stream?>(stream => stream == null),
|
||||
Arg.Is<string?>(fileName => fileName == null),
|
||||
Arg.Is<string>(fieldName => fieldName == "cover"),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
Assert.Equal(expectedPath, jsonDocument.RootElement.GetProperty("data").GetString());
|
||||
}
|
||||
|
||||
private void ConfigureRequest(Guid bookId, byte[] content, string fileName)
|
||||
@@ -121,7 +162,8 @@ public class UpdateBookCoverEndpointTests
|
||||
|
||||
private void ConfigureRequest(string bookId, byte[] content, string fileName)
|
||||
{
|
||||
_sut.HttpContext.Request.RouteValues["id"] = bookId;
|
||||
_sut.HttpContext.Request.RouteValues["bookId"] = bookId;
|
||||
_sut.HttpContext.Request.QueryString = new QueryString($"?libraryId={s_libraryId}");
|
||||
MemoryStream coverStream = new(content);
|
||||
IFormFile formFile = new FormFile(coverStream, 0, content.Length, "cover", fileName);
|
||||
FormFileCollection files = [formFile];
|
||||
@@ -132,7 +174,8 @@ public class UpdateBookCoverEndpointTests
|
||||
|
||||
private void ConfigureRequestWithoutFiles(Guid bookId)
|
||||
{
|
||||
_sut.HttpContext.Request.RouteValues["id"] = bookId.ToString();
|
||||
_sut.HttpContext.Request.RouteValues["bookId"] = bookId.ToString();
|
||||
_sut.HttpContext.Request.QueryString = new QueryString($"?libraryId={s_libraryId}");
|
||||
IFormCollection form = new FormCollection([]);
|
||||
_sut.HttpContext.Request.ContentType = "multipart/form-data; boundary=----test";
|
||||
_sut.HttpContext.Features.Set<IFormFeature>(new FormFeature(form));
|
||||
|
||||
Reference in new issue
Block a user