mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Adapts the theme integration tests to the bundled lumina-default theme
This commit is contained in:
1 parent
85849783b3
commit
75281f48ef
5 files changed
+18
-10
No files matched your search
+3
-3
@@ -17,7 +17,7 @@ namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
|||||||
public static class ThemeTestHelpers
|
public static class ThemeTestHelpers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Waits until the bundled 'editorial-paper' theme has been installed and activated by the theme detection job at startup.
|
/// Waits until the bundled 'lumina-default' theme has been installed and activated by the theme detection job at startup.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiFactory">The shared API factory whose database is polled.</param>
|
/// <param name="apiFactory">The shared API factory whose database is polled.</param>
|
||||||
/// <returns>A task representing the asynchronous operation.</returns>
|
/// <returns>A task representing the asynchronous operation.</returns>
|
||||||
@@ -31,12 +31,12 @@ public static class ThemeTestHelpers
|
|||||||
using IServiceScope scope = apiFactory.Services.CreateScope();
|
using IServiceScope scope = apiFactory.Services.CreateScope();
|
||||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||||
|
|
||||||
if (await dbContext.Themes.AnyAsync(theme => theme.ThemeId == "editorial-paper" && theme.IsCurrent == true))
|
if (await dbContext.Themes.AnyAsync(theme => theme.ThemeId == "lumina-default" && theme.IsCurrent == true))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await Task.Delay(DELAY_MILLISECONDS);
|
await Task.Delay(DELAY_MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Fail("The bundled theme 'editorial-paper' was not installed and activated within the expected time.");
|
Assert.Fail("The bundled theme 'lumina-default' was not installed and activated within the expected time.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+11
-3
@@ -114,8 +114,12 @@ public class DeleteThemeEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
// Arrange
|
// Arrange
|
||||||
await ThemeTestHelpers.WaitForBundledThemeAsync(_apiFactory);
|
await ThemeTestHelpers.WaitForBundledThemeAsync(_apiFactory);
|
||||||
|
|
||||||
// Act
|
// deleting a bundled theme that is not the last remaining one is allowed, so only the last one is protected
|
||||||
HttpResponseMessage response = await _client.DeleteAsync("/api/v1/themes/editorial-paper");
|
HttpResponseMessage firstDeletionResponse = await _client.DeleteAsync("/api/v1/themes/editorial-paper");
|
||||||
|
Assert.Equal(HttpStatusCode.NoContent, firstDeletionResponse.StatusCode);
|
||||||
|
|
||||||
|
// Act: the last remaining bundled theme cannot be deleted
|
||||||
|
HttpResponseMessage response = await _client.DeleteAsync("/api/v1/themes/lumina-default");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
||||||
@@ -127,9 +131,13 @@ public class DeleteThemeEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
|
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
|
||||||
Assert.Equal("General.Forbidden", problemDetails["title"].GetString());
|
Assert.Equal("General.Forbidden", problemDetails["title"].GetString());
|
||||||
Assert.Equal("LastBundledThemeCannotBeDeleted", problemDetails["detail"].GetString());
|
Assert.Equal("LastBundledThemeCannotBeDeleted", problemDetails["detail"].GetString());
|
||||||
Assert.Equal("/api/v1/themes/editorial-paper", problemDetails["instance"].GetString());
|
Assert.Equal("/api/v1/themes/lumina-default", problemDetails["instance"].GetString());
|
||||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||||
|
|
||||||
|
// restore the soft-deleted bundled theme, so the following tests start from a clean state
|
||||||
|
HttpResponseMessage restoreResponse = await _client.PostAsJsonAsync("/api/v1/themes/editorial-paper/restore", new { });
|
||||||
|
Assert.Equal(HttpStatusCode.NoContent, restoreResponse.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
+2
-2
@@ -220,8 +220,8 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore the bundled theme as the active one, so the following tests start from a clean state
|
// restore the bundled default theme as the active one, so the following tests start from a clean state
|
||||||
ThemeEntity? bundledTheme = await dbContext.Themes.FirstOrDefaultAsync(t => t.ThemeId == "editorial-paper");
|
ThemeEntity? bundledTheme = await dbContext.Themes.FirstOrDefaultAsync(t => t.ThemeId == "lumina-default");
|
||||||
if (bundledTheme is not null)
|
if (bundledTheme is not null)
|
||||||
bundledTheme.IsCurrent = true;
|
bundledTheme.IsCurrent = true;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ public class GetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
|
|
||||||
ThemeResponse? theme = await response.Content.ReadFromJsonAsync<ThemeResponse>(_jsonOptions);
|
ThemeResponse? theme = await response.Content.ReadFromJsonAsync<ThemeResponse>(_jsonOptions);
|
||||||
Assert.NotNull(theme);
|
Assert.NotNull(theme);
|
||||||
Assert.Equal("editorial-paper", theme!.ThemeId);
|
Assert.Equal("lumina-default", theme!.ThemeId);
|
||||||
Assert.True(theme.IsCurrent);
|
Assert.True(theme.IsCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -65,7 +65,7 @@ public class GetThemesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
|
|||||||
List<ThemeResponse>? themes = await response.Content.ReadFromJsonAsync<List<ThemeResponse>>(_jsonOptions);
|
List<ThemeResponse>? themes = await response.Content.ReadFromJsonAsync<List<ThemeResponse>>(_jsonOptions);
|
||||||
Assert.NotNull(themes);
|
Assert.NotNull(themes);
|
||||||
|
|
||||||
ThemeResponse? bundledTheme = themes!.FirstOrDefault(theme => theme.ThemeId == "editorial-paper");
|
ThemeResponse? bundledTheme = themes!.FirstOrDefault(theme => theme.ThemeId == "lumina-default");
|
||||||
Assert.NotNull(bundledTheme);
|
Assert.NotNull(bundledTheme);
|
||||||
Assert.NotEmpty(bundledTheme!.Name);
|
Assert.NotEmpty(bundledTheme!.Name);
|
||||||
Assert.Equal(ThemeInstallSource.Bundled, bundledTheme.InstallSource);
|
Assert.Equal(ThemeInstallSource.Bundled, bundledTheme.InstallSource);
|
||||||
|
|||||||
Reference in new issue
Block a user