306886a42b
Auth (Test-Mode):
- middleware.AuthMiddleware now takes a devMode flag. In dev,
requests without Authorization fall back to a deterministic dev
UUID (00000000-...-001) and role=teacher. ENVIRONMENT=production
re-enables the strict 401 path.
- main.go wires devMode = cfg.Environment != "production".
- page.tsx replaces the red 'Anmeldung noch nicht integriert' banner
with a softer Testumgebung notice; the manual-token form moves
behind a nested details block.
Export endpoints (school-service):
- LoadExportLessons joins tt_lesson with tt_period for wall-clock
times; one query feeds both CSV and ICS.
- WriteCSV streams 10 columns including pinned flag.
- WriteICS emits one VEVENT per lesson anchored to a Monday — caller
overridable via ?start=YYYY-MM-DD. RFC 5545 escapes for ',', ';',
'\n' in icsEscape().
- NextMonday helper for the default anchor.
- GET /timetable/solutions/:id/export.{csv,ics} handlers attach
Content-Disposition: attachment so browsers download instead of
rendering.
Frontend:
- lib/stundenplan/api.ts downloadSolutionExport() fetches as blob,
triggers a synthetic <a download> click, and forwards the JWT when
present.
- PlanView gains CSV / ICS / Drucken buttons next to the perspective
selector. The toolbar carries class 'no-print' so window.print()
yields only the grid.
- globals.css @media print rule hides chrome, forces white
background, gives the table proper borders for A4.
Docs:
- docs-src/services/stundenplan/{index,architecture,constraints,
solver-tuning,export}.md with nav entry in mkdocs.yml under
Services → Stundenplaner.
- sbom/stundenplan/README.md lists manually-verified key dependencies
and the policy reference. scripts/stundenplan-sbom.sh generates
full machine-readable inventories via go-licenses + pip-licenses
+ license-checker when those tools are available.
Tests:
- internal/services/timetable_exports_test.go: 4 unit tests covering
CSV column layout + quoting, ICS structure + DTSTART formatting,
icsEscape special chars, NextMonday weekday math.
- studio-v2/e2e/stundenplan-export.spec.ts split out of the main spec
file (LOC budget) — 3 tests for button render, CSV download,
ICS download.
- mockSchoolApi extended with export.csv + export.ics routes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
157 lines
5.9 KiB
TypeScript
157 lines
5.9 KiB
TypeScript
import { Page } from '@playwright/test'
|
|
|
|
/**
|
|
* Shared mock helper for the /stundenplan suite. Intercepts every endpoint
|
|
* the school-service proxy serves so tests stay hermetic.
|
|
*/
|
|
|
|
export const MOCK_TEACHER_ID = '11111111-1111-1111-1111-111111111111'
|
|
export const MOCK_SUBJECT_ID = '22222222-2222-2222-2222-222222222222'
|
|
export const MOCK_CLASS_ID = '33333333-3333-3333-3333-333333333333'
|
|
|
|
export interface MockClass {
|
|
id: string
|
|
name: string
|
|
grade_level: number
|
|
student_count: number
|
|
notes?: string
|
|
created_by_user_id: string
|
|
created_at: string
|
|
}
|
|
|
|
export interface MockOpts {
|
|
classes?: MockClass[]
|
|
teachers?: unknown[]
|
|
subjects?: unknown[]
|
|
rooms?: unknown[]
|
|
periods?: unknown[]
|
|
curriculum?: unknown[]
|
|
assignments?: unknown[]
|
|
solutions?: unknown[]
|
|
lessons?: unknown[]
|
|
}
|
|
|
|
export async function mockSchoolApi(page: Page, opts: MockOpts = {}) {
|
|
const classes = opts.classes ?? []
|
|
const teachers = opts.teachers ?? []
|
|
const subjects = opts.subjects ?? []
|
|
const rooms = opts.rooms ?? []
|
|
const periods = opts.periods ?? []
|
|
const curriculum = opts.curriculum ?? []
|
|
const assignments = opts.assignments ?? []
|
|
const solutions = opts.solutions ?? []
|
|
const lessons = opts.lessons ?? []
|
|
|
|
await page.route('**/api/school/timetable/classes', async (route) => {
|
|
if (route.request().method() === 'GET') {
|
|
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(classes) })
|
|
}
|
|
if (route.request().method() === 'POST') {
|
|
const body = JSON.parse(route.request().postData() || '{}')
|
|
const created: MockClass = {
|
|
id: 'new-class-id',
|
|
name: body.name,
|
|
grade_level: body.grade_level,
|
|
student_count: body.student_count ?? 0,
|
|
notes: body.notes,
|
|
created_by_user_id: 'test-user',
|
|
created_at: new Date().toISOString(),
|
|
}
|
|
classes.push(created)
|
|
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify(created) })
|
|
}
|
|
return route.fulfill({ status: 405 })
|
|
})
|
|
|
|
const staticList = (path: string, data: unknown) =>
|
|
page.route(`**/api/school/timetable/${path}`, async (route) =>
|
|
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(data) }))
|
|
|
|
await staticList('teachers', teachers)
|
|
await staticList('subjects', subjects)
|
|
await staticList('rooms', rooms)
|
|
await staticList('periods', periods)
|
|
await staticList('curriculum', curriculum)
|
|
await staticList('assignments', assignments)
|
|
|
|
for (const path of [
|
|
'constraints/teacher/unavailable-day',
|
|
'constraints/teacher/unavailable-window',
|
|
'constraints/teacher/max-hours-day',
|
|
'constraints/teacher/max-hours-week',
|
|
'constraints/teacher/excluded-subject',
|
|
'constraints/teacher/excluded-room',
|
|
'constraints/subject/max-consecutive',
|
|
'constraints/subject/preferred-period',
|
|
'constraints/subject/min-day-gap',
|
|
'constraints/subject/contiguous-when-repeated',
|
|
'constraints/subject/double-lesson',
|
|
'constraints/class/max-hours-day',
|
|
'constraints/class/no-gaps',
|
|
'constraints/room/requires-type',
|
|
'constraints/room/unavailable',
|
|
]) {
|
|
await staticList(path, [])
|
|
}
|
|
|
|
await page.route('**/api/school/timetable/solutions', async (route) => {
|
|
if (route.request().method() === 'GET') {
|
|
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(solutions) })
|
|
}
|
|
if (route.request().method() === 'POST') {
|
|
const body = JSON.parse(route.request().postData() || '{}')
|
|
const created = {
|
|
id: 'new-solution-id',
|
|
created_by_user_id: 'test-user',
|
|
name: body.name || 'Plan',
|
|
status: 'pending',
|
|
hard_score: null,
|
|
soft_score: null,
|
|
created_at: new Date().toISOString(),
|
|
}
|
|
;(solutions as unknown[]).push(created)
|
|
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify(created) })
|
|
}
|
|
return route.fulfill({ status: 405 })
|
|
})
|
|
|
|
await page.route(/\/api\/school\/timetable\/solutions\/[^/]+\/lessons$/, async (route) => {
|
|
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(lessons) })
|
|
})
|
|
|
|
// Phase 7: lesson-level pin toggle.
|
|
await page.route(/\/api\/school\/timetable\/lessons\/[^/]+\/pin$/, async (route) => {
|
|
if (route.request().method() !== 'PUT') return route.fulfill({ status: 405 })
|
|
const body = JSON.parse(route.request().postData() || '{}')
|
|
return route.fulfill({
|
|
status: 200, contentType: 'application/json',
|
|
body: JSON.stringify({ message: 'ok', pinned: body.pinned ?? false }),
|
|
})
|
|
})
|
|
// Phase 8: CSV + ICS exports. Routed BEFORE the generic /solutions/:id
|
|
// catch-all so the .csv / .ics suffix path is matched first.
|
|
await page.route(/\/api\/school\/timetable\/solutions\/[^/]+\/export\.csv$/, async (route) => {
|
|
return route.fulfill({
|
|
status: 200, contentType: 'text/csv',
|
|
body: 'day_of_week,period_index,start_time,end_time,class,subject,subject_code,teacher,room,pinned\n1,1,08:00,08:45,5a,Mathe,M,"Schmidt, Anna",A101,false\n',
|
|
})
|
|
})
|
|
await page.route(/\/api\/school\/timetable\/solutions\/[^/]+\/export\.ics(\?.*)?$/, async (route) => {
|
|
return route.fulfill({
|
|
status: 200, contentType: 'text/calendar',
|
|
body: 'BEGIN:VCALENDAR\r\nVERSION:2.0\r\nEND:VCALENDAR\r\n',
|
|
})
|
|
})
|
|
|
|
await page.route(/\/api\/school\/timetable\/solutions\/[^/]+$/, async (route) => {
|
|
if (route.request().method() === 'DELETE') {
|
|
return route.fulfill({ status: 200, contentType: 'application/json', body: '{"message":"deleted"}' })
|
|
}
|
|
const url = route.request().url()
|
|
const id = url.split('/').pop() ?? ''
|
|
const sol = (solutions as Array<{ id: string }>).find(s => s.id === id)
|
|
if (!sol) return route.fulfill({ status: 404 })
|
|
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(sol) })
|
|
})
|
|
}
|