Bundles the prior autonomous-session output that was sitting unstaged: - Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances) - country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk after the per-subpath dynamic-import approach silently failed in webpack) - Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index, redirects (ocr to ai, reports to dashboard, invitations to users), docs/admin-ia-proposal.md - Per-template email tester (registry + endpoint + UI on Email admin page) - Cancel-document mode picker (delete-from-Documenso vs keep-for-audit) - Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers - Customize-widgets per-region sortables at xl+ (charts/rails/feed); single flat sortable below xl when the layout stacks; per-viewport saved orders - Audit doc updates capturing each shipped item - Lint fixes: react-compiler immutability in DonutChart (reduce instead of let-reassign), set-state-in-effect disables in CountryFlag and UploadForSigning preview-bytes effect, unused 'confirm' destructures in interest contract + reservation tabs, unescaped apostrophe in test-template card copy
87 lines
3.5 KiB
TypeScript
87 lines
3.5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import {
|
|
createFolderSchema,
|
|
renameFolderSchema,
|
|
moveFolderSchema,
|
|
moveDocumentToFolderSchema,
|
|
} from '@/lib/validators/document-folders';
|
|
import { listDocumentsSchema } from '@/lib/validators/documents';
|
|
|
|
describe('document-folder validators', () => {
|
|
it('accepts a valid create payload', () => {
|
|
expect(createFolderSchema.safeParse({ name: 'Deals', parentId: null }).success).toBe(true);
|
|
expect(createFolderSchema.safeParse({ name: 'Q1', parentId: 'abc-123' }).success).toBe(true);
|
|
});
|
|
|
|
it('rejects empty + over-long names', () => {
|
|
expect(createFolderSchema.safeParse({ name: '', parentId: null }).success).toBe(false);
|
|
expect(createFolderSchema.safeParse({ name: 'x'.repeat(201), parentId: null }).success).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it('rejects whitespace-only names', () => {
|
|
expect(createFolderSchema.safeParse({ name: ' ', parentId: null }).success).toBe(false);
|
|
});
|
|
|
|
it('rename schema requires only name', () => {
|
|
expect(renameFolderSchema.safeParse({ name: 'New' }).success).toBe(true);
|
|
expect(renameFolderSchema.safeParse({ name: '' }).success).toBe(false);
|
|
});
|
|
|
|
it('move schema accepts null parentId', () => {
|
|
expect(moveFolderSchema.safeParse({ parentId: null }).success).toBe(true);
|
|
expect(moveFolderSchema.safeParse({ parentId: 'abc' }).success).toBe(true);
|
|
});
|
|
|
|
it('moveDocumentToFolderSchema accepts null folderId', () => {
|
|
expect(moveDocumentToFolderSchema.safeParse({ folderId: null }).success).toBe(true);
|
|
expect(moveDocumentToFolderSchema.safeParse({ folderId: 'abc' }).success).toBe(true);
|
|
});
|
|
|
|
// ─── folderId='' → null transform (regression) ─────────────────────────────
|
|
//
|
|
// The frontend's URL-query builder emits `?folderId=` (empty string) when
|
|
// the user picks "All documents" - without the transform, Zod would parse
|
|
// this as the literal string "" and the SQL layer would try to JOIN on an
|
|
// empty folder id, returning zero rows instead of the expected unscoped
|
|
// result. The transform lives on `listDocumentsSchema` (and
|
|
// `listFilesSchema`); we exercise the documents one here.
|
|
describe("listDocumentsSchema folderId='' transform", () => {
|
|
const BASE = { page: 1, limit: 20, sort: 'createdAt', order: 'desc', includeArchived: 'false' };
|
|
|
|
it("coerces folderId='' to null so the empty-string query param means 'unscoped'", () => {
|
|
const result = listDocumentsSchema.safeParse({ ...BASE, folderId: '' });
|
|
expect(result.success).toBe(true);
|
|
if (result.success) {
|
|
expect(result.data.folderId).toBeNull();
|
|
}
|
|
});
|
|
|
|
it('leaves a non-empty folderId untouched', () => {
|
|
const id = crypto.randomUUID();
|
|
const result = listDocumentsSchema.safeParse({ ...BASE, folderId: id });
|
|
expect(result.success).toBe(true);
|
|
if (result.success) {
|
|
expect(result.data.folderId).toBe(id);
|
|
}
|
|
});
|
|
|
|
it('accepts an explicit folderId=null (no transform needed)', () => {
|
|
const result = listDocumentsSchema.safeParse({ ...BASE, folderId: null });
|
|
expect(result.success).toBe(true);
|
|
if (result.success) {
|
|
expect(result.data.folderId).toBeNull();
|
|
}
|
|
});
|
|
|
|
it('treats an absent folderId as undefined (not the same as null)', () => {
|
|
const result = listDocumentsSchema.safeParse(BASE);
|
|
expect(result.success).toBe(true);
|
|
if (result.success) {
|
|
expect(result.data.folderId).toBeUndefined();
|
|
}
|
|
});
|
|
});
|
|
});
|