mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
Add a Quiz Questions content page (list/filter/create/edit/activate- deactivate, no delete since quiz_answers reference questions by id), route it under manage_questions, and add a sidebar entry. Fix DaresPage so intensity (1-5) is editable and shown in the table; previously every admin-created dare silently defaulted to intensity 1. Add authored min/max intensity fields to DarePacksPage: no trigger or worker in apps/api computes these columns, so they are admin-set thresholds gating pack visibility, not derived aggregates. avg_intensity is displayed read-only since nothing writes to it and it is not used for filtering. Extract dare intensity and quiz option validation into small lib modules with focused unit tests.
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { sanitizeQuizOptions, validateQuizQuestionForm } from './quizQuestions';
|
|
|
|
describe('sanitizeQuizOptions', () => {
|
|
it('trims and drops empty options', () => {
|
|
expect(sanitizeQuizOptions([' A ', '', ' ', 'B'])).toEqual(['A', 'B']);
|
|
});
|
|
});
|
|
|
|
describe('validateQuizQuestionForm', () => {
|
|
const base = {
|
|
prompt_self: 'What is your favourite season?',
|
|
prompt_guess: "What is your partner's favourite season?",
|
|
options: ['Spring', 'Summer'],
|
|
};
|
|
|
|
it('accepts a valid form', () => {
|
|
expect(validateQuizQuestionForm(base)).toBeNull();
|
|
});
|
|
|
|
it('requires the self prompt', () => {
|
|
expect(validateQuizQuestionForm({ ...base, prompt_self: ' ' })).toMatch(/about yourself/);
|
|
});
|
|
|
|
it('requires the guess prompt', () => {
|
|
expect(validateQuizQuestionForm({ ...base, prompt_guess: '' })).toMatch(/about your partner/);
|
|
});
|
|
|
|
it('requires at least two options', () => {
|
|
expect(validateQuizQuestionForm({ ...base, options: ['Only one'] })).toMatch(/At least 2 options/);
|
|
});
|
|
|
|
it('allows at most four options', () => {
|
|
expect(validateQuizQuestionForm({ ...base, options: ['A', 'B', 'C', 'D', 'E'] })).toMatch(/At most 4 options/);
|
|
});
|
|
|
|
it('ignores blank options when counting', () => {
|
|
expect(validateQuizQuestionForm({ ...base, options: ['Spring', 'Summer', '', ''] })).toBeNull();
|
|
});
|
|
});
|