okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
9caf39495
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { readFile } from 'node:fs/promises' ; 4import { transform } from 'esbuild' ; 5 6const { code} = await transform ( await readFile ( new URL ( '../src/lib/chat-attach-file.ts' , import . meta. url ), 'utf8' ), { loader :'ts' , format :'esm' }); 7const { uploadChatFile, FILE_ACCEPT } = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 8 9test ( 'the file dialog lists PDFs and text on Linux: the types sit next to the extensions (#3838)' , () => { 10for ( const t of [ 'image/*' , 'application/pdf' , 'text/*' , '.pdf' , '.md' ]) assert . ok ( FILE_ACCEPT . split ( ',' ). includes ( t ), t ); 11}); 12test ( 'a PDF is sent to the chat folder through the upload route and named back' , async () => { 13let seen ; 14const fake = async ( url , init ) => { seen = { url, init}; return { ok :true , json :async () => ({ files :[{ name :'report-2.pdf' , attached :true }] }) }; }; 15const out = await uploadChatFile ( new File ([ '%PDF-1.4' ], 'report.pdf' , { type :'application/pdf' }), 's 1' , fake ); 16assert . equal ( out . name , 'report-2.pdf' ); 17assert . match ( seen . url , / \/api\/chat\/upload\?sessionId=s%201&name=report\.pdf$ / ); 18assert . equal ( seen . init . method , 'POST' ); assert . equal ( seen . init . headers [ 'content-type' ], 'application/pdf' ); 19}); 20test ( 'a refused upload says why' , async () => { 21await assert . rejects ( uploadChatFile ( new File ([ 'x' ], 'a.pdf' ), 's' , async () => ({ ok :false , json :async () => ({ error :'"a.pdf" is bigger than 12 MB.' }) })), / bigger than 12 MB / ); 22});