Sustituye el envío de push por la API legacy de GCM (muerta desde jun-2024) y saca el envío del observer de Meteor a una cola BullMQ controlada. - poller: consume 'notifications' pendientes (campos correctos; el cron viejo tenía un typo nofitied/emailNofitied que nunca casaba) - fcm-worker: firebase-admin (FCM HTTP v1), payload compatible con la app Flutter (FLUTTER_NOTIFICATION_CLICK, collapseKey=_id, data); purga tokens muertos sin reintentar - email-worker: nodemailer + plantillas new-fire portadas verbatim - idempotencia persistente: notification_sends, indice unico (notificationId, channel) -> sobrevive reinicios y replays - salvaguardas anti-spam: modos dry-run/shadow/canary/full, exclusion mutua por canal (OWNED_CHANNELS + notifDisabledChannels en Meteor), kill switch, limites por usuario/dia y circuit breaker por batch - docs/legacy-behavior.md (caracterizacion) + docs/rollout.md - 47 tests (vitest + mongodb-memory-server), typecheck y build OK - deploy: systemd + pm2 (Node 22 standalone) Falta el service account de Firebase para envio real de push (pedir al usuario).
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { ObjectId } from 'mongodb';
|
|
import { renderEmail } from '../src/mailer.js';
|
|
import { buildEmail } from '../src/messages.js';
|
|
import type { NotificationDoc } from '../src/types.js';
|
|
|
|
const notif: NotificationDoc = {
|
|
_id: new ObjectId(),
|
|
userId: 'u1',
|
|
content: '🔥 Incendio en Ourense:',
|
|
geo: { type: 'Point', coordinates: [-7.86, 42.34] },
|
|
type: 'web',
|
|
when: new Date('2026-07-12T18:30:00Z'),
|
|
sealed: 'fire-xyz',
|
|
};
|
|
|
|
describe('renderEmail with ported new-fire templates', () => {
|
|
it('renders es html + text with the message and links', () => {
|
|
const content = buildEmail(notif, 'es', 'Ana', { rootUrl: 'https://fuegos.comunes.org/' });
|
|
const { html, text } = renderEmail('new-fire', content);
|
|
expect(html).toContain('Ana');
|
|
expect(html).toContain('Incendio en Ourense');
|
|
expect(html).toContain('https://fuegos.comunes.org/fire/fire-xyz');
|
|
// juice should inline styles (style attribute present on elements)
|
|
expect(html).toMatch(/style=/);
|
|
expect(text).toContain('Ana');
|
|
expect(text).toContain('https://fuegos.comunes.org/fire/fire-xyz');
|
|
});
|
|
|
|
it('renders en template', () => {
|
|
const content = buildEmail(notif, 'en', 'Bob', { rootUrl: 'https://fires.comunes.org/' });
|
|
const { html } = renderEmail('new-fire', content);
|
|
expect(html).toContain('Bob');
|
|
expect(html).toContain('fires.comunes.org/fire/fire-xyz');
|
|
});
|
|
});
|