mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 15:13:07 +00:00
test(ops96-audit): extrair pins puros do municipalityUpdateCreateSchema para unit — zod sem Local API
This commit is contained in:
parent
adcfb39a49
commit
d8866d903f
2 changed files with 78 additions and 72 deletions
|
|
@ -10,7 +10,6 @@ import { beforeAll, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
import { createMunicipalityUpdateRecord } from '@/app/(campaign)/campanha/actions/municipalityUpdate'
|
import { createMunicipalityUpdateRecord } from '@/app/(campaign)/campanha/actions/municipalityUpdate'
|
||||||
import { MunicipalityUpdate } from '@/collections/MunicipalityUpdate'
|
import { MunicipalityUpdate } from '@/collections/MunicipalityUpdate'
|
||||||
import { municipalityUpdateCreateSchema } from '@/lib/schemas/municipalityUpdate'
|
|
||||||
import type { CampaignUser } from '@/payload-types'
|
import type { CampaignUser } from '@/payload-types'
|
||||||
import config from '@/payload.config'
|
import config from '@/payload.config'
|
||||||
import { acquireTextAdvisoryLocks } from '@/utilities/postgresTransactionLocks'
|
import { acquireTextAdvisoryLocks } from '@/utilities/postgresTransactionLocks'
|
||||||
|
|
@ -68,77 +67,6 @@ describe('campaign municipality update domain', () => {
|
||||||
payload = await getPayload({ config: await config })
|
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 () => {
|
it('enforces body and polarity validation through the Local API', async () => {
|
||||||
const coordinator = await campaignFixtures().createCampaignUser('coordinator')
|
const coordinator = await campaignFixtures().createCampaignUser('coordinator')
|
||||||
const municipality = await campaignFixtures().getMunicipality()
|
const municipality = await campaignFixtures().getMunicipality()
|
||||||
|
|
|
||||||
78
tests/unit/municipalityUpdateCreateSchema.unit.spec.ts
Normal file
78
tests/unit/municipalityUpdateCreateSchema.unit.spec.ts
Normal file
|
|
@ -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,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Reference in a new issue