mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 20:40:05 +00:00
chore(git): Merge branch 'master' into auto-tests
This commit is contained in:
@@ -81,6 +81,27 @@ const errorAndCsrfData: any = {
|
||||
_csrf: [{ col1: 'q', col2: 'w', col3: 'e', col4: 'r' }]
|
||||
}
|
||||
|
||||
const testTable = 'sometable'
|
||||
export const testTableWithSpecialNumeric: { [key: string]: any } = {
|
||||
[testTable]: [
|
||||
{ var1: 'string', var2: 232, specialnumeric: 'A' },
|
||||
{ var1: 'string', var2: 232, specialnumeric: 'B' },
|
||||
{ var1: 'string', var2: 232, specialnumeric: '_' },
|
||||
{ var1: 'string', var2: 232, specialnumeric: 0 },
|
||||
{ var1: 'string', var2: 232, specialnumeric: 'Z' },
|
||||
{ var1: 'string', var2: 232, specialnumeric: null }
|
||||
],
|
||||
[`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } }
|
||||
}
|
||||
export const testTableWithSpecialNumericOneRow: { [key: string]: any } = {
|
||||
[testTable]: [{ var1: 'string', var2: 232, specialnumeric: 'S' }],
|
||||
[`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } }
|
||||
}
|
||||
export const testTableWithSpecialNumericLowercase: { [key: string]: any } = {
|
||||
[testTable]: [{ var1: 'string', var2: 232, specialnumeric: 's' }],
|
||||
[`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } }
|
||||
}
|
||||
|
||||
export const specialCaseTests = (adapter: SASjs): TestSuite => ({
|
||||
name: 'Special Cases',
|
||||
tests: [
|
||||
@@ -277,6 +298,203 @@ export const specialCaseTests = (adapter: SASjs): TestSuite => ({
|
||||
const responseKeys: any = Object.keys(response)
|
||||
return responseKeys.includes('file') && responseKeys.includes('data')
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Special missing values',
|
||||
description: 'Should support special missing values',
|
||||
test: () => {
|
||||
return adapter.request('common/sendObj', testTableWithSpecialNumeric)
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
let assertionRes = true
|
||||
|
||||
// We receive formats in response. We compare it with formats that we included in request to make sure they are equal
|
||||
const resVars = res[`$${testTable}`].vars
|
||||
|
||||
Object.keys(resVars).forEach((key: any, i: number) => {
|
||||
let formatValue =
|
||||
testTableWithSpecialNumeric[`$${testTable}`].formats[
|
||||
key.toLowerCase()
|
||||
]
|
||||
// If it is char, we change it to $ to be compatible for comparsion
|
||||
// If it is number, it will already be compatible to comapre (best.)
|
||||
formatValue = formatValue?.includes('$') ? '$' : formatValue
|
||||
|
||||
if (
|
||||
formatValue !== undefined &&
|
||||
!resVars[key].format.includes(formatValue)
|
||||
) {
|
||||
assertionRes = false
|
||||
}
|
||||
})
|
||||
|
||||
// Here we will compare the response values with values we send
|
||||
const resValues = res[testTable]
|
||||
|
||||
testTableWithSpecialNumeric[testTable].forEach(
|
||||
(row: { [key: string]: any }, i: number) =>
|
||||
Object.keys(row).forEach((col: string) => {
|
||||
if (resValues[i][col.toUpperCase()] !== row[col]) {
|
||||
assertionRes = false
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return assertionRes
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Special missing values (ONE ROW)',
|
||||
description:
|
||||
'Should support special missing values, when one row is send',
|
||||
test: () => {
|
||||
return adapter.request(
|
||||
'common/sendObj',
|
||||
testTableWithSpecialNumericOneRow
|
||||
)
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
let assertionRes = true
|
||||
|
||||
// We receive formats in response. We compare it with formats that we included in request to make sure they are equal
|
||||
const resVars = res[`$${testTable}`].vars
|
||||
|
||||
Object.keys(resVars).forEach((key: any, i: number) => {
|
||||
let formatValue =
|
||||
testTableWithSpecialNumeric[`$${testTable}`].formats[
|
||||
key.toLowerCase()
|
||||
]
|
||||
// If it is char, we change it to $ to be compatible for comparsion
|
||||
// If it is number, it will already be compatible to comapre (best.)
|
||||
formatValue = formatValue?.includes('$') ? '$' : formatValue
|
||||
|
||||
if (
|
||||
formatValue !== undefined &&
|
||||
!resVars[key].format.includes(formatValue)
|
||||
) {
|
||||
assertionRes = false
|
||||
}
|
||||
})
|
||||
|
||||
// Here we will compare the response values with values we send
|
||||
const resValues = res[testTable]
|
||||
|
||||
testTableWithSpecialNumericOneRow[testTable].forEach(
|
||||
(row: { [key: string]: any }, i: number) =>
|
||||
Object.keys(row).forEach((col: string) => {
|
||||
if (resValues[i][col.toUpperCase()] !== row[col]) {
|
||||
assertionRes = false
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return assertionRes
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Special missing values (LOWERCASE)',
|
||||
description:
|
||||
'Should support special missing values, when LOWERCASE value is sent',
|
||||
test: () => {
|
||||
return adapter.request(
|
||||
'common/sendObj',
|
||||
testTableWithSpecialNumericLowercase
|
||||
)
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
let assertionRes = true
|
||||
|
||||
// We receive formats in response. We compare it with formats that we included in request to make sure they are equal
|
||||
const resVars = res[`$${testTable}`].vars
|
||||
|
||||
Object.keys(resVars).forEach((key: any, i: number) => {
|
||||
let formatValue =
|
||||
testTableWithSpecialNumericLowercase[`$${testTable}`].formats[
|
||||
key.toLowerCase()
|
||||
]
|
||||
// If it is a char, we change it to $ to be compatible for comparison
|
||||
// If it is a number, it will already be compatible to compare (best.)
|
||||
formatValue = formatValue?.includes('$') ? '$' : formatValue
|
||||
|
||||
if (
|
||||
formatValue !== undefined &&
|
||||
!resVars[key].format.includes(formatValue)
|
||||
) {
|
||||
assertionRes = false
|
||||
}
|
||||
})
|
||||
|
||||
// Here we will compare the response values with values we send
|
||||
const resValues = res[testTable]
|
||||
|
||||
testTableWithSpecialNumericLowercase[testTable].forEach(
|
||||
(row: { [key: string]: any }, i: number) =>
|
||||
Object.keys(row).forEach((col: string) => {
|
||||
if (col === 'specialnumeric') {
|
||||
if (
|
||||
resValues[i][col.toUpperCase()] !== row[col].toUpperCase()
|
||||
) {
|
||||
assertionRes = false
|
||||
}
|
||||
} else {
|
||||
if (resValues[i][col.toUpperCase()] !== row[col]) {
|
||||
assertionRes = false
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return assertionRes
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Special missing values (ONE ROW) useComputeApi undefined',
|
||||
description:
|
||||
'Should support special missing values, when one row is send (On VIYA Web Approach)',
|
||||
test: () => {
|
||||
return adapter.request(
|
||||
'common/sendObj',
|
||||
testTableWithSpecialNumericOneRow,
|
||||
{ useComputeApi: undefined }
|
||||
)
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
let assertionRes = true
|
||||
|
||||
// We receive formats in response. We compare it with formats that we included in request to make sure they are equal
|
||||
const resVars = res[`$${testTable}`].vars
|
||||
|
||||
Object.keys(resVars).forEach((key: any, i: number) => {
|
||||
let formatValue =
|
||||
testTableWithSpecialNumeric[`$${testTable}`].formats[
|
||||
key.toLowerCase()
|
||||
]
|
||||
// If it is char, we change it to $ to be compatible for comparsion
|
||||
// If it is number, it will already be compatible to comapre (best.)
|
||||
formatValue = formatValue?.includes('$') ? '$' : formatValue
|
||||
|
||||
if (
|
||||
formatValue !== undefined &&
|
||||
!resVars[key].format.includes(formatValue)
|
||||
) {
|
||||
assertionRes = false
|
||||
}
|
||||
})
|
||||
|
||||
// Here we will compare the response values with values we send
|
||||
const resValues = res[testTable]
|
||||
|
||||
testTableWithSpecialNumericOneRow[testTable].forEach(
|
||||
(row: { [key: string]: any }, i: number) =>
|
||||
Object.keys(row).forEach((col: string) => {
|
||||
if (resValues[i][col.toUpperCase()] !== row[col]) {
|
||||
assertionRes = false
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return assertionRes
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user