diff --git a/src/api/viya/spec/uploadTables.spec.ts b/src/api/viya/spec/uploadTables.spec.ts index ab00cfd..a253674 100644 --- a/src/api/viya/spec/uploadTables.spec.ts +++ b/src/api/viya/spec/uploadTables.spec.ts @@ -23,6 +23,20 @@ describe('uploadTables', () => { ) }) + it('should skip $tablename formats metadata keys', async () => { + const data = { + tablewith2cols2rows: [{ col1: 'val1', specialMissingsCol: 'A' }], + $tablewith2cols2rows: { formats: { specialMissingsCol: 'best.' } } + } + + const files = await uploadTables(requestClient, data, 't0k3n') + + expect(files).toEqual([ + { tableName: 'tablewith2cols2rows', file: 'test-file' } + ]) + expect(requestClient.uploadFile).toHaveBeenCalledTimes(1) + }) + it('should throw an error when the CSV exceeds the maximum length', async () => { const data = { foo: 'bar' } jest diff --git a/src/api/viya/uploadTables.ts b/src/api/viya/uploadTables.ts index 47f3208..54749be 100644 --- a/src/api/viya/uploadTables.ts +++ b/src/api/viya/uploadTables.ts @@ -1,6 +1,6 @@ import { prefixMessage } from '@sasjs/utils/error' import { RequestClient } from '../../request/RequestClient' -import { convertToCSV } from '../../utils/convertToCsv' +import { convertToCSV, isFormatsTable } from '../../utils/convertToCsv' /** * Uploads tables to SAS as specially formatted CSVs. @@ -18,6 +18,10 @@ export async function uploadTables( const uploadedFiles = [] for (const tableName in data) { + // $tablename keys carry only column-format metadata for the matching + // tablename payload; they must not be uploaded as separate files. + if (isFormatsTable(tableName)) continue + const csv = convertToCSV(data, tableName) if (csv === 'ERROR: LARGE STRING LENGTH') { throw new Error(