66 lines
2.6 KiB
JavaScript
66 lines
2.6 KiB
JavaScript
// Generated, do not edit. sha256:fefc7c108aded894b1e2af3e5fbbedc3eac1b26a65f9c5ddfd7154896dda96a0
|
|
import { describe, it, before } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { openBaselineDb } from '../helpers/baseline-db.mjs';
|
|
import { CONFIG } from '../../shared/config.js';
|
|
|
|
const EIGEN_ONTSTAAN = {
|
|
ScanLog: 'scannedAt',
|
|
ReconcileProposal: 'detectedAt',
|
|
ImportBatch: 'importedAt',
|
|
AiToolCall: 'occurredAt',
|
|
AiToolCallMessage: 'occurredAt',
|
|
BusSignal: 'occurredAt',
|
|
ChangeLog: 'occurredAt',
|
|
IntegrationCall: 'occurredAt',
|
|
};
|
|
const GEEN_RIJ_IDENTITEIT = ['ApiCallMetric', 'Schema'];
|
|
|
|
let KOLOMMEN;
|
|
|
|
before(() => {
|
|
const db = openBaselineDb();
|
|
KOLOMMEN = {};
|
|
for (const t of CONFIG.DB_TABLES) {
|
|
KOLOMMEN[t] = db.prepare(`PRAGMA table_info(${t})`).all().map(k => k.name);
|
|
}
|
|
db.close();
|
|
});
|
|
|
|
describe('tijdstempels: createdAt waar het ontstaan nog nergens staat', () => {
|
|
it('geeft elke tabel een createdAt, op de vrijgestelde na', () => {
|
|
const missend = CONFIG.DB_TABLES.filter(t =>
|
|
!(t in EIGEN_ONTSTAAN) && !GEEN_RIJ_IDENTITEIT.includes(t) && !KOLOMMEN[t].includes('createdAt'));
|
|
assert.deepEqual(missend, [],
|
|
'een nieuwe tabel hoort een createdAt te krijgen, of een gemotiveerde vrijstelling hierboven');
|
|
});
|
|
|
|
it('houdt de vrijgestelde tabellen vrij, want anders staan er twee namen voor hetzelfde moment', () => {
|
|
for (const [tabel, kolom] of Object.entries(EIGEN_ONTSTAAN)) {
|
|
assert.ok(KOLOMMEN[tabel].includes(kolom), `${tabel} zou zijn ontstaan in ${kolom} bewaren`);
|
|
assert.ok(!KOLOMMEN[tabel].includes('createdAt'),
|
|
`${tabel} heeft ${kolom} én createdAt: dat is een tweede waarheid over hetzelfde moment`);
|
|
}
|
|
for (const tabel of GEEN_RIJ_IDENTITEIT) {
|
|
assert.ok(!KOLOMMEN[tabel].includes('createdAt'), `${tabel} heeft geen rij om een moment aan te hangen`);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('tijdstempels: updatedAt waar een wijziging betekenis heeft', () => {
|
|
it('geeft elke getrackte tabel een updatedAt', () => {
|
|
const missend = CONFIG.DB_HISTORY.TRACKED.filter(t => !KOLOMMEN[t].includes('updatedAt'));
|
|
assert.deepEqual(missend, [],
|
|
'een tabel die meedoet in het wijzigingslogboek hoort te kunnen zeggen wanneer hij wijzigde');
|
|
});
|
|
|
|
it('geeft hem NIET aan een tabel waar niemand die vraag stelt', () => {
|
|
const teveel = CONFIG.DB_TABLES.filter(t =>
|
|
!CONFIG.DB_HISTORY.TRACKED.includes(t) && t !== 'PriceHistory'
|
|
&& t !== 'DashboardProfile' && KOLOMMEN[t].includes('updatedAt'));
|
|
assert.deepEqual(teveel, [],
|
|
'updatedAt op een tabel die niet meedoet: die kolom blijft per definitie leeg');
|
|
});
|
|
});
|