Refine report filtering and date formatting
CI / test (push) Successful in 28s
CI / publish (push) Failing after 1m14s

This commit is contained in:
Joe Julian
2026-03-30 18:05:54 -07:00
parent 86856abda2
commit edb66e3a5a
2 changed files with 200 additions and 23 deletions
+94
View File
@@ -1,6 +1,7 @@
package main
import (
"net/url"
"os"
"strings"
"testing"
@@ -48,6 +49,28 @@ func TestFilterUpcomingAssignments(t *testing.T) {
}
}
func TestFilterMissingAssignmentsHidesRevisionForCurrentA(t *testing.T) {
start := time.Date(2026, 1, 20, 0, 0, 0, 0, time.UTC)
assignments := []Assignment{
{
DueDate: time.Date(2026, 3, 20, 0, 0, 0, 0, time.UTC),
Course: "Geometry Lab",
Title: "Revise me",
Status: "Revision Needed",
},
{
DueDate: time.Date(2026, 3, 21, 0, 0, 0, 0, time.UTC),
Course: "Geometry Lab",
Title: "Still missing",
Status: "Missing",
},
}
got := filterMissingAssignments(assignments, start, map[string]struct{}{"geometry lab": {}})
if len(got) != 1 || got[0].Title != "Still missing" {
t.Fatalf("unexpected filtered assignments: %#v", got)
}
}
func TestDedupeAssignments(t *testing.T) {
assignment := Assignment{
DueDate: time.Date(2026, 4, 1, 0, 0, 0, 0, time.UTC),
@@ -141,6 +164,77 @@ func TestNormalizeSMTPHeloName(t *testing.T) {
}
}
func TestClassesWithCurrentA(t *testing.T) {
got := classesWithCurrentA([]ClassInfo{
{Name: "Geometry Lab", Grade: "A"},
{Name: "Civics", Grade: "B"},
{Name: "Intro. Spanish 1", Grade: "A-"},
})
if !hasCurrentA(got, "Geometry Lab") {
t.Fatal("expected Geometry Lab to have current A")
}
if !hasCurrentA(got, "Intro. Spanish 1") {
t.Fatal("expected Intro. Spanish 1 to have current A")
}
if hasCurrentA(got, "Civics") {
t.Fatal("did not expect Civics to have current A")
}
}
func TestFetchScheduleClasses(t *testing.T) {
doc := mustParseHTML(`
<table class="student-classes current-classes pure-table pure-table-horizontal">
<tbody>
<tr>
<td><a data-track="Class Home Page" href="/class/1?back=/schedule">Geometry Lab</a></td>
<td>S1, S2</td>
<td>-</td>
<td>Teacher</td>
<td>A</td>
<td>Aug 25, 2025</td>
<td>-</td>
</tr>
<tr>
<td><a data-track="Class Home Page" href="/class/2?back=/schedule">Civics</a></td>
<td>S2</td>
<td>-</td>
<td>Teacher</td>
<td>B</td>
<td>Jan 20, 2026</td>
<td>-</td>
</tr>
</tbody>
</table>`)
base, err := url.Parse("https://example.invalid/children/student/schedule")
if err != nil {
t.Fatalf("parse base URL: %v", err)
}
got, err := extractScheduleClasses(doc, base)
if err != nil {
t.Fatalf("extractScheduleClasses returned error: %v", err)
}
if len(got) != 2 {
t.Fatalf("got %d classes", len(got))
}
if got[1].Grade != "A" || got[1].Name != "Geometry Lab" {
t.Fatalf("unexpected classes: %#v", got)
}
}
func TestBuildBodyIncludesWeekday(t *testing.T) {
now := time.Date(2026, 3, 30, 10, 0, 0, 0, time.UTC)
start := time.Date(2026, 1, 20, 0, 0, 0, 0, time.UTC)
body := buildBody([]Assignment{{
DueDate: time.Date(2026, 3, 30, 0, 0, 0, 0, time.UTC),
Course: "Civics",
Title: "Essay",
Status: "Missing",
}}, nil, start, "https://example.invalid/assignments", "https://example.invalid/schedule", now, 14)
if !strings.Contains(body, "Monday 2026-03-30") {
t.Fatalf("body missing weekday date: %s", body)
}
}
func mustParseHTML(text string) *html.Node {
doc, err := html.Parse(strings.NewReader(text))
if err != nil {