@@ -221,6 +221,11 @@ describe("sendClickClackMedia", () => {
221221 } ) ;
222222
223223 it ( "preserves filename and MIME while uploading before channel delivery" , async ( ) => {
224+ loadOutboundMediaFromUrl . mockResolvedValueOnce ( {
225+ buffer : Buffer . from ( "const proof = true;" ) ,
226+ contentType : "image/png" ,
227+ fileName : "viewer-proof.ts" ,
228+ } ) ;
224229 const order : string [ ] = [ ] ;
225230 createUpload . mockImplementationOnce ( async ( ) => {
226231 order . push ( "upload" ) ;
@@ -254,7 +259,7 @@ describe("sendClickClackMedia", () => {
254259 workspaceId : "wsp_1" ,
255260 buffer : Buffer . from ( "const proof = true;" ) ,
256261 filename : "viewer-proof.ts" ,
257- contentType : "text/typescript " ,
262+ contentType : "image/png " ,
258263 } ) ;
259264 expect ( createChannelMessage ) . toHaveBeenCalledWith (
260265 "general" ,
@@ -266,6 +271,83 @@ describe("sendClickClackMedia", () => {
266271 expect ( messageId ) . toBe ( "msg_out" ) ;
267272 } ) ;
268273
274+ it ( "derives an extension from the MIME type when media has no filename" , async ( ) => {
275+ loadOutboundMediaFromUrl . mockResolvedValueOnce ( {
276+ buffer : Buffer . from ( "fake png bytes" ) ,
277+ contentType : "image/png" ,
278+ } ) ;
279+
280+ await sendClickClackMedia ( {
281+ cfg,
282+ to : "channel:general" ,
283+ text : "" ,
284+ mediaUrl : "https://files.example/unnamed" ,
285+ } ) ;
286+
287+ expect ( createUpload ) . toHaveBeenCalledWith ( {
288+ workspaceId : "wsp_1" ,
289+ buffer : Buffer . from ( "fake png bytes" ) ,
290+ filename : "attachment.png" ,
291+ contentType : "image/png" ,
292+ } ) ;
293+ expect ( createChannelMessage ) . toHaveBeenCalledWith (
294+ "general" ,
295+ "attachment.png" ,
296+ expect . objectContaining ( { quotedMessageId : undefined } ) ,
297+ ) ;
298+ } ) ;
299+
300+ it ( "keeps the generic fallback when MIME type has no known extension" , async ( ) => {
301+ loadOutboundMediaFromUrl . mockResolvedValueOnce ( {
302+ buffer : Buffer . from ( "unknown bytes" ) ,
303+ contentType : "application/x-unknown" ,
304+ } ) ;
305+
306+ await sendClickClackMedia ( {
307+ cfg,
308+ to : "channel:general" ,
309+ text : "" ,
310+ mediaUrl : "https://files.example/unknown" ,
311+ } ) ;
312+
313+ expect ( createUpload ) . toHaveBeenCalledWith ( {
314+ workspaceId : "wsp_1" ,
315+ buffer : Buffer . from ( "unknown bytes" ) ,
316+ filename : "attachment" ,
317+ contentType : "application/x-unknown" ,
318+ } ) ;
319+ expect ( createChannelMessage ) . toHaveBeenCalledWith (
320+ "general" ,
321+ "attachment" ,
322+ expect . objectContaining ( { quotedMessageId : undefined } ) ,
323+ ) ;
324+ } ) ;
325+
326+ it ( "keeps the generic fallback when MIME type is missing" , async ( ) => {
327+ loadOutboundMediaFromUrl . mockResolvedValueOnce ( {
328+ buffer : Buffer . from ( "opaque bytes" ) ,
329+ } ) ;
330+
331+ await sendClickClackMedia ( {
332+ cfg,
333+ to : "channel:general" ,
334+ text : "" ,
335+ mediaUrl : "https://files.example/missing-type" ,
336+ } ) ;
337+
338+ expect ( createUpload ) . toHaveBeenCalledWith ( {
339+ workspaceId : "wsp_1" ,
340+ buffer : Buffer . from ( "opaque bytes" ) ,
341+ filename : "attachment" ,
342+ contentType : "application/octet-stream" ,
343+ } ) ;
344+ expect ( createChannelMessage ) . toHaveBeenCalledWith (
345+ "general" ,
346+ "attachment" ,
347+ expect . objectContaining ( { quotedMessageId : undefined } ) ,
348+ ) ;
349+ } ) ;
350+
269351 it ( "uses the filename as the minimal media-only body and routes DMs" , async ( ) => {
270352 const messageId = await sendClickClackMedia ( {
271353 cfg,
0 commit comments