1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-10 05:40:06 +00:00

feat(nullVars): add SAS null vars support

This commit is contained in:
Yury Shkoda
2022-01-05 16:54:16 +03:00
parent 84ed3e7d03
commit fbce35b272
5 changed files with 163 additions and 52 deletions

View File

@@ -167,4 +167,42 @@ describe('convertToCsv', () => {
convertToCSV([{ slashWithSpecialExtra: '\\\ts\tl\ta\ts\t\th\t' }])
).toEqual(`slashWithSpecialExtra:$char13.\r\n\"\\\ts\tl\ta\ts\t\th\t\"`)
})
it('should convert not null values', () => {
const data = [
{ var1: 'string', nullvar: 'A', var2: 232 },
{ var1: 'string', nullvar: 'B', var2: 232 },
{ var1: 'string', nullvar: '_', var2: 232 },
{ var1: 'string', nullvar: 0, var2: 232 },
{ var1: 'string', nullvar: 'z', var2: 232 },
{ var1: 'string', nullvar: null, var2: 232 }
]
const expectedOutput = `var1:$char6. nullvar:best. var2:best.\r\nstring,.a,232\r\nstring,.b,232\r\nstring,._,232\r\nstring,0,232\r\nstring,.z,232\r\nstring,.,232`
expect(
convertToCSV(data, {
formats: { var1: '$char6.', nullvar: 'best.' }
})
).toEqual(expectedOutput)
})
it('should return error if string is more than maxFieldValue', () => {
const data = [{ var1: 'z'.repeat(32765 + 1) }]
expect(convertToCSV(data)).toEqual('ERROR: LARGE STRING LENGTH')
})
it('should console log error if data has mixed types', () => {
const colName = 'var1'
const data = [{ [colName]: 'string' }, { [colName]: 232 }]
jest.spyOn(console, 'error').mockImplementation(() => {})
convertToCSV(data)
expect(console.error).toHaveBeenCalledWith(
`Row (2), Column (${colName}) has mixed types: ERROR`
)
})
})