mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
fix(special-missings): fixed formats table sent as part of sasjs_tables
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as NodeFormData from 'form-data'
|
||||
import { convertToCSV } from '../utils/convertToCsv'
|
||||
import { convertToCSV, isFormatsTable } from '../utils/convertToCsv'
|
||||
import { splitChunks } from '../utils/splitChunks'
|
||||
|
||||
export const generateTableUploadForm = (
|
||||
@@ -13,7 +13,8 @@ export const generateTableUploadForm = (
|
||||
for (const tableName in data) {
|
||||
tableCounter++
|
||||
|
||||
sasjsTables.push(tableName)
|
||||
// Formats table should not be sent as part of 'sasjs_tables'
|
||||
if (!isFormatsTable(tableName)) sasjsTables.push(tableName)
|
||||
|
||||
const csv = convertToCSV(data, tableName)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { convertToCSV } from './convertToCsv'
|
||||
import { convertToCSV, isFormatsTable } from './convertToCsv'
|
||||
|
||||
describe('convertToCsv', () => {
|
||||
const tableName = 'testTable'
|
||||
@@ -216,7 +216,9 @@ describe('convertToCsv', () => {
|
||||
const data = { [tableName]: [{ var1: 'string' }] }
|
||||
|
||||
expect(() => convertToCSV(data, 'wrongTableName')).toThrow(
|
||||
new Error('No table provided to be converted to CSV')
|
||||
new Error(
|
||||
'Error while converting to CSV. No table provided to be converted to CSV.'
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
@@ -226,3 +228,15 @@ describe('convertToCsv', () => {
|
||||
expect(convertToCSV(data, tableName)).toEqual('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isFormatsTable', () => {
|
||||
const tableName = 'sometable'
|
||||
|
||||
it('should return true if table name match pattern of formats table', () => {
|
||||
expect(isFormatsTable(`$${tableName}`)).toEqual(true)
|
||||
})
|
||||
|
||||
it('should return false if table name does not match pattern of formats table', () => {
|
||||
expect(isFormatsTable(tableName)).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { isSpecialMissing } from '@sasjs/utils/input/validators'
|
||||
import { prefixMessage } from '@sasjs/utils/error'
|
||||
|
||||
/**
|
||||
* Converts the given JSON object array to a CSV string.
|
||||
@@ -9,7 +10,10 @@ export const convertToCSV = (
|
||||
tableName: string
|
||||
) => {
|
||||
if (!data[tableName]) {
|
||||
throw new Error('No table provided to be converted to CSV')
|
||||
throw prefixMessage(
|
||||
'No table provided to be converted to CSV.',
|
||||
'Error while converting to CSV. '
|
||||
)
|
||||
}
|
||||
|
||||
const table = data[tableName]
|
||||
@@ -170,6 +174,12 @@ export const convertToCSV = (
|
||||
return finalCSV
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if table is table of formats (table name should start from '$' character).
|
||||
* @param tableName - table name.
|
||||
*/
|
||||
export const isFormatsTable = (tableName: string) => /^\$.*/.test(tableName)
|
||||
|
||||
const getByteSize = (str: string) => {
|
||||
let byteSize = str.length
|
||||
for (let i = str.length - 1; i >= 0; i--) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { convertToCSV } from './convertToCsv'
|
||||
import { convertToCSV, isFormatsTable } from './convertToCsv'
|
||||
import { splitChunks } from './splitChunks'
|
||||
|
||||
export const formatDataForRequest = (data: any) => {
|
||||
@@ -8,7 +8,7 @@ export const formatDataForRequest = (data: any) => {
|
||||
|
||||
for (const tableName in data) {
|
||||
if (
|
||||
tableName.match(/^\$.*/) &&
|
||||
isFormatsTable(tableName) &&
|
||||
Object.keys(data).includes(tableName.replace(/^\$/, ''))
|
||||
) {
|
||||
continue
|
||||
@@ -16,7 +16,8 @@ export const formatDataForRequest = (data: any) => {
|
||||
|
||||
tableCounter++
|
||||
|
||||
sasjsTables.push(tableName)
|
||||
// Formats table should not be sent as part of 'sasjs_tables'
|
||||
if (!isFormatsTable(tableName)) sasjsTables.push(tableName)
|
||||
|
||||
const csv = convertToCSV(data, tableName)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user