mirror of
https://github.com/sasjs/adapter.git
synced 2026-06-08 18:20:20 +00:00
fix(viya): stringify JES job arguments + sasjs-tests fixes
This commit is contained in:
@@ -72,7 +72,7 @@ export class TestCard extends HTMLElement {
|
|||||||
? `
|
? `
|
||||||
<div class="error">
|
<div class="error">
|
||||||
<strong>Error:</strong>
|
<strong>Error:</strong>
|
||||||
<pre>${(error as Error).message || String(error)}</pre>
|
<pre>${formatError(error)}</pre>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ''
|
: ''
|
||||||
@@ -110,4 +110,35 @@ export class TestCard extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const escapeHtml = (s: string) =>
|
||||||
|
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||||
|
|
||||||
|
const formatError = (err: unknown): string => {
|
||||||
|
if (err == null) return ''
|
||||||
|
if (typeof err === 'string') return escapeHtml(err)
|
||||||
|
|
||||||
|
const anyErr = err as any
|
||||||
|
// Adapter ErrorResponse: { error: { message, details, raw } }
|
||||||
|
const nestedMsg = anyErr?.error?.message
|
||||||
|
const directMsg = anyErr?.message
|
||||||
|
const msg = directMsg || nestedMsg
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
const details = anyErr?.error?.details ?? anyErr?.details
|
||||||
|
const detailsStr =
|
||||||
|
details && typeof details === 'object'
|
||||||
|
? `\n${JSON.stringify(details, null, 2)}`
|
||||||
|
: details
|
||||||
|
? `\n${details}`
|
||||||
|
: ''
|
||||||
|
return escapeHtml(`${msg}${detailsStr}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return escapeHtml(JSON.stringify(err, null, 2))
|
||||||
|
} catch {
|
||||||
|
return escapeHtml(String(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
customElements.define('test-card', TestCard)
|
customElements.define('test-card', TestCard)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
|||||||
title: 'Compute API request',
|
title: 'Compute API request',
|
||||||
description: 'Should run the request with compute API approach',
|
description: 'Should run the request with compute API approach',
|
||||||
test: async () => {
|
test: async () => {
|
||||||
return await adapter.request('common/sendArr', stringData)
|
return await adapter.request('services/common/sendArr', stringData)
|
||||||
},
|
},
|
||||||
assertion: (response: any) => {
|
assertion: (response: any) => {
|
||||||
return response.table1[0][0] === stringData.table1[0].col1
|
return response.table1[0][0] === stringData.table1[0].col1
|
||||||
@@ -25,7 +25,11 @@ export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
|||||||
useComputeApi: false
|
useComputeApi: false
|
||||||
}
|
}
|
||||||
|
|
||||||
return await adapter.request('common/sendArr', stringData, config)
|
return await adapter.request(
|
||||||
|
'services/common/sendArr',
|
||||||
|
stringData,
|
||||||
|
config
|
||||||
|
)
|
||||||
},
|
},
|
||||||
assertion: (response: any) => {
|
assertion: (response: any) => {
|
||||||
return response.table1[0][0] === stringData.table1[0].col1
|
return response.table1[0][0] === stringData.table1[0].col1
|
||||||
@@ -36,7 +40,10 @@ export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
|||||||
description: 'Should start a compute job and return the session',
|
description: 'Should start a compute job and return the session',
|
||||||
test: () => {
|
test: () => {
|
||||||
const data: any = { table1: [{ col1: 'first col value' }] }
|
const data: any = { table1: [{ col1: 'first col value' }] }
|
||||||
return adapter.startComputeJob(`${appLoc}/common/sendArr`, data)
|
return adapter.startComputeJob(
|
||||||
|
`${appLoc}/services/common/sendArr`,
|
||||||
|
data
|
||||||
|
)
|
||||||
},
|
},
|
||||||
assertion: (res: any) => {
|
assertion: (res: any) => {
|
||||||
const expectedProperties = ['id', 'applicationName', 'attributes']
|
const expectedProperties = ['id', 'applicationName', 'attributes']
|
||||||
@@ -49,7 +56,7 @@ export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
|||||||
test: () => {
|
test: () => {
|
||||||
const data: any = { table1: [{ col1: 'first col value' }] }
|
const data: any = { table1: [{ col1: 'first col value' }] }
|
||||||
return adapter.startComputeJob(
|
return adapter.startComputeJob(
|
||||||
`${appLoc}/common/sendArr`,
|
`${appLoc}/services/common/sendArr`,
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
undefined,
|
undefined,
|
||||||
|
|||||||
@@ -1031,11 +1031,17 @@ export class SASViyaApiClient {
|
|||||||
jobArguments[`_webin_name${index + 1}`] = fileInfo.tableName
|
jobArguments[`_webin_name${index + 1}`] = fileInfo.tableName
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Viya JES requires arguments to be Map<String,String>; coerce booleans/numbers.
|
||||||
|
const stringifiedArguments: { [key: string]: string } = {}
|
||||||
|
for (const k of Object.keys(jobArguments)) {
|
||||||
|
stringifiedArguments[k] = String(jobArguments[k])
|
||||||
|
}
|
||||||
|
|
||||||
const postJobRequestBody = {
|
const postJobRequestBody = {
|
||||||
name: `exec-${jobName}`,
|
name: `exec-${jobName}`,
|
||||||
description: 'Powered by SASjs',
|
description: 'Powered by SASjs',
|
||||||
jobDefinition,
|
jobDefinition,
|
||||||
arguments: jobArguments
|
arguments: stringifiedArguments
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result: postedJob } = await this.requestClient.post<Job>(
|
const { result: postedJob } = await this.requestClient.post<Job>(
|
||||||
|
|||||||
Reference in New Issue
Block a user