Merge main into phase/39-school-owners.
Keep school owners and phase 41 opinions/portraits together; ResetAsync wipes all saves so shared AppHost tests stay isolated.
This commit is contained in:
@@ -177,6 +177,36 @@ public class PeopleApiTests(AppHostFixture fixture)
|
||||
Assert.Contains(motherCard.Family.Children, child => child.Id == card.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Card_ConnectionsCarryOnlyThisPersonsOpinions()
|
||||
{
|
||||
using var client = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.ResetAsync(client);
|
||||
var school = await SchoolApiTests.CreateAsync(client, "Связи карточка", Start, seed: 1);
|
||||
|
||||
var pupils = await GetPeopleAsync(client, school.Id, "role=student&pageSize=20");
|
||||
var pupil = pupils.People.First(person => person.Roles.Contains("student"));
|
||||
var card = await GetCardAsync(client, school.Id, pupil.Id);
|
||||
|
||||
Assert.NotNull(card.Connections);
|
||||
Assert.NotEmpty(card.Connections!.Family.Parents);
|
||||
Assert.All(card.Connections.Family.Parents, parent =>
|
||||
{
|
||||
Assert.NotNull(parent.Opinion);
|
||||
Assert.True(parent.Opinion > 0);
|
||||
Assert.False(string.IsNullOrWhiteSpace(parent.OpinionLabel));
|
||||
});
|
||||
|
||||
var linkedIds = card.Connections.Others.Select(row => row.Id).ToHashSet(StringComparer.Ordinal);
|
||||
foreach (var other in card.Connections.Friends.Concat(card.Connections.Enemies))
|
||||
{
|
||||
Assert.DoesNotContain(other.Id, linkedIds);
|
||||
}
|
||||
|
||||
using var bulk = await client.GetAsync($"/api/schools/{school.Id}/people/opinions", TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.NotFound, bulk.StatusCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phases 7 and 9 together: the roster survives a restart, and what comes back is the
|
||||
/// composition *after* the first-September intake. Generating from the seed again would
|
||||
@@ -320,7 +350,8 @@ public class PeopleApiTests(AppHostFixture fixture)
|
||||
IReadOnlyList<LabeledStatResponse> Skills,
|
||||
IReadOnlyList<DefLabelResponse> Traits,
|
||||
IReadOnlyList<NeedStatResponse> Needs,
|
||||
PersonFamilyResponse Family);
|
||||
PersonFamilyResponse Family,
|
||||
PersonConnectionsResponse? Connections);
|
||||
|
||||
private sealed record LabeledStatResponse(string Id, string Label, string Value);
|
||||
|
||||
@@ -332,7 +363,25 @@ public class PeopleApiTests(AppHostFixture fixture)
|
||||
IReadOnlyList<PersonRelResponse> Siblings,
|
||||
IReadOnlyList<PersonRelResponse> Partners);
|
||||
|
||||
private sealed record PersonRelResponse(string Id, string FullName, bool Female);
|
||||
private sealed record PersonRelResponse(
|
||||
string Id,
|
||||
string FullName,
|
||||
bool Female,
|
||||
int? Opinion = null,
|
||||
string? OpinionLabel = null);
|
||||
|
||||
private sealed record PersonOpinionLinkResponse(
|
||||
string Id,
|
||||
string FullName,
|
||||
bool Female,
|
||||
int Opinion,
|
||||
string OpinionLabel);
|
||||
|
||||
private sealed record PersonConnectionsResponse(
|
||||
PersonFamilyResponse Family,
|
||||
IReadOnlyList<PersonOpinionLinkResponse> Friends,
|
||||
IReadOnlyList<PersonOpinionLinkResponse> Enemies,
|
||||
IReadOnlyList<PersonOpinionLinkResponse> Others);
|
||||
|
||||
private sealed record DirectoryResponse(IReadOnlyList<DirectoryPersonResponse> People);
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -592,26 +592,7 @@ public class SchoolApiTests(AppHostFixture fixture)
|
||||
|
||||
internal static async Task ResetAsync(HttpClient client)
|
||||
{
|
||||
await LoginAsync(client);
|
||||
|
||||
var state = await GetSchoolsAsync(client);
|
||||
|
||||
foreach (var school in state.Schools)
|
||||
{
|
||||
using var response = await client.DeleteAsync($"/api/schools/{school.Id}", TestContext.Current.CancellationToken);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
foreach (var school in state.Others)
|
||||
{
|
||||
using var response = await client.DeleteAsync($"/api/schools/{school.Id}", TestContext.Current.CancellationToken);
|
||||
if (response.StatusCode == HttpStatusCode.Forbidden)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
await WipeAllSavesAsync(client);
|
||||
}
|
||||
|
||||
internal static async Task WipeAllSavesAsync(HttpClient client)
|
||||
@@ -731,7 +712,16 @@ public class SchoolApiTests(AppHostFixture fixture)
|
||||
return payload.Path;
|
||||
}
|
||||
|
||||
private sealed record SchoolSaveFile(string? CountryId, string? ClimatePresetId, string? NativeLanguage, string? Owner);
|
||||
private sealed record SchoolSaveFile(
|
||||
string? CountryId,
|
||||
string? ClimatePresetId,
|
||||
string? NativeLanguage,
|
||||
string? Owner,
|
||||
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
|
||||
{
|
||||
|
||||
@@ -71,6 +71,9 @@ public class SchoolOwnerApiTests(AppHostFixture fixture)
|
||||
{
|
||||
client.Dispose();
|
||||
}
|
||||
|
||||
using var cleanup = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.WipeAllSavesAsync(cleanup);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user