This commit is contained in:
1 parent
e4a81e8974
commit
a3cd57e5d8
7 files changed
+73
-2
No files matched your search
@@ -187,6 +187,45 @@ public sealed class UntisReportCacheServiceTests
|
||||
Assert.Equal(4, handler.Requests.Count); // keine weiteren Anfragen - aus dem Cache bedient
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAbsencesAsync_AlterHistorischerBerichtWirdErsetztUndDanachGecacht()
|
||||
{
|
||||
var day = DateOnly.FromDateTime(DateTime.Today).AddDays(-30);
|
||||
var csv = Encoding.UTF8.GetBytes(
|
||||
"Schüler*innen\tKlasse\tDatum\tFehlstd.\tFehlmin.\tFehltage\r\n" +
|
||||
$"Muster Max\t10c\t{day:dd.MM.yy}\t2\t90\t0\r\n");
|
||||
var schoolyears = "{\"result\":[{\"id\":7,\"name\":\"2026/27\",\"startDate\":20260801,\"endDate\":20270731}]}";
|
||||
var handler = new QueueHandler(
|
||||
Json("{\"result\":{\"sessionId\":\"s\"}}"), Json(schoolyears), Json(schoolyears),
|
||||
Json("{\"result\":[{\"id\":874,\"name\":\"10c\"}]}"),
|
||||
Json("{\"data\":{\"finished\":true,\"error\":false,\"reportParams\":\"get=rpt.tmp&name=AbsencePerStudent&format=csv\"}}"),
|
||||
new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(csv) },
|
||||
Json("{\"result\":{}}"));
|
||||
await using var untis = new WebUntisIntegrationService(new HttpClient(handler), TestSupport.BuildWebUntisSettingsService());
|
||||
await untis.ConnectAsync(new WebUntisCredentials("bk-ostvest", "arche.webuntis.com", "lehrkraft", "geheim"));
|
||||
var absences = new FakeUntisAbsenceCache();
|
||||
absences.InsertRange([new UntisAbsenceCacheEntry
|
||||
{
|
||||
ClassName = "10c", StudentName = "Muster Max", Date = Int(day),
|
||||
AbsentPeriods = 2, CountsAsFullDay = true,
|
||||
}]);
|
||||
var states = new FakeUntisCacheFetchStates();
|
||||
states.Save(new UntisCacheFetchState
|
||||
{
|
||||
ClassName = "10c", Kind = UntisCacheKind.Absences,
|
||||
HotWindowFetchedAt = DateTime.UtcNow, ColdCoverageStartDate = Int(day),
|
||||
});
|
||||
var cache = new UntisReportCacheService(untis, absences, new FakeUntisClassRegisterCache(),
|
||||
new FakeUntisStudentRosterCache(), states);
|
||||
|
||||
var first = Assert.Single(await cache.GetAbsencesAsync("10c", day, day));
|
||||
Assert.False(first.CountsAsFullDay);
|
||||
Assert.Equal(2, first.AbsentPeriods);
|
||||
var requestCount = handler.Requests.Count;
|
||||
Assert.False(Assert.Single(await cache.GetAbsencesAsync("10c", day, day)).CountsAsFullDay);
|
||||
Assert.Equal(requestCount, handler.Requests.Count);
|
||||
}
|
||||
|
||||
private static HttpResponseMessage Json(string json) => new(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent(json, Encoding.UTF8, "application/json"),
|
||||
|
||||
Reference in new issue
Block a user