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.
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user