1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-07 04:20:05 +00:00

fix(convert-to-csv): return empty string if table is not an array

This commit is contained in:
Yury Shkoda
2022-03-03 17:31:23 +03:00
parent 4f3478c215
commit f6abb61c69
4 changed files with 12 additions and 3 deletions

View File

@@ -2388,7 +2388,7 @@
"node_modules/@sasjs/adapter": { "node_modules/@sasjs/adapter": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "file:../build/sasjs-adapter-5.0.0.tgz", "resolved": "file:../build/sasjs-adapter-5.0.0.tgz",
"integrity": "sha512-O4MnLA6Tm2xoANU1uBJ5xMzEBeXVGkw38lR6LoiLIUhQOJY5gpwjb39oBPFqPfvCwjG0Jqjx7XcaE+g23pEfNw==", "integrity": "sha512-lbDWueAEnfNlu4OGrc9hBEzT0aoLfAy7eLd2nLHArrF6zukcSGBNhUgOqxIhlz4WeBdf1gt3nk1G7p5X1mrWYQ==",
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
@@ -20998,7 +20998,7 @@
}, },
"@sasjs/adapter": { "@sasjs/adapter": {
"version": "file:../build/sasjs-adapter-5.0.0.tgz", "version": "file:../build/sasjs-adapter-5.0.0.tgz",
"integrity": "sha512-O4MnLA6Tm2xoANU1uBJ5xMzEBeXVGkw38lR6LoiLIUhQOJY5gpwjb39oBPFqPfvCwjG0Jqjx7XcaE+g23pEfNw==", "integrity": "sha512-lbDWueAEnfNlu4OGrc9hBEzT0aoLfAy7eLd2nLHArrF6zukcSGBNhUgOqxIhlz4WeBdf1gt3nk1G7p5X1mrWYQ==",
"requires": { "requires": {
"@sasjs/utils": "2.36.1", "@sasjs/utils": "2.36.1",
"axios": "0.26.0", "axios": "0.26.0",

View File

@@ -465,6 +465,6 @@ export const specialCaseTests = (adapter: SASjs): TestSuite => ({
return assertionRes return assertionRes
} }
}, }
] ]
}) })

View File

@@ -219,4 +219,10 @@ describe('convertToCsv', () => {
new Error('No table provided to be converted to CSV') new Error('No table provided to be converted to CSV')
) )
}) })
it('should empty string if table is not an array', () => {
const data = { [tableName]: true }
expect(convertToCSV(data, tableName)).toEqual('')
})
}) })

View File

@@ -11,6 +11,9 @@ export const convertToCSV = (
} }
const table = data[tableName] const table = data[tableName]
if (!Array.isArray(table)) return ''
let formats = data[`$${tableName}`]?.formats let formats = data[`$${tableName}`]?.formats
let headers: string[] = [] let headers: string[] = []
let csvTest let csvTest