diff --git a/api-v3/test/unit/survey-planning-dto.test.ts b/api-v3/test/unit/survey-planning-dto.test.ts index 4df9a52..7bea745 100644 --- a/api-v3/test/unit/survey-planning-dto.test.ts +++ b/api-v3/test/unit/survey-planning-dto.test.ts @@ -1,35 +1,31 @@ -import 'reflect-metadata'; import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import path from 'node:path'; import test from 'node:test'; -import { validate } from 'class-validator'; -import { AddSurveyTargetDto } from '../../src/survey-planning/dto/add-survey-target.dto'; -import { CreateSurveyCampaignDto } from '../../src/survey-planning/dto/create-survey-campaign.dto'; -const ASSET_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('campaign DTO accepts dynamic asset scope and ISO planning dates', async () => { - const dto = Object.assign(new CreateSurveyCampaignDto(), { - code: 'REL-2026-001', - name: 'CampaƱa operativa', - description: null, - plannedStartAt: '2026-08-15T12:00:00.000Z', - plannedEndAt: '2026-08-20T12:00:00.000Z', - scopeAssetId: ASSET_ID, - coordinatorUserId: null, - }); - assert.deepEqual(await validate(dto), []); +test('F4 removes Survey planning DTOs from the active code surface', () => { + assert.equal(fs.existsSync(path.join(root, 'src/survey-planning/dto/create-survey-campaign.dto.ts')), false); + assert.equal(fs.existsSync(path.join(root, 'src/survey-planning/dto/add-survey-target.dto.ts')), false); }); -test('target DTO references an existing Maestro asset instead of copying it', async () => { - const dto = Object.assign(new AddSurveyTargetDto(), { - assetId: ASSET_ID, - assignedUserId: null, - dueAt: null, - instructions: null, - }); - assert.deepEqual(await validate(dto), []); +test('F4 drops Survey planning tables after removing their permissions', () => { + assert.match(migration, /DELETE FROM permissions/); + assert.match(migration, /DROP TABLE IF EXISTS survey_campaign_targets/); + assert.match(migration, /DROP TABLE IF EXISTS survey_campaigns/); + assert.doesNotMatch(migration, /DROP TABLE IF EXISTS survey_campaigns CASCADE/); +}); - dto.assetId = 'not-a-uuid'; - const properties = new Set((await validate(dto)).map((error) => error.property)); - assert.equal(properties.has('assetId'), true); +test('F4 rollback can reconstruct historical Survey planning dates and asset references', () => { + assert.match(migration, /CREATE TABLE IF NOT EXISTS survey_campaigns/); + assert.match(migration, /planned_start_at timestamptz/); + assert.match(migration, /planned_end_at timestamptz/); + assert.match(migration, /scope_asset_id uuid REFERENCES assets\(id\) ON DELETE RESTRICT/); + assert.match(migration, /CREATE TABLE IF NOT EXISTS survey_campaign_targets/); + assert.match(migration, /asset_id uuid NOT NULL REFERENCES assets\(id\) ON DELETE RESTRICT/); });