mirror of
https://github.com/sasjs/server.git
synced 2026-01-04 05:20:06 +00:00
chore: addExtension function fix and testing
This commit is contained in:
@@ -63,7 +63,7 @@ router.get('/SASjsExecutor/do', async (req, res) => {
|
|||||||
.replace(new RegExp('/', 'g'), path.sep)
|
.replace(new RegExp('/', 'g'), path.sep)
|
||||||
|
|
||||||
// If no extension provided, add .sas extension
|
// If no extension provided, add .sas extension
|
||||||
sasCodePath += !sasCodePath.includes('.') ? '.sas' : ''
|
sasCodePath += addExtensionIfNotFound(sasCodePath, 'sas')
|
||||||
|
|
||||||
await new ExecutionController()
|
await new ExecutionController()
|
||||||
.execute(sasCodePath, undefined, undefined, { ...req.query })
|
.execute(sasCodePath, undefined, undefined, { ...req.query })
|
||||||
|
|||||||
@@ -26,5 +26,11 @@ export const generateUniqueFileName = (fileName: string, extension = '') =>
|
|||||||
].join('')
|
].join('')
|
||||||
|
|
||||||
export const addExtensionIfNotFound = (value: string, extension: string) => {
|
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}` : ''
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/utils/spec/file.spec.ts
Normal file
11
src/utils/spec/file.spec.ts
Normal 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('')
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user