eCourt-Doc-Edit/web/test/versionDownload.spec.ts
Suphonchai Phoonsawat 39d610a781 Phase 11: version PDF (FR-15)
- เลข version ใหม่: เว็บ-generate = v0 ฉบับตั้งต้น (ไม่มี PDF), add-in save (Start Versioning + Save & Version) = v1+ มี PDF เสมอ
- PDF ผลิตจาก Word จริงผ่าน task pane เท่านั้น (getFileAsync Pdf + runtime guard, manifest ไม่เพิ่ม requirement); capture/upload เป็น best-effort — docx ผ่านแม้ PDF ล้ม + MessageBar เตือนตาม hasPdf
- Backend: DocumentVersion.PdfObjectKey (nullable, migration AddVersionPdf) + sibling .pdf ใน bucket docx-versions · multipart part pdf (ผิด type → 400) · /download + /download-link รับ ?format=pdf (ไม่มี → 404) · presigned ฝังชื่อไฟล์ไทย + _vN (RFC 5987)
- Web: เปิดไฟล์แทน blob-download — PDF แท็บใหม่, docx ผ่าน ms-word:ofe|u| พร้อม heuristic fallback ลิงก์สำรอง (useVersionOpen, versionDownload) · ปุ่ม "เปิดใน Word" ที่หน้า success ของฟอร์มสร้างเอกสาร
- Spec v7 + CONTEXT.md + ADR 0001 + แผน docs/plans/version-pdf.md
- Automated QA: backend 68 / add-in 63 / web 55 ผ่าน · manual acceptance ผ่านบน Word for Mac (2026-09-08) รวม fidelity + track changes — ค้างเฉพาะ Windows / Word on the web

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-08 14:01:13 +07:00

17 lines
970 B
TypeScript

import { describe, expect, it } from 'vitest'
import { versionFileName, versionDownloadPath, wordOpenUrl } from '../app/utils/versionDownload'
describe('version downloads', () => {
it('names v0 and later artifacts', () => {
expect(versionFileName('คำร้อง.DOCX', 0)).toBe('คำร้อง_v0.docx')
expect(versionFileName('คำร้อง.docx', 1, 'pdf')).toBe('คำร้อง_v1.pdf')
})
it('requests the authenticated download-link format', () => {
expect(versionDownloadPath('d', 'v')).toBe('/api/documents/d/versions/v/download-link')
expect(versionDownloadPath('d', 'v', 'pdf')).toBe('/api/documents/d/versions/v/download-link?format=pdf')
})
it('preserves the signed URL exactly inside the Office URI', () => {
const url = 'https://files.example/d.docx?X-Amz-Signature=abc&response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27'
expect(wordOpenUrl(url)).toBe(`ms-word:ofe|u|${url}`)
})
})