Share-link sets save into the class; flashcards up to 75
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 28s

- Sets visitors generate show in the owner's Drafts while being written, then
  save into the class (and exam, for an exam link) automatically, as if
  approved. If the save fails, the draft waits in Drafts for review.
- Deleting a share link keeps what was made on it; running jobs finish and save.
- Visitor flashcard sets go up to 75 cards (default 30); quizzes stay at 50.
- The visitor page links finished sets to the class items; the separate
  AI-set view is gone.

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

View file

@ -197,41 +197,50 @@ describe('share-link visitors can generate', () => {
throw new Error('generation did not finish');
}
it('is off until the owner allows it, then makes quizzes and flashcards within daily limits', async () => {
it('is off until the owner allows it, then adds quizzes and flashcards to the class within daily limits', async () => {
await connectAi();
const { cls, doc } = await classWithMaterial();
const share = (await t.api('POST', '/api/shares', { kind: 'class', targetId: cls.id })).body.share;
const exam = (await t.api('POST', `/api/classes/${cls.id}/folders`, { name: 'Exam 1' })).body.folder;
await t.api('PATCH', `/api/documents/${doc.id}`, { folderId: exam.id });
const share = (await t.api('POST', '/api/shares', { kind: 'folder', targetId: exam.id })).body.share;
const token = share.token;
expect((await t.api('POST', `/api/public/${token}/generate`, { kind: 'quiz', count: 4 })).status).toBe(403);
await t.api('PATCH', `/api/shares/${share.id}`, { ai: { generate: true, explain: true } });
expect((await t.api('GET', `/api/public/${token}`)).body.ai.generate).toBe(true);
// At most 50 questions, materials from the link only.
expect((await t.api('POST', `/api/public/${token}/generate`, { kind: 'quiz', count: 51 })).status).toBe(422);
// At most 50 questions or 75 cards, materials from the link only.
expect((await t.api('POST', `/api/public/${token}/generate`, { kind: 'quiz', count: 51 })).status).toBe(400);
expect((await t.api('POST', `/api/public/${token}/generate`, { kind: 'deck', count: 76 })).status).toBe(422);
expect((await t.api('POST', `/api/public/${token}/generate`, { kind: 'quiz', documentIds: ['not-shared'] })).status).toBe(404);
mock.requests.length = 0;
mock.delayChat(150);
const first = await t.api('POST', `/api/public/${token}/generate`, { kind: 'quiz', count: 8, difficulty: 'hard', documentIds: [doc.id], math: true });
expect(first.status).toBe(202);
expect(first.body.usage.quiz).toEqual({ used: 1, limit: 4 });
// In the owner's drafts while it is being written.
expect((await t.api('GET', '/api/drafts')).body.drafts.find((d: any) => d.id === first.body.set.id)?.status).toBe('generating');
mock.delayChat(0);
const [set] = await waitSets(token);
expect(set).toMatchObject({ kind: 'quiz', status: 'ready', count: 8 });
const quiz = (await t.api('GET', `/api/public/${token}/items/ai/${set.id}`)).body;
expect(quiz.kind).toBe('quiz');
expect(set.itemId).toBeTruthy();
// Saved into the exam as if the owner made it, and gone from Drafts.
expect((await t.api('GET', '/api/drafts')).body.drafts.some((d: any) => d.id === set.id)).toBe(false);
const saved = (await t.api('GET', `/api/quizzes/${set.itemId}`)).body;
expect(saved.quiz.folderId).toBe(exam.id);
expect(saved.quiz.description).toBe('Made with AI on a share link.');
const shown = (await t.api('GET', `/api/public/${token}`)).body.items.map((i: any) => i.id);
expect(shown).toContain(set.itemId);
const quiz = (await t.api('GET', `/api/public/${token}/items/quiz/${set.itemId}`)).body;
expect(quiz.questions.filter((q: any) => q.type === 'numeric')).toHaveLength(5);
expect(quiz.questions[0].id).toBe('q1');
const sent = JSON.stringify(chatCalls().map((r) => r.body.messages));
expect(sent).toContain('Difficulty: hard');
expect(sent).toMatch(/Exactly 1 of them must be select-all-that-apply/);
// Explain works on a generated question.
const explained = await t.raw('POST', `/api/public/${token}/explain`, { headers: { 'content-type': 'application/json' }, body: JSON.stringify({ kind: 'question', quizId: set.id, questionId: 'q1' }) });
const explained = await t.raw('POST', `/api/public/${token}/explain`, { headers: { 'content-type': 'application/json' }, body: JSON.stringify({ kind: 'question', quizId: set.itemId, questionId: quiz.questions[0].id }) });
expect(explained.status).toBe(200);
// The owner's drafts list does not show visitors' sets; the share settings do.
expect((await t.api('GET', '/api/drafts')).body.drafts.some((d: any) => d.id === set.id)).toBe(false);
const listed = (await t.api('GET', '/api/shares')).body.shares.find((s: any) => s.id === share.id);
expect(listed.generated.sets.map((s: any) => s.id)).toEqual([set.id]);
expect(listed.generated.sets.map((s: any) => s.itemId)).toEqual([set.itemId]);
// Four quizzes and two flashcard sets a day.
for (let i = 0; i < 3; i += 1) expect((await t.api('POST', `/api/public/${token}/generate`, { kind: 'quiz', count: 2 })).status).toBe(202);
@ -245,8 +254,16 @@ describe('share-link visitors can generate', () => {
// The owner resets the allowance.
const reset = await t.api('POST', `/api/shares/${share.id}/generate/reset`);
expect(reset.body.generated.usage.quiz.used).toBe(0);
expect((await t.api('POST', `/api/public/${token}/generate`, { kind: 'quiz', count: 2 })).status).toBe(202);
await waitSets(token);
// Deleting the link keeps everything made on it, including a set still being written.
mock.delayChat(150);
const running = (await t.api('POST', `/api/public/${token}/generate`, { kind: 'deck', count: 3 })).body.set;
expect((await t.api('DELETE', `/api/shares/${share.id}`)).status).toBe(200);
mock.delayChat(0);
const finished = await waitDraft(running.id);
expect(finished.status).toBe('saved');
expect((await t.api('GET', `/api/decks/${finished.savedId}`)).status).toBe(200);
expect((await t.api('GET', `/api/quizzes/${set.itemId}`)).status).toBe(200);
});
it('defaults to a 50-question quiz', async () => {