teqo/tests/unit/campaignUserProfile.unit.spec.ts
Francisco Ignácio Fontoura Solla 0e4e6855dc Add the tooling gate: knip, CI, zero-warning lint, as-never ban
- knip (files/deps at error level; unused exports ledgered as warn) with
  config for Payload/Next entries; deleted the dead modules it confirmed:
  RecentlyVisited + UpcomingActionPlansCard + actionPlanUpcomingPreview,
  lazy-dialog helpers, tseZone, federalCandidateTotalsAggregate (test-only),
  unused ui kit files, one-shot rename script; pruned unused radix deps and
  typescript-eslint; added pg/@types/pg (pinned to drizzle's 8.10.2)
- GitHub Actions CI on the mirror: lint, typecheck, knip, unit, migrate, int
  against a Postgres 17 service
- eslint: unused-vars with ^_ ignore patterns (migrations args exempt),
  repo-wide ban on `as never` (no-restricted-syntax), lint gate at
  --max-warnings=0; fixed all 54 pre-existing warnings (dead imports,
  hooks deps, tracking-pixel img disable with impeccable config exception)
- tsconfig: include consolidated from 219 lines to 5 (wildcard covers all
  .next dist variants), noUnusedLocals on
- typed replacements for every as-never: hookFilledCreateData (actions
  create data completed by collection hooks), drizzle scopeColumn narrowing,
  tests' stub<T> helper (property-level checking kept, completeness waived)
- test infra: leased-consent generalization used by onda0 spec (shared
  leases over the stable consent keys; window race ledgered), purge fix
- docs: IMPROVE-CODE-QUALITY-PLAN.md tracker, TECH-DEBT.md ledger,
  TESTING.md safety-net map (package.json also gains the Phase 2
  build:election-aggregates script entry; the script lands next commit)
2026-07-23 23:06:12 -03:00

40 lines
1.1 KiB
TypeScript

// @vitest-environment node
import { describe, expect, it } from 'vitest'
import type { Media } from '@/payload-types'
import {
assertCampaignAvatarFile,
campaignUserInitials,
campaignUserShellView,
mediaDocumentUrl,
} from '@/utilities/campaignUserProfile'
import { stub } from '../helpers/stub'
describe('campaignUserProfile helpers', () => {
it('builds initials from the user name', () => {
expect(campaignUserInitials('Maria Silva')).toBe('MS')
expect(campaignUserInitials('João')).toBe('J')
})
it('builds shell view from a campaign user', () => {
expect(
campaignUserShellView({
name: 'Maria',
role: 'coordinator',
avatar: stub<Media>({ id: 1, url: 'https://example.com/a.jpg' }),
}),
).toEqual({
name: 'Maria',
role: 'coordinator',
avatarUrl: 'https://example.com/a.jpg',
})
expect(mediaDocumentUrl(42)).toBeNull()
})
it('rejects unsupported avatar mime types', () => {
const file = new File(['x'], 'avatar.gif', { type: 'image/gif' })
expect(() => assertCampaignAvatarFile(file)).toThrow(/JPEG, PNG ou WebP/)
})
})