feat(git): Teilen per Snapshot – snapshotAt im Git-Status, Anzeige im Editor, Tests für alle Leser-Routen (ADR 0003 §6)
CI / Storage (mongo) (pull_request) Failing after 1m13s
CI / Storage (postgres) (pull_request) Successful in 1m12s
CI / App (npm ci + Build, ESLint, Stylelint, Jest) (pull_request) Successful in 2m9s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dev-bot BotandClaude Sonnet 5.5 committed 2026-11-25 21:32:14 +00:00
1 parent 448c67912f
commit 3e05096fd6
5 files changed
+81 -3

No files matched your search

+51
View File
@@ -151,6 +151,57 @@ for (const { driver, url } of backends) {
expect(await storage.getStorage().brewGitLinks.findByBrewId(created.body.id)).toBeNull();
});
test('Teilen: alle Leser-Routen ohne Anmeldung und ohne Git, Snapshot-Zeit steigt, normale Brews unberührt', async ()=>{
const { url: repoUrl } = remote.createRepo('share.git');
const conn = await api('post', '/api/git/connections').send({ label: 'Privat', repoUrl, authUsername: remote.username, token: remote.token });
const created = await api('post', '/api/git/brews').send({ connectionId: conn.body.id, path: 'brews/share.md', brew: { title: 'Geteilt', text: '```css\n.snap { color: red; }\n```\n\nSnapshot Eins', renderer: 'V3' } });
expect(created.status).toBe(200);
const { editId, shareId } = created.body;
const plain = await api('post', '/api').send({ title: 'Normal', text: 'Ohne Git', renderer: 'V3' });
expect(plain.status).toBe(200);
const readerRoutes = (id)=>[`/share/${id}`, `/api/fetch/${id}`, `/metadata/${id}`, `/source/${id}`, `/download/${id}`, `/css/${id}`];
const readAll = async (id)=>{
const out = {};
for (const route of readerRoutes(id)) {
const res = await request.get(route); // bewusst ohne Cookie: Leser ohne Konto
expect([route, res.status]).toEqual([route, 200]);
out[route] = res;
const body = `${res.text ?? ''}${JSON.stringify(res.body ?? {})}`;
expect(body).not.toContain(remote.token);
expect(body).not.toContain(repoUrl);
expect(body).not.toContain('brews/share.md');
}
return out;
};
remote.setHang(true); // Git nicht erreichbar → Share darf nicht davon abhängen
let before;
try { before = await readAll(shareId); } finally { remote.setHang(false); }
expect(before[`/source/${shareId}`].text).toContain('Snapshot Eins');
expect(before[`/download/${shareId}`].text).toContain('Snapshot Eins');
const t1 = new Date(JSON.parse(before[`/metadata/${shareId}`].text ?? JSON.stringify(before[`/metadata/${shareId}`].body)).updatedAt);
// Jedes erfolgreiche Speichern aktualisiert den Snapshot und seinen Zeitpunkt
await new Promise((r)=>setTimeout(r, 20));
expect((await save(editId, 'Snapshot Zwei')).status).toBe(200);
remote.setHang(true);
let after;
try { after = await readAll(shareId); } finally { remote.setHang(false); }
expect(after[`/source/${shareId}`].text).toContain('Snapshot Zwei');
const t2 = new Date(after[`/metadata/${shareId}`].body.updatedAt);
expect(t2.getTime()).toBeGreaterThan(t1.getTime());
const st = await api('get', `/api/git/brews/${editId}`);
expect(new Date(st.body.snapshotAt).getTime()).toBe(t2.getTime());
// Normaler Brew: gleiche Routen, kein Git-Feld
const normal = await request.get(`/api/fetch/${plain.body.shareId}`);
expect(normal.status).toBe(200);
expect(normal.body.brew.text).toContain('Ohne Git');
expect((await request.get(`/source/${plain.body.shareId}`)).text).toContain('Ohne Git');
expect((await api('get', `/api/git/brews/${plain.body.editId}`)).body).toEqual({ linked: false });
});
test('Konten ohne uid (nicht angemeldet) bekommen 403 G07', async ()=>{
const res = await request.get('/api/git/connections').set(version);
expect([res.status, res.body.HBErrorCode]).toEqual([403, 'G07']);