1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 11:24:35 +00:00

chore: addExtension function fix and testing

This commit is contained in:
Mihajlo Medjedovic
2021-10-18 16:24:10 +00:00
parent 6efb2d0b51
commit 94fc242afe
3 changed files with 19 additions and 2 deletions

View File

@@ -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 += !sasCodePath.includes('.') ? '.sas' : ''
sasCodePath += addExtensionIfNotFound(sasCodePath, 'sas')
await new ExecutionController()
.execute(sasCodePath, undefined, undefined, { ...req.query })

View File

@@ -26,5 +26,11 @@ export const generateUniqueFileName = (fileName: string, extension = '') =>
].join('')
export const addExtensionIfNotFound = (value: string, extension: string) => {
return !value.includes('.') ? `.${extension}` : ''
const valueSplit = value.split('.')
if (valueSplit.length < 2) return `.${extension}`
const hasExt = valueSplit[valueSplit.length - 1].length === 3
return !hasExt ? `.${extension}` : ''
}

View File

@@ -0,0 +1,11 @@
import { addExtensionIfNotFound } 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('')
})
})