diff --git a/src/routes/index.ts b/src/routes/index.ts index d6e5b12..1e9c681 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -7,7 +7,7 @@ import { import { ExecutionResult, isRequestQuery, isFileTree } from '../types' import path from 'path' import { - addExtensionIfNotFound, + addSasExtensionIfNotFound, getTmpFilesFolderPath, getTmpFolderPath, makeFilesNamesMap @@ -63,7 +63,7 @@ router.get('/SASjsExecutor/do', async (req, res) => { .replace(new RegExp('/', 'g'), path.sep) // If no extension provided, add .sas extension - sasCodePath += addExtensionIfNotFound(sasCodePath, 'sas') + sasCodePath += addSasExtensionIfNotFound(sasCodePath) await new ExecutionController() .execute(sasCodePath, undefined, undefined, { ...req.query }) @@ -96,7 +96,7 @@ router.post( .replace(new RegExp('/', 'g'), path.sep) // If no extension provided, add .sas extension - sasCodePath += addExtensionIfNotFound(sasCodePath, 'sas') + sasCodePath += addSasExtensionIfNotFound(sasCodePath) let filesNamesMap = null diff --git a/src/utils/file.ts b/src/utils/file.ts index 6271316..ead26e0 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -25,7 +25,8 @@ export const generateUniqueFileName = (fileName: string, extension = '') => extension ].join('') -export const addExtensionIfNotFound = (value: string, extension: string) => { +export const addSasExtensionIfNotFound = (value: string) => { + const extension = 'sas' const valueSplit = value.split('.') if (valueSplit.length < 2) return `.${extension}` diff --git a/src/utils/spec/file.spec.ts b/src/utils/spec/file.spec.ts index 06d7511..07616ac 100644 --- a/src/utils/spec/file.spec.ts +++ b/src/utils/spec/file.spec.ts @@ -1,11 +1,11 @@ -import { addExtensionIfNotFound } from '..' +import { addSasExtensionIfNotFound } from '..' describe('file utils', () => { it('should add extension if missing', async () => { - expect(addExtensionIfNotFound('test', 'ext')).toEqual('.ext') - expect(addExtensionIfNotFound('test.test', 'ext')).toEqual('.ext') - expect(addExtensionIfNotFound('test.sas', 'ext')).toEqual('') - expect(addExtensionIfNotFound('test.test.test', 'ext')).toEqual('.ext') - expect(addExtensionIfNotFound('test.test.test.sas', 'ext')).toEqual('') + expect(addSasExtensionIfNotFound('test')).toEqual('.sas') + expect(addSasExtensionIfNotFound('test.test')).toEqual('.sas') + expect(addSasExtensionIfNotFound('test.sas')).toEqual('') + expect(addSasExtensionIfNotFound('test.test.test')).toEqual('.sas') + expect(addSasExtensionIfNotFound('test.test.test.sas')).toEqual('') }) })