Files
gruperly/apps/web/test/billing-copy.test.ts
Jose Selesan 58c776e18c feat(groups): kids groups with an adult in charge
- Add the `kidsGroups` plan feature (Pro) and `Group.audience` (ADULTS | KIDS);
  creating or switching a group to KIDS requires the feature, existing KIDS
  groups keep working after a downgrade.
- Model the adult in charge as a Person linked through `person_guardians`;
  migrate the old guardian_name/guardian_phone columns and drop them.
- Kids quick add: kid + guardian form, guardian lookup by phone to pick an
  existing kid or add a sibling; backend rejects KIDS adds without guardian.
- Attendee page: "Adulto a cargo" section with siblings, editable via
  PATCH /groups/:gid/attendees/:aid/guardian.
- Contact phone (WhatsApp jobs, attention, student access invite, students at
  risk, attendee actions) prefers the guardian's phone.
- Edit group screen (PATCH /groups/:gid, owner only); switching back to ADULTS
  is blocked while kids have no phone of their own.
- Hide bulk import in KIDS groups until it carries guardian data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 13:27:13 -03:00

87 lines
3.5 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import type { BillingStatusDto } from '@gruperly/shared'
import { PLAN_LIMITS } from '@gruperly/shared'
import {
formatUsage,
hasPlanFeature,
isPlanProblem,
planBadgeVariant,
planFeatureList,
planNoticeMessage,
subscriptionStatusLabel,
} from '../src/features/billing/copy'
function status(overrides: Partial<BillingStatusDto> = {}): BillingStatusDto {
return {
plan: 'FREE',
status: null,
readOnly: false,
graceUntil: null,
paidThrough: null,
nextPaymentDate: null,
payerEmail: null,
priceAmount: 15000,
currency: 'ARS',
country: 'AR',
availableInCountry: true,
enforced: true,
usage: { groups: 1, attendees: 3 },
limits: PLAN_LIMITS.FREE,
...overrides,
}
}
/* El copy del plan lo comparten Ajustes, /billing, el onboarding y los avisos. */
describe('copy del plan', () => {
test('lista lo que incluye cada plan', () => {
expect(planFeatureList(PLAN_LIMITS.FREE)).toEqual([
{ label: '1 grupo', included: true },
{ label: 'Hasta 15 alumnos activos', included: true },
{ label: 'Cobros con Mercado Pago', included: false },
{ label: 'Mensajes automáticos por WhatsApp', included: false },
{ label: 'Grupos de chicos con adulto a cargo', included: false },
])
expect(planFeatureList(PLAN_LIMITS.PRO).every((feature) => feature.included)).toBe(true)
})
test('muestra el uso contra el límite', () => {
expect(formatUsage(3, 15)).toBe('3 de 15')
expect(formatUsage(42, null)).toBe('42')
})
test('nombra cada estado de la suscripción', () => {
expect(subscriptionStatusLabel('AUTHORIZED')).toBe('Activa')
expect(subscriptionStatusLabel('PENDING')).toBe('Pendiente de pago')
expect(subscriptionStatusLabel(null)).toBe('Sin suscripción')
})
test('avisa solo lectura antes que gracia', () => {
expect(planNoticeMessage(status())).toBeNull()
expect(planNoticeMessage(status({ readOnly: true }))?.tone).toBe('danger')
expect(planNoticeMessage(status({ plan: 'PRO', status: 'AUTHORIZED', graceUntil: '2026-11-01T00:00:00.000Z' }))?.tone).toBe('warning')
expect(planBadgeVariant(status({ readOnly: true }))).toBe('danger')
expect(planBadgeVariant(status({ plan: 'PRO', limits: PLAN_LIMITS.PRO }))).toBe('success')
})
test('el aviso de gracia distingue la cancelación de un cobro rechazado', () => {
const graceUntil = '2026-11-01T12:00:00.000Z'
expect(planNoticeMessage(status({ plan: 'PRO', status: 'CANCELLED', graceUntil }))?.text).toContain('Cancelaste Pro')
expect(planNoticeMessage(status({ plan: 'PRO', status: 'AUTHORIZED', graceUntil }))?.text).toContain('No pudimos cobrar')
})
test('deja pasar las funciones sin datos o sin límites aplicados', () => {
expect(hasPlanFeature(undefined, 'mpCharges')).toBe(true)
expect(hasPlanFeature(status({ enforced: false }), 'mpCharges')).toBe(true)
expect(hasPlanFeature(status(), 'mpCharges')).toBe(false)
expect(hasPlanFeature(status({ limits: PLAN_LIMITS.PRO }), 'whatsappAutomations')).toBe(true)
})
test('reconoce un 402 de plan y nada más', () => {
expect(isPlanProblem({ status: 402, problem: { code: 'plan_limit_reached' } })).toBe(true)
expect(isPlanProblem({ status: 402, problem: { code: 'otra_cosa' } })).toBe(false)
expect(isPlanProblem({ status: 409, problem: { code: 'plan_limit_reached' } })).toBe(false)
expect(isPlanProblem(new Error('x'))).toBe(false)
expect(isPlanProblem(null)).toBe(false)
})
})