File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22const { shimInit } = require ( './shim-init-node' ) ;
33import shim from './shim' ;
44import { setupDatabaseAndSynchronizer , supportDir } from './testing/test-utils' ;
5+ import { copyFile } from 'fs-extra' ;
56
67describe ( 'shim-init-node' , ( ) => {
78
@@ -10,10 +11,21 @@ describe('shim-init-node', () => {
1011 shimInit ( ) ;
1112 } ) ;
1213
13- test ( 'should set mime the correct mime for a PDF file even if the extension is missing' , async ( ) => {
14+ test ( 'should set the correct mime for a PDF file even if the extension is missing' , async ( ) => {
1415 const filePath = `${ supportDir } /valid_pdf_without_ext` ;
1516 const resource = await shim . createResourceFromPath ( filePath ) ;
1617
1718 expect ( resource . mime ) . toBe ( 'application/pdf' ) ;
1819 } ) ;
20+
21+ test ( 'should preserve the file extension if one is provided regardless of the mime type' , async ( ) => {
22+ const originalFilePath = `${ supportDir } /valid_pdf_without_ext` ;
23+ const fileWithDifferentExtension = `${ originalFilePath } .mscz` ;
24+ await copyFile ( originalFilePath , fileWithDifferentExtension ) ;
25+
26+ const resource = await shim . createResourceFromPath ( fileWithDifferentExtension ) ;
27+
28+ expect ( resource . file_extension ) . toBe ( 'mscz' ) ;
29+ } ) ;
30+
1931} ) ;
Original file line number Diff line number Diff line change @@ -344,7 +344,7 @@ function shimInit(options: ShimInitOptions = null) {
344344 const detectedType = await fileTypeFromFile ( filePath ) ;
345345
346346 if ( detectedType ) {
347- fileExt = detectedType . ext ;
347+ fileExt = fileExt ? fileExt : detectedType . ext ;
348348 resource . mime = detectedType . mime ;
349349 } else {
350350 resource . mime = 'application/octet-stream' ;
You can’t perform that action at this time.
0 commit comments