Files
Schulcloud-MCP/test/etherpad.test.ts
MechaCat02 521c21f7ae Reach tasks attached to topics, and read Etherpad pads
Testing against a local instance turned up four things the server was
getting wrong, all of them invisible against the live account because the
data that exposes them had never been produced there.

`GET /lessons/{id}/tasks` returns a bare array, not the `{data,total}`
envelope every sibling endpoint uses, so `.data` was undefined and a
topic's tasks silently vanished. Its items also carry no id at all —
`LessonLinkedTaskResponse` has no id property — which leaves a
topic-attached task unidentifiable: it is not a task element on the
course page, and once past due it is in neither task list. So its
submission, and its grade, could not be reached by any route. That is 18
of 60 tasks on the real account, now reachable: the ids come off the
legacy topic page, where each task is linked as `/homework/{id}`.

The types said `id: string` and `status: TaskStatus` on something that
has neither, which is what let this stay quiet; `LessonLinkedTask` and
`ResolvedTask` now say what is actually there.

Collaborative text editor elements come back with `content: {}`, and the
tool said their contents were unavailable. They are available: the
content-element endpoint returns the pad url *and* an Etherpad session
cookie, and the pad exports itself as text to whoever holds it. No API
key needed. Pads are now shown by get_board and indexed for search.

The store's file digest covered id and size on the grounds that file
records are immutable. `PATCH /file/rename/{id}` renames one in place,
so a rename was reported as nothing at all.

Finally, get_board reported an unpublished board as "no permission",
which sends the reader hunting for an access problem that is not there.

smoke gains checks for topic tasks and for pads, and no longer assumes a
populated index or a search term that happens to match. 39/39 live-only
and 41/41 index-backed, against both the live instance and a local one.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-13 15:39:51 +02:00

40 lines
1.6 KiB
TypeScript

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { padIdFromUrl } from '../src/core/etherpad.ts';
const BASE = 'https://schulcloud.example.org';
describe('padIdFromUrl', () => {
it('takes the pad id out of the url the server hands back', () => {
assert.equal(padIdFromUrl(`${BASE}/etherpad/p/g.abc123$65f0e1d2c3b4a5968778695a`, BASE), 'g.abc123$65f0e1d2c3b4a5968778695a');
});
it('keeps the id exactly as encoded', () => {
// Group pad ids contain `$`. Decoding or re-encoding the segment produces
// an id Etherpad does not recognise.
assert.equal(padIdFromUrl(`${BASE}/etherpad/p/g.x%24y`, BASE), 'g.x%24y');
});
it('refuses a url pointing at another host', () => {
// The caller sends an Etherpad session cookie to whatever this returns, and
// the url comes from server configuration — so a mismatch must not be
// followed rather than trusted.
assert.equal(padIdFromUrl('https://evil.test/etherpad/p/g.abc$123', BASE), undefined);
});
it('accepts a differing port only when it matches', () => {
assert.equal(padIdFromUrl('http://localhost:4400/etherpad/p/pad1', 'http://localhost:4400'), 'pad1');
assert.equal(padIdFromUrl('http://localhost:9001/etherpad/p/pad1', 'http://localhost:4400'), undefined);
});
it('gives up on a url that is not a pad url', () => {
assert.equal(padIdFromUrl(`${BASE}/dashboard`, BASE), undefined);
assert.equal(padIdFromUrl(`${BASE}/etherpad/p/`, BASE), undefined);
});
it('gives up rather than throwing on something that is not a url', () => {
assert.equal(padIdFromUrl('not a url', BASE), undefined);
assert.equal(padIdFromUrl('', BASE), undefined);
});
});