test: assert Survey execution DTOs are retired in F4

This commit is contained in:
2026-09-08 09:17:48 -03:00
parent 9fab773090
commit 792e21e669
+21 -39
View File
@@ -1,48 +1,30 @@
import 'reflect-metadata';
import assert from 'node:assert/strict'; import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test'; import test from 'node:test';
import { validate } from 'class-validator';
import { ReviewSurveyReportDto } from '../../src/survey-execution/dto/review-survey-report.dto';
import { SaveSurveyReportDto } from '../../src/survey-execution/dto/save-survey-report.dto';
const MEDIA_ID = '16e54e65-60cf-4739-b0d1-ccdd904fbfd5'; const root = process.cwd();
const migration = fs.readFileSync(
path.join(root, 'src/database/migrations/1790000300000-f4-remove-survey-subsystem.ts'),
'utf8',
);
test('field report DTO accepts outcome, GPS and protected media references', async () => { test('F4 removes Survey execution DTOs together with the retired endpoint surface', () => {
const dto = Object.assign(new SaveSurveyReportDto(), { assert.equal(fs.existsSync(path.join(root, 'src/survey-execution/dto/save-survey-report.dto.ts')), false);
outcome: 'CONFIRMED', assert.equal(fs.existsSync(path.join(root, 'src/survey-execution/dto/review-survey-report.dto.ts')), false);
observedAt: '2026-08-14T18:00:00.000Z',
latitude: -32.8895,
longitude: -68.8458,
accuracyM: 4.25,
notes: 'Activo verificado en campo.',
mediaIds: [MEDIA_ID],
});
assert.deepEqual(await validate(dto), []);
}); });
test('field report DTO rejects invalid coordinates and repeated evidence', async () => { test('F4 drops Survey report tables without CASCADE so unexpected dependencies stop migration', () => {
const dto = Object.assign(new SaveSurveyReportDto(), { assert.match(migration, /DROP TABLE IF EXISTS survey_target_report_versions/);
outcome: 'CONFIRMED', assert.match(migration, /DROP TABLE IF EXISTS survey_target_report_media/);
observedAt: 'not-a-date', assert.match(migration, /DROP TABLE IF EXISTS survey_target_reports/);
latitude: -95, assert.doesNotMatch(migration, /DROP TABLE IF EXISTS survey_target_reports CASCADE/);
longitude: -68.8458,
accuracyM: 4.25,
mediaIds: [MEDIA_ID, MEDIA_ID],
});
const properties = new Set((await validate(dto)).map((error) => error.property));
assert.equal(properties.has('observedAt'), true);
assert.equal(properties.has('latitude'), true);
assert.equal(properties.has('mediaIds'), true);
}); });
test('review DTO only accepts explicit approval or rejection decisions', async () => { test('F4 rollback can reconstruct the historical Survey report integrity rules', () => {
const dto = Object.assign(new ReviewSurveyReportDto(), { assert.match(migration, /CREATE TABLE IF NOT EXISTS survey_target_reports/);
decision: 'APPROVE', assert.match(migration, /outcome IN \('CONFIRMED','CHANGES_RECORDED','NOT_LOCATED'\)/);
notes: null, assert.match(migration, /latitude BETWEEN -90 AND 90/);
}); assert.match(migration, /longitude BETWEEN -180 AND 180/);
assert.deepEqual(await validate(dto), []); assert.match(migration, /CREATE TABLE IF NOT EXISTS survey_target_report_versions/);
dto.decision = 'MAYBE' as typeof dto.decision;
const properties = new Set((await validate(dto)).map((error) => error.property));
assert.equal(properties.has('decision'), true);
}); });