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

chore(git): Merge branch 'master' into auto-tests

This commit is contained in:
2022-04-27 16:26:02 +02:00
306 changed files with 47729 additions and 92319 deletions

View File

@@ -1,4 +1,4 @@
import SASjs, { SASjsConfig } from '@sasjs/adapter'
import SASjs, { LoginMechanism, SASjsConfig } from '@sasjs/adapter'
import { TestSuite } from '@sasjs/test-framework'
import { ServerType } from '@sasjs/utils/types'
@@ -6,6 +6,7 @@ const stringData: any = { table1: [{ col1: 'first col value' }] }
const defaultConfig: SASjsConfig = {
serverUrl: window.location.origin,
pathSASJS: '/SASjsApi/stp/execute',
pathSAS9: '/SASStoredProcess/do',
pathSASViya: '/SASJobExecution',
appLoc: '/Public/seedapp',
@@ -13,7 +14,7 @@ const defaultConfig: SASjsConfig = {
debug: false,
contextName: 'SAS Job Execution compute context',
useComputeApi: false,
allowInsecureRequests: false
loginMechanism: LoginMechanism.Default
}
const customConfig = {
@@ -41,6 +42,19 @@ export const basicTests = (
assertion: (response: any) =>
response && response.isLoggedIn && response.userName === userName
},
{
title: 'Fetch username for already logged in user',
description: 'Should log the user in',
test: async () => {
await adapter.logIn(userName, password)
const newAdapterIns = new SASjs(adapter.getSasjsConfig())
return await newAdapterIns.checkSession()
},
assertion: (response: any) =>
response?.isLoggedIn && response?.userName === userName
},
{
title: 'Multiple Log in attempts',
description:
@@ -48,7 +62,7 @@ export const basicTests = (
test: async () => {
await adapter.logOut()
await adapter.logIn('invalid', 'invalid')
return adapter.logIn(userName, password)
return await adapter.logIn(userName, password)
},
assertion: (response: any) =>
response && response.isLoggedIn && response.userName === userName
@@ -64,8 +78,8 @@ export const basicTests = (
'common/sendArr',
stringData,
undefined,
() => {
adapter.logIn(userName, password)
async () => {
await adapter.logIn(userName, password)
}
)
},
@@ -150,8 +164,8 @@ export const basicTests = (
title: 'Web request',
description: 'Should run the request with old web approach',
test: async () => {
const config = {
useComputeApi: undefined
const config: Partial<SASjsConfig> = {
useComputeApi: false
}
return await adapter.request('common/sendArr', stringData, config)

View File

@@ -0,0 +1,35 @@
import SASjs from '@sasjs/adapter'
import { TestSuite } from '@sasjs/test-framework'
export const fileUploadTests = (adapter: SASjs): TestSuite => ({
name: 'File Upload Tests',
tests: [
{
title: 'Upload File',
description: 'Should upload the file to VIYA',
test: async () => {
let blob: any = new Blob(['test'], { type: 'text/html' })
blob['lastModifiedDate'] = ''
blob['name'] = 'macvars_testfile'
let file = blob
const filesToUpload = [
{
file: file,
fileName: file.name
}
]
return adapter.uploadFile('common/sendMacVars', filesToUpload, null)
},
assertion: (response: any) =>
(response.macvars as any[]).findIndex(
(el: any) => el.NAME === '_WEBIN_FILE_COUNT' && el.VALUE === '1'
) > -1 &&
(response.macvars as any[]).findIndex(
(el: any) =>
el.NAME === '_WEBIN_FILENAME' && el.VALUE === 'macvars_testfile'
) > -1
}
]
})

View File

@@ -218,6 +218,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
const invalidData: any = {
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: [{ col1: 42 }]
}
return adapter.request('common/sendObj', invalidData).catch((e) => e)
},
assertion: (error: any) =>

View File

@@ -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
}
}
]
})