Add speech-topic policy from tomorrow and a morning family talk.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace HSchool.AppHost.Tests;
|
||||
|
||||
[Collection(AppHostCollection.Name)]
|
||||
public class SpeechRulesApiTests(AppHostFixture fixture)
|
||||
{
|
||||
private static readonly DateTime Start = new(2012, 4, 3, 6, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
[Fact]
|
||||
public async Task NewSchool_DefaultSpeech_IsFree()
|
||||
{
|
||||
using var client = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.ResetAsync(client);
|
||||
var school = await SchoolApiTests.CreateAsync(client, "Речь дефолт", Start, seed: 46);
|
||||
|
||||
var response = await client.GetAsync($"/api/schools/{school.Id}/speech-rules", TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
var rules = await response.Content.ReadFromJsonAsync<SpeechRulesDto>(TestContext.Current.CancellationToken);
|
||||
Assert.NotNull(rules);
|
||||
Assert.Equal("free", rules.Students);
|
||||
Assert.Equal("free", rules.Staff);
|
||||
Assert.Null(rules.PendingStudents);
|
||||
Assert.Null(rules.PendingStaff);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostStudyOnlyToday_QueuesPending_LeavesLiveFree()
|
||||
{
|
||||
using var client = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.ResetAsync(client);
|
||||
var school = await SchoolApiTests.CreateAsync(client, "Речь завтра", Start, seed: 46);
|
||||
|
||||
var post = await client.PostAsJsonAsync(
|
||||
$"/api/schools/{school.Id}/speech-rules",
|
||||
new { students = "studyOnly" },
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.OK, post.StatusCode);
|
||||
var queued = await post.Content.ReadFromJsonAsync<SpeechRulesDto>(TestContext.Current.CancellationToken);
|
||||
Assert.NotNull(queued);
|
||||
Assert.Equal("free", queued.Students);
|
||||
Assert.Equal("studyOnly", queued.PendingStudents);
|
||||
|
||||
var get = await client.GetFromJsonAsync<SpeechRulesDto>(
|
||||
$"/api/schools/{school.Id}/speech-rules",
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.NotNull(get);
|
||||
Assert.Equal("free", get.Students);
|
||||
Assert.Equal("studyOnly", get.PendingStudents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnknownPolicy_Returns400()
|
||||
{
|
||||
using var client = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.ResetAsync(client);
|
||||
var school = await SchoolApiTests.CreateAsync(client, "Плохая речь", Start, seed: 46);
|
||||
|
||||
using var response = await client.PostAsJsonAsync(
|
||||
$"/api/schools/{school.Id}/speech-rules",
|
||||
new { students = "silence" },
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
Assert.Equal("unknown-speech", await SchoolApiTests.ProblemCodeAsync(response));
|
||||
}
|
||||
|
||||
private sealed record SpeechRulesDto(
|
||||
string Students,
|
||||
string Staff,
|
||||
string? PendingStudents,
|
||||
string? PendingStaff);
|
||||
}
|
||||
Reference in New Issue
Block a user