mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-17 17:10:05 +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 * as NodeFormData from 'form-data'
|
||||||
import { convertToCSV } from '../utils/convertToCsv'
|
import { convertToCSV, isFormatsTable } from '../utils/convertToCsv'
|
||||||
import { splitChunks } from '../utils/splitChunks'
|
import { splitChunks } from '../utils/splitChunks'
|
||||||
|
|
||||||
export const generateTableUploadForm = (
|
export const generateTableUploadForm = (
|
||||||
@@ -13,7 +13,8 @@ export const generateTableUploadForm = (
|
|||||||
for (const tableName in data) {
|
for (const tableName in data) {
|
||||||
tableCounter++
|
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)
|
const csv = convertToCSV(data, tableName)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { convertToCSV } from './convertToCsv'
|
import { convertToCSV, isFormatsTable } from './convertToCsv'
|
||||||
|
|
||||||
describe('convertToCsv', () => {
|
describe('convertToCsv', () => {
|
||||||
const tableName = 'testTable'
|
const tableName = 'testTable'
|
||||||
@@ -216,7 +216,9 @@ describe('convertToCsv', () => {
|
|||||||
const data = { [tableName]: [{ var1: 'string' }] }
|
const data = { [tableName]: [{ var1: 'string' }] }
|
||||||
|
|
||||||
expect(() => convertToCSV(data, 'wrongTableName')).toThrow(
|
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('')
|
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 { isSpecialMissing } from '@sasjs/utils/input/validators'
|
||||||
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given JSON object array to a CSV string.
|
* Converts the given JSON object array to a CSV string.
|
||||||
@@ -9,7 +10,10 @@ export const convertToCSV = (
|
|||||||
tableName: string
|
tableName: string
|
||||||
) => {
|
) => {
|
||||||
if (!data[tableName]) {
|
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]
|
const table = data[tableName]
|
||||||
@@ -170,6 +174,12 @@ export const convertToCSV = (
|
|||||||
return finalCSV
|
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) => {
|
const getByteSize = (str: string) => {
|
||||||
let byteSize = str.length
|
let byteSize = str.length
|
||||||
for (let i = str.length - 1; i >= 0; i--) {
|
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'
|
import { splitChunks } from './splitChunks'
|
||||||
|
|
||||||
export const formatDataForRequest = (data: any) => {
|
export const formatDataForRequest = (data: any) => {
|
||||||
@@ -8,7 +8,7 @@ export const formatDataForRequest = (data: any) => {
|
|||||||
|
|
||||||
for (const tableName in data) {
|
for (const tableName in data) {
|
||||||
if (
|
if (
|
||||||
tableName.match(/^\$.*/) &&
|
isFormatsTable(tableName) &&
|
||||||
Object.keys(data).includes(tableName.replace(/^\$/, ''))
|
Object.keys(data).includes(tableName.replace(/^\$/, ''))
|
||||||
) {
|
) {
|
||||||
continue
|
continue
|
||||||
@@ -16,7 +16,8 @@ export const formatDataForRequest = (data: any) => {
|
|||||||
|
|
||||||
tableCounter++
|
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)
|
const csv = convertToCSV(data, tableName)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user