Add portrait settings support to school creation and update related API and UI components. Enhance error handling for invalid presets and ensure proper cloning of settings. Update tests to validate new functionality.
ci / server (push) Failing after 3m40s
ci / client (push) Failing after 14s

This commit is contained in:
Leonid Pershin
2026-08-20 08:17:58 +03:00
parent db95de0ddf
commit 9d96108516
20 changed files with 293 additions and 40 deletions
@@ -1,5 +1,6 @@
using System.Net;
using System.Net.Http.Json;
using System.Text.Json;
namespace HSchool.AppHost.Tests;
@@ -104,6 +105,40 @@ public class PortraitApiTests(AppHostFixture fixture)
Assert.False(string.IsNullOrWhiteSpace(settings.ActivePresetId));
}
[Fact]
public async Task CreateSchool_CopiesPortraitSettingsIntoTheSave()
{
using var client = fixture.App.CreateHttpClient("server");
await SchoolApiTests.ResetAsync(client);
var school = await SchoolApiTests.CreateAsync(client, "Пресеты школы", Start);
var directory = await SavesDirectoryAsync(client);
var json = await File.ReadAllTextAsync(
Path.Combine(directory, $"{school.Id}.json"),
TestContext.Current.CancellationToken);
using var document = JsonDocument.Parse(json);
Assert.True(document.RootElement.TryGetProperty("portraitSettings", out var presets));
Assert.True(presets.TryGetProperty("presets", out var list));
Assert.True(list.GetArrayLength() > 0);
}
[Fact]
public async Task CreateSchool_RejectsEmptyPortraitPresets()
{
using var client = fixture.App.CreateHttpClient("server");
await SchoolApiTests.ResetAsync(client);
using var response = await client.PostAsJsonAsync(
"/api/schools",
new
{
name = "Плохие пресеты",
startDate = Start,
portraitSettings = new { activePresetId = "missing", presets = Array.Empty<object>(), ageRules = Array.Empty<object>() },
},
TestContext.Current.CancellationToken);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Equal("invalid-portrait-settings", await SchoolApiTests.ProblemCodeAsync(response));
}
[Fact]
public async Task DeleteSchool_RemovesPortraitDirectory()
{
@@ -659,7 +659,15 @@ public class SchoolApiTests(AppHostFixture fixture)
return payload.Path;
}
private sealed record SchoolSaveFile(string? CountryId, string? ClimatePresetId, string? NativeLanguage);
private sealed record SchoolSaveFile(
string? CountryId,
string? ClimatePresetId,
string? NativeLanguage,
SwarmUiSaveFile? PortraitSettings);
private sealed record SwarmUiSaveFile(string? ActivePresetId, IReadOnlyList<SwarmUiPresetSave>? Presets);
private sealed record SwarmUiPresetSave(string? Id, string? Model);
internal static readonly object SimpleCustomMap = new
{
@@ -40,4 +40,18 @@ public class SwarmUiSettingsStoreTests
Assert.Equal("legacy.safetensors", config.Presets[0].Model);
Assert.Equal(12, config.Presets[0].Steps);
}
[Fact]
public void Clone_IsIndependentOfTheSource()
{
var source = SwarmUiConfigFile.CreateDefault();
source.Presets[0].Model = "mutated.safetensors";
var copy = SwarmUiConfigFile.Clone(source);
copy.Presets[0].Model = "other.safetensors";
Assert.Equal("mutated.safetensors", source.Presets[0].Model);
Assert.Equal("other.safetensors", copy.Presets[0].Model);
Assert.Equal(source.ActivePresetId, copy.ActivePresetId);
}
}