2026-05-10 16:53:51 +02:00
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
|
|
|
|
|
|
import { parseImportPath } from '@/lib/services/document-import';
|
|
|
|
|
|
|
|
|
|
describe('parseImportPath', () => {
|
|
|
|
|
it('splits a nested key into folders + filename', () => {
|
|
|
|
|
expect(parseImportPath('legacy', 'legacy/Deals 2026/Q1/contract.pdf')).toEqual({
|
|
|
|
|
folderSegments: ['Deals 2026', 'Q1'],
|
|
|
|
|
filename: 'contract.pdf',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns empty folderSegments for a file at the prefix root', () => {
|
|
|
|
|
expect(parseImportPath('legacy', 'legacy/index.pdf')).toEqual({
|
|
|
|
|
folderSegments: [],
|
|
|
|
|
filename: 'index.pdf',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('tolerates trailing slashes on the prefix', () => {
|
|
|
|
|
expect(parseImportPath('legacy/', 'legacy/Deals/x.pdf')).toEqual({
|
|
|
|
|
folderSegments: ['Deals'],
|
|
|
|
|
filename: 'x.pdf',
|
|
|
|
|
});
|
|
|
|
|
expect(parseImportPath('legacy///', 'legacy/Deals/x.pdf')).toEqual({
|
|
|
|
|
folderSegments: ['Deals'],
|
|
|
|
|
filename: 'x.pdf',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('collapses empty intermediate segments', () => {
|
|
|
|
|
expect(parseImportPath('legacy', 'legacy/a//b/c.pdf')).toEqual({
|
|
|
|
|
folderSegments: ['a', 'b'],
|
|
|
|
|
filename: 'c.pdf',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('handles an empty prefix as "list-the-whole-bucket"', () => {
|
|
|
|
|
expect(parseImportPath('', 'Folder/file.pdf')).toEqual({
|
|
|
|
|
folderSegments: ['Folder'],
|
|
|
|
|
filename: 'file.pdf',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('preserves special characters in folder names', () => {
|
chore(autonomous-session): consolidate uncommitted work from prior session
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
2026-05-23 00:52:59 +02:00
|
|
|
expect(parseImportPath('', "Q1 - Year's End/contract & rider.pdf")).toEqual({
|
|
|
|
|
folderSegments: ["Q1 - Year's End"],
|
2026-05-10 16:53:51 +02:00
|
|
|
filename: 'contract & rider.pdf',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws when the key is not under the prefix', () => {
|
|
|
|
|
expect(() => parseImportPath('legacy', 'other/x.pdf')).toThrow(/not under prefix/);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws when the relative path has no filename', () => {
|
|
|
|
|
expect(() => parseImportPath('legacy', 'legacy/')).toThrow(/no filename/);
|
|
|
|
|
expect(() => parseImportPath('', '')).toThrow(/no filename/);
|
|
|
|
|
});
|
|
|
|
|
});
|