fix: evitar duplicar recordatorio diario, filtrar por grupos y limitar a 10

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
main
borja 3 weeks ago
parent cae5a7f1f6
commit 3039af3a43

@ -135,10 +135,12 @@ export class RemindersService {
if (pref.reminder_freq === 'weekly' && weekday !== 'Mon') continue;
try {
const allItems = TaskService.listUserPending(pref.user_id, 10);
const items = enforce ? allItems.filter(t => !t.group_id || AllowedGroups.isAllowed(t.group_id)) : allItems;
const total = TaskService.countUserPending(pref.user_id);
if (!items || items.length === 0) {
// Obtener una lista amplia para filtrar correctamente por grupos permitidos
const allPending = TaskService.listUserPending(pref.user_id, 1000);
const filtered = enforce ? allPending.filter(t => !t.group_id || AllowedGroups.isAllowed(t.group_id)) : allPending;
const total = filtered.length;
const items = filtered.slice(0, 10);
if (items.length === 0) {
// No enviar si no hay tareas; no marcamos last_reminded_on para permitir enviar si aparecen más tarde hoy
continue;
}

@ -82,7 +82,7 @@ describe('RemindersService', () => {
it('no duplica recordatorio diario en el mismo día', async () => {
insertPref('daily', '08:30', null);
const now = new Date('2025-09-08T07:40:00.000Z'); // ≥ 08:30 local
const now = new Date('2025-09-08T07:30:00.000Z'); // dentro de ventana (≤ 60 min)
TaskService.createTask(
{ description: 'Tarea B', due_date: '2025-09-11', group_id: null, created_by: USER },
@ -92,7 +92,7 @@ describe('RemindersService', () => {
await RemindersService.runOnce(now);
expect(countQueued()).toBe(1);
// Segunda ejecución el mismo día
// Segunda ejecución el mismo día (fuera de ventana, pero ya enviado hoy → no duplica)
await RemindersService.runOnce(new Date('2025-09-08T08:00:00.000Z'));
expect(countQueued()).toBe(1); // sin incremento
});
@ -148,7 +148,7 @@ describe('RemindersService', () => {
it('incluye “… y X más” cuando hay más de 10 tareas (tope de listado)', async () => {
insertPref('daily', '08:30', null);
const now = new Date('2025-09-08T07:40:00.000Z');
const now = new Date('2025-09-08T07:30:00.000Z'); // dentro de ventana
// Crear 12 tareas asignadas al usuario
for (let i = 0; i < 12; i++) {

Loading…
Cancel
Save