feat(mp): add Mercado Pago reauthorization notice and status card components
- Implemented MpReauthNotice component to notify users when reauthorization is needed. - Created MpStatusCard component to display the current status of the Mercado Pago account. - Added utility functions and constants for handling Mercado Pago status and messages. - Introduced hooks for managing the connection and disconnection of Mercado Pago accounts. - Developed a disconnect confirmation modal for user actions. - Added tests for the new functionality and utility functions. - Defined schemas for Mercado Pago account status and callback reasons in shared package.
This commit is contained in:
81
apps/web/test/mp-copy.test.ts
Normal file
81
apps/web/test/mp-copy.test.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
import {
|
||||
formatMpConnectionDate,
|
||||
mpCallbackErrorMessage,
|
||||
mpStatusBadgeVariant,
|
||||
mpStatusLabel,
|
||||
readMpCallbackFeedback,
|
||||
shouldShowMpReauthNotice,
|
||||
} from '../src/features/mp/copy'
|
||||
|
||||
/* El copy de Mercado Pago es la única fuente de la verdad de lo que el profesor
|
||||
lee, y el paso del onboarding, Ajustes y el aviso global lo comparten. */
|
||||
|
||||
describe('readMpCallbackFeedback', () => {
|
||||
test('lee el resultado de la vinculación desde la URL', () => {
|
||||
expect(readMpCallbackFeedback('success', undefined)).toEqual({ kind: 'success' })
|
||||
expect(readMpCallbackFeedback('error', 'mp_denied')).toEqual({
|
||||
kind: 'error',
|
||||
reason: 'mp_denied',
|
||||
})
|
||||
})
|
||||
|
||||
test('sin parámetros no hay nada que mostrar', () => {
|
||||
expect(readMpCallbackFeedback(undefined, undefined)).toBeNull()
|
||||
expect(readMpCallbackFeedback(undefined, 'mp_denied')).toBeNull()
|
||||
})
|
||||
|
||||
test('un motivo desconocido se degrada a un fallo genérico', () => {
|
||||
// Nunca se muestra en pantalla lo que venga en la URL: el backend manda el
|
||||
// código y esta función decide el texto.
|
||||
expect(readMpCallbackFeedback('error', 'stack trace')).toEqual({
|
||||
kind: 'error',
|
||||
reason: 'mp_error',
|
||||
})
|
||||
expect(readMpCallbackFeedback('error', undefined)).toEqual({
|
||||
kind: 'error',
|
||||
reason: 'mp_error',
|
||||
})
|
||||
expect(readMpCallbackFeedback('algo-distinto', 'mp_denied')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('mpCallbackErrorMessage', () => {
|
||||
test('cada motivo tiene su propio mensaje', () => {
|
||||
const reasons = ['invalid_state', 'mp_denied', 'mp_error', 'mp_account_in_use'] as const
|
||||
const messages = reasons.map(mpCallbackErrorMessage)
|
||||
|
||||
expect(new Set(messages).size).toBe(reasons.length)
|
||||
expect(messages.every((message) => message.length > 0)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('estado de la cuenta', () => {
|
||||
test('cada estado tiene su etiqueta y su color', () => {
|
||||
expect(mpStatusLabel('none')).toBe('Sin vincular')
|
||||
expect(mpStatusLabel('active')).toBe('Vinculada')
|
||||
expect(mpStatusLabel('requires_reauth')).toBe('Necesita vincularse de nuevo')
|
||||
|
||||
expect(mpStatusBadgeVariant('none')).toBe('neutral')
|
||||
expect(mpStatusBadgeVariant('active')).toBe('success')
|
||||
expect(mpStatusBadgeVariant('requires_reauth')).toBe('warning')
|
||||
})
|
||||
|
||||
test('solo requiere_reauth levanta el aviso global', () => {
|
||||
// "Sin vincular" es legítimo: el paso del onboarding es salteable.
|
||||
expect(shouldShowMpReauthNotice('requires_reauth')).toBe(true)
|
||||
expect(shouldShowMpReauthNotice('active')).toBe(false)
|
||||
expect(shouldShowMpReauthNotice('none')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatMpConnectionDate', () => {
|
||||
test('formatea la fecha de vinculación', () => {
|
||||
expect(formatMpConnectionDate('2026-10-05T12:00:00.000Z')).toMatch(/2026/)
|
||||
})
|
||||
|
||||
test('sin fecha o con una inválida no inventa nada', () => {
|
||||
expect(formatMpConnectionDate(null)).toBeNull()
|
||||
expect(formatMpConnectionDate('no-es-fecha')).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user