diff --git a/src/app/(campaign)/campanha/actions/municipality.ts b/src/app/(campaign)/campanha/actions/municipality.ts index 43ad5f00..44033b17 100644 --- a/src/app/(campaign)/campanha/actions/municipality.ts +++ b/src/app/(campaign)/campanha/actions/municipality.ts @@ -3,6 +3,7 @@ import type { Payload } from 'payload' import { + ENGAGEMENT_LEVEL_NO_RATIONALE_LABEL, ENGAGEMENT_LEVEL_PATTERN_ID, EngagementLevelBlockedError, getEngagementLevelViolations, @@ -205,7 +206,7 @@ export const setMunicipalityEngagementLevelRecord = async ( municipality, patternId: ENGAGEMENT_LEVEL_PATTERN_ID, outcome: 'movimento', - rationale: levelNote ?? '', + rationale: levelNote?.trim() ? levelNote : ENGAGEMENT_LEVEL_NO_RATIONALE_LABEL, // Only the values the decision was taken on — no document dumps // (the collection caps the serialized snapshot at 16 KB). snapshot: { diff --git a/src/lib/engagementLevel.ts b/src/lib/engagementLevel.ts index cd93387c..30ea4f0c 100644 --- a/src/lib/engagementLevel.ts +++ b/src/lib/engagementLevel.ts @@ -19,6 +19,9 @@ export const ENGAGEMENT_LEVEL_PATTERN_ID = 'nivel' /** Cap shared by the field, the schema and the textareas, so they agree. */ export const ENGAGEMENT_LEVEL_TEXT_MAX_LENGTH = 2000 +/** Filed on `allocationDecision.rationale` when the coordinator omits a motivo (B134). */ +export const ENGAGEMENT_LEVEL_NO_RATIONALE_LABEL = 'Sem justificativa registrada.' + export type EngagementLevel = (typeof engagementLevels)[number] /** diff --git a/tests/int/campaignMunicipalityEngagementLevel.int.spec.ts b/tests/int/campaignMunicipalityEngagementLevel.int.spec.ts index 242b9e35..a2fc9544 100644 --- a/tests/int/campaignMunicipalityEngagementLevel.int.spec.ts +++ b/tests/int/campaignMunicipalityEngagementLevel.int.spec.ts @@ -84,7 +84,7 @@ describe('municipality engagement level (E14)', () => { const decision = decisions.docs[0]! fixtures.own('allocationDecision', decision.id) - expect(decision.rationale).toBe('') + expect(decision.rationale).toBe('Sem justificativa registrada.') expect(decision.snapshot).toMatchObject({ from: null, to: 'n1',