33 lines
2.3 KiB
JavaScript
33 lines
2.3 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { buildFleetInventorySql, fleetInventoryFromRows } from './fleet-inventory-evidence.mjs'
|
|
import { assertReadOnlySql, createTestEvidenceReaders } from './fba-core-regression-evidence.mjs'
|
|
|
|
const scope = { marker: 'CROSS-TEST-1', customerId: '2106128532165988353', warehouseId: '193000000000200003' }
|
|
const empty = () => ['balances', 'positions', 'ledger'].map(collection => ({ collection, count: '0' }))
|
|
test('customer/warehouse snapshot includes zero rows and all ledger kinds in a single read-only transaction', () => {
|
|
const sql = assertReadOnlySql(buildFleetInventorySql(scope))
|
|
assert.equal((sql.match(/SELECT JSON_OBJECT/g) || []).length, 6)
|
|
assert.doesNotMatch(sql, /\bLIMIT\b|available_packages\s*>|business_type\s*=/)
|
|
assert.match(sql, /'deltaPackages',CAST\(delta_packages AS CHAR\)/)
|
|
assert.match(sql, /'version',CAST\(version AS CHAR\)/)
|
|
assert.equal((sql.match(/BINARY customer_id=/g) || []).length, 6)
|
|
assert.equal((sql.match(/BINARY overseas_warehouse_id=/g) || []).length, 6)
|
|
assert.equal(fleetInventoryFromRows(scope, empty()).scope.coverage, 'CUSTOMER_WAREHOUSE_COMPLETE')
|
|
})
|
|
test('rejects missing count, truncation, duplicate count, foreign or incomplete rows', () => {
|
|
for (const rows of [[], empty().slice(1), [...empty(), empty()[0]], [...empty(), { collection: 'balances', row: { id: '1', customerId: 'wrong' } }], [{ collection: 'balances', count: '1' }, ...empty().slice(1)]]) {
|
|
assert.throws(() => fleetInventoryFromRows(scope, rows))
|
|
}
|
|
for (const changed of [{ customerId: '1 OR 1=1' }, { warehouseId: 193000000000200003 }, { marker: "';DROP" }]) assert.throws(() => buildFleetInventorySql({ ...scope, ...changed }))
|
|
})
|
|
test('transport integration uses the existing secret-safe TEST reader', async () => {
|
|
let requests = 0
|
|
const reader = createTestEvidenceReaders({ JENKINS_URL: 'https://ci.example.invalid/', JENKINS_USER: 'test', JENKINS_API_TOKEN: 'secret', FBA_CORE_JENKINS_AGENT: 'java-test-agent' }, async (_url, options) => {
|
|
requests++; assert.equal(options.method, 'POST')
|
|
return { ok: true, text: async () => 'FBA_CORE_JSON=' + JSON.stringify({ ok: true, rows: empty() }) }
|
|
})
|
|
assert.deepEqual((await reader.readFleetInventory(scope)).balances, [])
|
|
assert.equal(requests, 1)
|
|
})
|