From d8866d903feae17f7436afe55bf725689a13f0ac Mon Sep 17 00:00:00 2001 From: Francisco Solla Date: Tue, 25 Aug 2026 14:01:15 -0300 Subject: [PATCH] =?UTF-8?q?test(ops96-audit):=20extrair=20pins=20puros=20d?= =?UTF-8?q?o=20municipalityUpdateCreateSchema=20para=20unit=20=E2=80=94=20?= =?UTF-8?q?zod=20sem=20Local=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../campaignMunicipalityUpdate.int.spec.ts | 72 ----------------- ...unicipalityUpdateCreateSchema.unit.spec.ts | 78 +++++++++++++++++++ 2 files changed, 78 insertions(+), 72 deletions(-) create mode 100644 tests/unit/municipalityUpdateCreateSchema.unit.spec.ts diff --git a/tests/int/campaignMunicipalityUpdate.int.spec.ts b/tests/int/campaignMunicipalityUpdate.int.spec.ts index f1f0ac3e..fe1b6773 100644 --- a/tests/int/campaignMunicipalityUpdate.int.spec.ts +++ b/tests/int/campaignMunicipalityUpdate.int.spec.ts @@ -10,7 +10,6 @@ import { beforeAll, describe, expect, it, vi } from 'vitest' import { createMunicipalityUpdateRecord } from '@/app/(campaign)/campanha/actions/municipalityUpdate' import { MunicipalityUpdate } from '@/collections/MunicipalityUpdate' -import { municipalityUpdateCreateSchema } from '@/lib/schemas/municipalityUpdate' import type { CampaignUser } from '@/payload-types' import config from '@/payload.config' import { acquireTextAdvisoryLocks } from '@/utilities/postgresTransactionLocks' @@ -68,77 +67,6 @@ describe('campaign municipality update domain', () => { payload = await getPayload({ config: await config }) }) - it('requires body and polarity and accepts urgent and adversary flags', () => { - expect( - municipalityUpdateCreateSchema.safeParse({ - municipality: 1, - polarity: 'neutra', - body: 'Mobilização na feira', - }).success, - ).toBe(true) - expect( - municipalityUpdateCreateSchema.safeParse({ - municipality: 1, - body: 'Sem polaridade', - }).success, - ).toBe(false) - expect( - municipalityUpdateCreateSchema.safeParse({ - municipality: 1, - polarity: 'ruim', - urgent: true, - body: 'Precisamos responder hoje.', - }).success, - ).toBe(true) - expect( - municipalityUpdateCreateSchema.safeParse({ - municipality: 1, - polarity: 'neutra', - body: ' ', - }).success, - ).toBe(false) - expect( - municipalityUpdateCreateSchema.safeParse({ - municipality: 1, - polarity: 'ruim', - body: 'Ex-prefeito retirou o apoio na feira.', - }).success, - ).toBe(true) - expect( - municipalityUpdateCreateSchema.safeParse({ - municipality: 1, - polarity: 'invalid', - body: 'Visita adversária confirmada.', - }).success, - ).toBe(false) - expect( - municipalityUpdateCreateSchema.safeParse({ - municipality: 1, - polarity: 'ruim', - adversarySignal: true, - }).success, - ).toBe(false) - }) - - it('strips forged author and timestamps from input', () => { - const parsed = municipalityUpdateCreateSchema.parse({ - municipality: 1, - polarity: 'neutra', - body: 'Registro de campo', - author: 999, - createdAt: '2000-01-01T00:00:00.000Z', - updatedAt: '2000-01-01T00:00:00.000Z', - }) - - expect(parsed).toEqual({ - municipality: 1, - polarity: 'neutra', - body: 'Registro de campo', - urgent: false, - adversarySignal: false, - }) - }) - it('enforces body and polarity validation through the Local API', async () => { const coordinator = await campaignFixtures().createCampaignUser('coordinator') const municipality = await campaignFixtures().getMunicipality() diff --git a/tests/unit/municipalityUpdateCreateSchema.unit.spec.ts b/tests/unit/municipalityUpdateCreateSchema.unit.spec.ts new file mode 100644 index 00000000..0de241e5 --- /dev/null +++ b/tests/unit/municipalityUpdateCreateSchema.unit.spec.ts @@ -0,0 +1,78 @@ +// @vitest-environment node + +import { describe, expect, it } from 'vitest' + +import { municipalityUpdateCreateSchema } from '@/lib/schemas/municipalityUpdate' + +describe('municipalityUpdateCreateSchema', () => { + it('requires body and polarity and accepts urgent and adversary flags', () => { + expect( + municipalityUpdateCreateSchema.safeParse({ + municipality: 1, + polarity: 'neutra', + body: 'Mobilização na feira', + }).success, + ).toBe(true) + expect( + municipalityUpdateCreateSchema.safeParse({ + municipality: 1, + body: 'Sem polaridade', + }).success, + ).toBe(false) + expect( + municipalityUpdateCreateSchema.safeParse({ + municipality: 1, + polarity: 'ruim', + urgent: true, + body: 'Precisamos responder hoje.', + }).success, + ).toBe(true) + expect( + municipalityUpdateCreateSchema.safeParse({ + municipality: 1, + polarity: 'neutra', + body: ' ', + }).success, + ).toBe(false) + expect( + municipalityUpdateCreateSchema.safeParse({ + municipality: 1, + polarity: 'ruim', + body: 'Ex-prefeito retirou o apoio na feira.', + }).success, + ).toBe(true) + expect( + municipalityUpdateCreateSchema.safeParse({ + municipality: 1, + polarity: 'invalid', + body: 'Visita adversária confirmada.', + }).success, + ).toBe(false) + expect( + municipalityUpdateCreateSchema.safeParse({ + municipality: 1, + polarity: 'ruim', + adversarySignal: true, + }).success, + ).toBe(false) + }) + + it('strips forged author and timestamps from input', () => { + const parsed = municipalityUpdateCreateSchema.parse({ + municipality: 1, + polarity: 'neutra', + body: 'Registro de campo', + author: 999, + createdAt: '2000-01-01T00:00:00.000Z', + updatedAt: '2000-01-01T00:00:00.000Z', + }) + + expect(parsed).toEqual({ + municipality: 1, + polarity: 'neutra', + body: 'Registro de campo', + urgent: false, + adversarySignal: false, + }) + }) +})