test(f4): guard retired inspection fields
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { getMetadataArgsStorage, type QueryRunner } from 'typeorm';
|
||||
import { InspectionVisit } from '../../src/database/entities/inspection-visit.entity';
|
||||
import { F4RemoveInspectionLegacyFields1790000500000 } from '../../src/database/migrations/1790000500000-f4-remove-inspection-legacy-fields';
|
||||
|
||||
test('F4: InspectionVisit no vuelve a mapear title ni plannedEndAt', () => {
|
||||
const metadata = getMetadataArgsStorage();
|
||||
const columns = metadata.columns
|
||||
.filter((column) => column.target === InspectionVisit)
|
||||
.map((column) => column.propertyName);
|
||||
const indexes = metadata.indices
|
||||
.filter((index) => index.target === InspectionVisit)
|
||||
.map((index) => index.name);
|
||||
|
||||
assert.equal(columns.includes('title'), false);
|
||||
assert.equal(columns.includes('plannedEndAt'), false);
|
||||
assert.equal(columns.includes('plannedStartAt'), true);
|
||||
assert.equal(indexes.includes('idx_inspection_visits_planned_dates'), false);
|
||||
assert.equal(indexes.includes('idx_inspection_visits_planned_start_at'), true);
|
||||
});
|
||||
|
||||
test('F4: la migración retira las columnas legacy y conserva índice de inicio', async () => {
|
||||
const statements: string[] = [];
|
||||
const queryRunner = {
|
||||
query: async (sql: string) => {
|
||||
statements.push(sql.replace(/\s+/g, ' ').trim());
|
||||
return [];
|
||||
},
|
||||
} as unknown as QueryRunner;
|
||||
|
||||
await new F4RemoveInspectionLegacyFields1790000500000().up(queryRunner);
|
||||
const sql = statements.join('\n');
|
||||
|
||||
assert.match(sql, /DROP COLUMN IF EXISTS planned_end_at/i);
|
||||
assert.match(sql, /DROP COLUMN IF EXISTS title/i);
|
||||
assert.match(sql, /DROP CONSTRAINT IF EXISTS chk_inspection_visits_planned_dates/i);
|
||||
assert.match(sql, /CREATE INDEX IF NOT EXISTS idx_inspection_visits_planned_start_at/i);
|
||||
assert.doesNotMatch(sql, /CREATE INDEX IF NOT EXISTS idx_inspection_visits_planned_dates/i);
|
||||
});
|
||||
|
||||
test('F4: el rollback reconstruye la forma histórica de D1', async () => {
|
||||
const statements: string[] = [];
|
||||
const queryRunner = {
|
||||
query: async (sql: string) => {
|
||||
statements.push(sql.replace(/\s+/g, ' ').trim());
|
||||
return [];
|
||||
},
|
||||
} as unknown as QueryRunner;
|
||||
|
||||
await new F4RemoveInspectionLegacyFields1790000500000().down(queryRunner);
|
||||
const sql = statements.join('\n');
|
||||
|
||||
assert.match(sql, /ADD COLUMN IF NOT EXISTS title varchar\(200\)/i);
|
||||
assert.match(sql, /UPDATE inspection_visits SET title = code WHERE title IS NULL/i);
|
||||
assert.match(sql, /ALTER COLUMN title SET NOT NULL/i);
|
||||
assert.match(sql, /ADD COLUMN IF NOT EXISTS planned_end_at timestamptz/i);
|
||||
assert.match(sql, /ADD CONSTRAINT chk_inspection_visits_planned_dates CHECK/i);
|
||||
assert.match(sql, /CREATE INDEX IF NOT EXISTS idx_inspection_visits_planned_dates/i);
|
||||
});
|
||||
Reference in New Issue
Block a user