import { describe, expect, it } from 'vitest' import { TECHNICAL_INDEX_COLUMNS, isTenantColumn, knownIndexColumns } from '../entity-columns.js' // The ONE definition of « which columns an index may name », imported by // scaffold-entity/validate.ts (dev time, hard error) and audit-ba DM-023 (BA // time, the same error six phases earlier). Pin the set so the two cannot drift. describe('lib/entity-columns — knownIndexColumns', () => { it('is the union of fields ∪ owning FKs ∪ extra ∪ code-when-coded ∪ technical, lower-cased', () => { const set = knownIndexColumns({ fields: ['Name', 'Amount'], owningFks: ['ClientId'], extra: ['OwnerUserId'], coded: true, }) expect([...set].sort()).toEqual(['amount', 'clientid', 'code', 'createdat', 'name', 'owneruserid', 'tenantid']) }) it('adds `code` ONLY on a coded entity', () => { expect(knownIndexColumns({ fields: [], owningFks: [], coded: false }).has('code')).toBe(false) expect(knownIndexColumns({ fields: [], owningFks: [], coded: true }).has('code')).toBe(true) }) it('technical columns are exactly TenantId + CreatedAt — never Id/UpdatedAt/DeletedAt (an index on them is nonsense the scaffolder never accepted)', () => { expect([...TECHNICAL_INDEX_COLUMNS]).toEqual(['TenantId', 'CreatedAt']) const set = knownIndexColumns({ fields: [], owningFks: [], coded: false }) expect(set.has('id')).toBe(false) expect(set.has('updatedat')).toBe(false) }) it('isTenantColumn is casing-agnostic', () => { expect(isTenantColumn('TenantId')).toBe(true) expect(isTenantColumn(' tenantid ')).toBe(true) expect(isTenantColumn('Tenant')).toBe(false) }) })