1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-09 13:30:04 +00:00

chore(sasjs-tests): improve spelling and code readability

This commit is contained in:
Yury Shkoda
2022-03-03 10:58:51 +03:00
parent 888a2b9bd3
commit f0f33cee52
2 changed files with 81 additions and 46 deletions

View File

@@ -2388,7 +2388,7 @@
"node_modules/@sasjs/adapter": { "node_modules/@sasjs/adapter": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "file:../build/sasjs-adapter-5.0.0.tgz", "resolved": "file:../build/sasjs-adapter-5.0.0.tgz",
"integrity": "sha512-iPr8TRKHAFSI9tWJjCqB/M+DzstyhQSJhrovkhqiKB76tuqck+vvgTiB+4KoHEq6PjlbW+mfIzHcVC9trrztxA==", "integrity": "sha512-JZsvovkPNb0dlnBRh1uDdvgJg+BE0ebIomWwhYjHj3YApds4MgI++1pa+Ck2tltIUUYASeiPUIPJJX8tF3VCTw==",
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
@@ -20998,7 +20998,7 @@
}, },
"@sasjs/adapter": { "@sasjs/adapter": {
"version": "file:../build/sasjs-adapter-5.0.0.tgz", "version": "file:../build/sasjs-adapter-5.0.0.tgz",
"integrity": "sha512-iPr8TRKHAFSI9tWJjCqB/M+DzstyhQSJhrovkhqiKB76tuqck+vvgTiB+4KoHEq6PjlbW+mfIzHcVC9trrztxA==", "integrity": "sha512-JZsvovkPNb0dlnBRh1uDdvgJg+BE0ebIomWwhYjHj3YApds4MgI++1pa+Ck2tltIUUYASeiPUIPJJX8tF3VCTw==",
"requires": { "requires": {
"@sasjs/utils": "2.36.1", "@sasjs/utils": "2.36.1",
"axios": "0.26.0", "axios": "0.26.0",

View File

@@ -92,15 +92,11 @@ export const testTableWithSpecialNumeric: { [key: string]: any } = {
[`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } } [`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } }
} }
export const testTableWithSpecialNumericOneRow: { [key: string]: any } = { export const testTableWithSpecialNumericOneRow: { [key: string]: any } = {
[testTable]: [ [testTable]: [{ var1: 'string', var2: 232, specialnumeric: 'S' }],
{ var1: 'string', var2: 232, specialnumeric: 'S' }
],
[`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } } [`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } }
} }
export const testTableWithSpecialNumericLowercase: { [key: string]: any } = { export const testTableWithSpecialNumericLowercase: { [key: string]: any } = {
[testTable]: [ [testTable]: [{ var1: 'string', var2: 232, specialnumeric: 's' }],
{ var1: 'string', var2: 232, specialnumeric: 's' }
],
[`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } } [`$${testTable}`]: { formats: { var1: '$char12.', specialnumeric: 'best.' } }
} }
@@ -285,23 +281,32 @@ export const specialCaseTests = (adapter: SASjs): TestSuite => ({
// We receive formats in response. We compare it with formats that we included in request to make sure they are equal // 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 const resVars = res[`$${testTable}`].vars
Object.keys(resVars).forEach( Object.keys(resVars).forEach((key: any, i: number) => {
(key: any, i: number) => { let formatValue =
let formatValue = testTableWithSpecialNumeric[`$${testTable}`].formats[key.toLowerCase()] testTableWithSpecialNumeric[`$${testTable}`].formats[
key.toLowerCase()
]
// If it is char, we change it to $ to be compatible for comparsion // 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.) // If it is number, it will already be compatible to comapre (best.)
formatValue = formatValue?.includes('$') ? '$' : formatValue formatValue = formatValue?.includes('$') ? '$' : formatValue
if (formatValue !== undefined && !resVars[key].format.includes(formatValue)) assertionRes = false if (
formatValue !== undefined &&
!resVars[key].format.includes(formatValue)
) {
assertionRes = false
}
}) })
// Here we will compare the response values with values we send // Here we will compare the response values with values we send
const resVals = res[testTable] const resValues = res[testTable]
testTableWithSpecialNumeric[testTable].forEach( testTableWithSpecialNumeric[testTable].forEach(
(row: { [key: string]: any }, i: number) => (row: { [key: string]: any }, i: number) =>
Object.keys(row).forEach((col: string) => { Object.keys(row).forEach((col: string) => {
if (resVals[i][col.toUpperCase()] !== row[col]) assertionRes = false if (resValues[i][col.toUpperCase()] !== row[col]) {
assertionRes = false
}
}) })
) )
@@ -310,9 +315,13 @@ export const specialCaseTests = (adapter: SASjs): TestSuite => ({
}, },
{ {
title: 'Special missing values (ONE ROW)', title: 'Special missing values (ONE ROW)',
description: 'Should support special missing values, when one row is send', description:
'Should support special missing values, when one row is send',
test: () => { test: () => {
return adapter.request('common/sendObj', testTableWithSpecialNumericOneRow,) return adapter.request(
'common/sendObj',
testTableWithSpecialNumericOneRow
)
}, },
assertion: (res: any) => { assertion: (res: any) => {
let assertionRes = true let assertionRes = true
@@ -320,23 +329,32 @@ export const specialCaseTests = (adapter: SASjs): TestSuite => ({
// We receive formats in response. We compare it with formats that we included in request to make sure they are equal // 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 const resVars = res[`$${testTable}`].vars
Object.keys(resVars).forEach( Object.keys(resVars).forEach((key: any, i: number) => {
(key: any, i: number) => { let formatValue =
let formatValue = testTableWithSpecialNumeric[`$${testTable}`].formats[key.toLowerCase()] testTableWithSpecialNumeric[`$${testTable}`].formats[
key.toLowerCase()
]
// If it is char, we change it to $ to be compatible for comparsion // 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.) // If it is number, it will already be compatible to comapre (best.)
formatValue = formatValue?.includes('$') ? '$' : formatValue formatValue = formatValue?.includes('$') ? '$' : formatValue
if (formatValue !== undefined && !resVars[key].format.includes(formatValue)) assertionRes = false if (
formatValue !== undefined &&
!resVars[key].format.includes(formatValue)
) {
assertionRes = false
}
}) })
// Here we will compare the response values with values we send // Here we will compare the response values with values we send
const resVals = res[testTable] const resValues = res[testTable]
testTableWithSpecialNumericOneRow[testTable].forEach( testTableWithSpecialNumericOneRow[testTable].forEach(
(row: { [key: string]: any }, i: number) => (row: { [key: string]: any }, i: number) =>
Object.keys(row).forEach((col: string) => { Object.keys(row).forEach((col: string) => {
if (resVals[i][col.toUpperCase()] !== row[col]) assertionRes = false if (resValues[i][col.toUpperCase()] !== row[col]) {
assertionRes = false
}
}) })
) )
@@ -345,9 +363,13 @@ export const specialCaseTests = (adapter: SASjs): TestSuite => ({
}, },
{ {
title: 'Special missing values (LOWERCASE)', title: 'Special missing values (LOWERCASE)',
description: 'Should support special missing values, when LOWERCASE value is send', description:
'Should support special missing values, when LOWERCASE value is sent',
test: () => { test: () => {
return adapter.request('common/sendObj', testTableWithSpecialNumericLowercase,) return adapter.request(
'common/sendObj',
testTableWithSpecialNumericLowercase
)
}, },
assertion: (res: any) => { assertion: (res: any) => {
let assertionRes = true let assertionRes = true
@@ -355,26 +377,39 @@ export const specialCaseTests = (adapter: SASjs): TestSuite => ({
// We receive formats in response. We compare it with formats that we included in request to make sure they are equal // 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 const resVars = res[`$${testTable}`].vars
Object.keys(resVars).forEach( Object.keys(resVars).forEach((key: any, i: number) => {
(key: any, i: number) => { let formatValue =
let formatValue = testTableWithSpecialNumericLowercase[`$${testTable}`].formats[key.toLowerCase()] testTableWithSpecialNumericLowercase[`$${testTable}`].formats[
//If it is char, we change it to $ to be compatible for comparsion key.toLowerCase()
//If it is number, it will already be compatible to comapre (best.) ]
// 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 formatValue = formatValue?.includes('$') ? '$' : formatValue
if (formatValue !== undefined && !resVars[key].format.includes(formatValue)) assertionRes = false if (
formatValue !== undefined &&
!resVars[key].format.includes(formatValue)
) {
assertionRes = false
}
}) })
// Here we will compare the response values with values we send // Here we will compare the response values with values we send
const resVals = res[testTable] const resValues = res[testTable]
testTableWithSpecialNumericLowercase[testTable].forEach( testTableWithSpecialNumericLowercase[testTable].forEach(
(row: { [key: string]: any }, i: number) => (row: { [key: string]: any }, i: number) =>
Object.keys(row).forEach((col: string) => { Object.keys(row).forEach((col: string) => {
if (col === 'specialnumeric') { if (col === 'specialnumeric') {
if (resVals[i][col.toUpperCase()] !== row[col].toUpperCase()) assertionRes = false if (
resValues[i][col.toUpperCase()] !== row[col].toUpperCase()
) {
assertionRes = false
}
} else { } else {
if (resVals[i][col.toUpperCase()] !== row[col]) assertionRes = false if (resValues[i][col.toUpperCase()] !== row[col]) {
assertionRes = false
}
} }
}) })
) )