WIP (unstable): WebUntis-iCal-Abgleich für Vertretungen/Ausfälle

Erkennt Vertretungen, Ausfälle und Zusatzaufsichten aus dem persönlichen
WebUntis-iCal-Feed und schreibt sie automatisch als SubstitutionEntry.
Bekannter offener Bug: es tauchen weiterhin falsche Vertretungen für
Stunden auf, die real unverändert sind — wird in einem Folge-Commit
untersucht, deshalb vorerst auf diesem Branch statt main.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-23 13:30:15 +02:00
co-authored by Claude Sonnet 5
parent e65a729f97
commit 4eb4d0a946
30 changed files with 3333 additions and 8 deletions
@@ -0,0 +1,89 @@
using LehrerApp.Desktop.Services;
using Xunit;
namespace LehrerApp.Desktop.Tests;
public sealed class WebUntisSettingsServiceTests
{
private const string SampleUrl = "https://example.webuntis.com/WebUntis/ical_export?school=example&id=test&elemId=1&token=geheim";
private static string BuildTempPath()
{
var path = Path.Combine(Path.GetTempPath(), $"lehrerapp-webuntissettingssvc-tests-{Guid.NewGuid():N}");
Directory.CreateDirectory(path);
return path;
}
[Fact]
public void SetEnabled_PersistiertUeberNeueInstanz()
{
var path = BuildTempPath();
new WebUntisSettingsService(path).SetEnabled(true);
var reloaded = new WebUntisSettingsService(path);
Assert.True(reloaded.Enabled);
}
[Fact]
public void SetIcalUrl_IstVerschluesseltAbrufbar()
{
var service = new WebUntisSettingsService(BuildTempPath());
service.SetIcalUrl(SampleUrl);
Assert.True(service.IsConfigured);
Assert.Equal(SampleUrl, service.GetIcalUrl());
}
[Fact]
public void IcalUrl_UeberlebtNeueInstanzMitDemselbenPfad()
{
var path = BuildTempPath();
new WebUntisSettingsService(path).SetIcalUrl(SampleUrl);
var reloaded = new WebUntisSettingsService(path);
Assert.True(reloaded.IsConfigured);
Assert.Equal(SampleUrl, reloaded.GetIcalUrl());
}
[Fact]
public void KonfigurationsdateiEnthaeltNichtDasTokenImKlartext()
{
var path = BuildTempPath();
var service = new WebUntisSettingsService(path);
service.SetIcalUrl(SampleUrl);
var raw = File.ReadAllText(Path.Combine(path, "webuntis-settings.json"));
Assert.DoesNotContain("token=geheim", raw);
}
[Fact]
public void ClearIcalUrl_EntferntUrlUndDeaktiviert()
{
var service = new WebUntisSettingsService(BuildTempPath());
service.SetIcalUrl(SampleUrl);
service.SetEnabled(true);
service.ClearIcalUrl();
Assert.False(service.IsConfigured);
Assert.Null(service.GetIcalUrl());
Assert.False(service.Enabled);
}
[Fact]
public void SetLastSync_PersistiertZeitstempelUndStatus()
{
var path = BuildTempPath();
var at = new DateTime(2026, 8, 22, 12, 0, 0, DateTimeKind.Utc);
new WebUntisSettingsService(path).SetLastSync(at, "3 Vertretungen erkannt");
var reloaded = new WebUntisSettingsService(path);
Assert.Equal(at, reloaded.LastSyncAt);
Assert.Equal("3 Vertretungen erkannt", reloaded.LastSyncStatus);
}
}