Class share links: visitors choose the exam for a generated set
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 24s

On a class link with exams, the visitor's Generate dialog asks which exam the
set is for (opening on the latest exam with materials, with "Not in an exam"
when there is loose material). Only that exam's class materials are offered,
and the set is saved into it. The server requires the choice and refuses
materials from another exam.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-15 22:13:11 -07:00
parent 76112cb4ae
commit d8df5edf30
4 changed files with 98 additions and 9 deletions

View file

@ -277,3 +277,40 @@ describe('share-link visitors can generate', () => {
expect(draft.meta.request).toMatchObject({ count: 50, sataShare: 0.25, format: 'exam' });
});
});
describe('class links: visitors choose the exam', () => {
beforeEach(async () => {
const { resetShareAiLimits } = await import('../server/routes/shares.ts');
resetShareAiLimits();
});
it('requires an exam, uses only its materials and saves the set into it', async () => {
await connectAi();
const cls = (await t.api('POST', '/api/classes', { name: 'Med-Surg' })).body.class;
const exam1 = (await t.api('POST', `/api/classes/${cls.id}/folders`, { name: 'Exam 1' })).body.folder;
const exam2 = (await t.api('POST', `/api/classes/${cls.id}/folders`, { name: 'Exam 2' })).body.folder;
const cardiac = (await t.api('POST', '/api/documents/text', { classId: cls.id, folderId: exam1.id, title: 'Cardiac', text: '# Cardiac\n\nDigoxin toxicity causes nausea and visual halos.' })).body.document;
await t.api('POST', '/api/documents/text', { classId: cls.id, folderId: exam2.id, title: 'Renal', text: '# Renal\n\nHyperkalemia in kidney failure shows peaked T waves. Kayexalate removes potassium.' });
await queueIdle(t.ctx);
const share = (await t.api('POST', '/api/shares', { kind: 'class', targetId: cls.id })).body.share;
await t.api('PATCH', `/api/shares/${share.id}`, { ai: { generate: true } });
const token = share.token;
const missing = await t.api('POST', `/api/public/${token}/generate`, { kind: 'deck', count: 3 });
expect(missing.status).toBe(400);
expect(missing.body.error.message).toContain('Choose which exam');
// Materials from another exam are refused.
expect((await t.api('POST', `/api/public/${token}/generate`, { kind: 'deck', count: 3, examId: exam2.id, documentIds: [cardiac.id] })).status).toBe(404);
mock.requests.length = 0;
const res = await t.api('POST', `/api/public/${token}/generate`, { kind: 'deck', count: 3, examId: exam2.id });
expect(res.status).toBe(202);
const draft = await waitDraft(res.body.set.id);
expect(draft.status).toBe('saved');
const deck = (await t.api('GET', `/api/decks/${draft.savedId}`)).body.deck;
expect(deck.folderId).toBe(exam2.id);
const sent = JSON.stringify(chatCalls().map((r) => r.body.messages));
expect(sent).toContain('Kayexalate');
expect(sent).not.toContain('Digoxin');
});
});