Files
dc/sas/mocks/test/mock-settings.test.js
T
dc 3bb9fb52e3
Build / Build-and-ng-test (pull_request) Successful in 4m28s
Lighthouse Checks / lighthouse (pull_request) Successful in 8m24s
Build / Build-and-test-development (pull_request) Canceled after 10m4s
fix(mocks): make getdata and viewlibs answer what the estate answers
The two scenarios recorded in the previous commit are now gated, with one
declared difference each instead of 388 and 4. The diffs were the mock's, and
they are fixed rather than accepted:

- cols: dropped the DESC key SAS never emits, and took LABEL/LONGDESC from the
  MPE_DATADICTIONARY rows for this lib.ds.column, as getdata.sas augments
  mp_getcols. COLTYPE is blank for DATE/DATETIME/TIME, which is what the estate
  answers.
- sasdata: sorted by the business key; character values trimmed the way the
  JSON writer writes them, with an all-blank value as a single space.
- dqrules: the active MPE_VALIDATIONS rows unioned with the schema's NOTNULL
  (limited to the columns left in the selection, which is why a NOT NULL on
  tx_from never reached the grid) and the derived columns' READONLY, then
  de-duplicated and sorted by column and rule type with X left at the missing
  value - getdata.sas's union/sort/by-group logic.
- sasparams: the current-rows clause mpe_filtermaster appends, and blank
  character values as the single space SAS sends.
- maxvarlengths: the value as stored (trimmed), and the key columns in upper
  case, which is how the selection spells them.
- approvers: computed from MPE_SECURITY's APPROVE rows with the admin group as
  the fallback, instead of a hardcoded sasdemo.
- viewlibs: the shape %mp_getlibs answers - engine in LIBRARYID, blank ENGINE,
  libref as LIBRARYNAME.

The control library and the admin group now come from services/settings.js
through dcInit(), which is the mock's %mpe_init(): makedata already writes
dc_libref, dc_admin_group and dcpath there, so a deployment with a different
DCPATH no longer needs a service change. test/mock-settings.test.js proves it by
renaming the library and moving the data. The remaining services still carry
const dcLibref = 'DC_JSLIB' and compute paths from it at file scope, so each is
a separate change.

The sas9 mock keeps its own getdata/viewlibs variant, so it is untouched: the
goldens are recorded from the SASjs Server estate.
2026-11-07 00:31:16 +00:00

67 lines
2.5 KiB
JavaScript

/**
* The settings program is the mock's %mpe_init(): makedata writes
* services/settings.js with the control library, the admin group and dcpath,
* and every service reads them from there rather than from a constant - so a
* deployment that puts the library elsewhere needs no service change.
*
* These pin the two services that read it today. The rest of the estate still
* carries `const dcLibref = 'DC_JSLIB'`; each computes paths from it at file
* scope, so converting them is a per-service change rather than a sweep.
*/
const test = require('node:test')
const assert = require('node:assert')
const fs = require('fs')
const path = require('path')
const { seededEstate, runService } = require('./harness')
function rewriteSettings(estate, libref, adminGroup) {
const file = path.join(estate.appDir, 'services', 'settings.js')
const settings = {
dc_libref: libref,
dc_admin_group: adminGroup,
dc_staging_area: path.join(estate.appDir, 'data', libref, 'dc_staging'),
dc_macros: path.join(estate.appDir, 'data', libref, 'dc_macros'),
mpelib: libref,
dcpath: path.join(estate.appDir, 'data', libref)
}
fs.writeFileSync(file, 'var dcSettings = ' + JSON.stringify(settings) + '\n')
}
test('viewlibs lists the library the settings file names', () => {
const estate = seededEstate({ demo: false })
const before = JSON.parse(runService(estate, 'public/viewlibs', {})).saslibs
assert.ok(
before.some((row) => row.LIBRARYREF === 'DC_JSLIB'),
'the seeded estate names its control library'
)
rewriteSettings(estate, 'DC7QATEST', 'dc-admin')
const after = JSON.parse(runService(estate, 'public/viewlibs', {})).saslibs
assert.ok(
after.some((row) => row.LIBRARYREF === 'DC7QATEST'),
'viewlibs follows the settings file rather than a constant'
)
})
test('getdata reads its table from the library the settings file names', () => {
const estate = seededEstate({ demo: false })
// move the control library's data files to the new libref, as a deployment
// with a different DCPATH would
const from = path.join(estate.appDir, 'data', 'DC_JSLIB')
const to = path.join(estate.appDir, 'data', 'DC7QATEST')
fs.cpSync(from, to, { recursive: true })
rewriteSettings(estate, 'DC7QATEST', 'dc-admin')
const body = JSON.parse(
runService(estate, 'editors/getdata', {
tableName: 'SASControlTable',
rows: [{ LIBDS: 'DC7QATEST.MPE_TABLES', FILTER_RK: -1 }]
})
)
assert.equal(body.sasjsAbort, undefined)
assert.ok(body.sasdata.length > 0, 'the table was found in the new library')
})