From 2446427b5f96dce515ba7f10d4118fe3818f717b Mon Sep 17 00:00:00 2001 From: brobert Date: Tue, 14 Oct 2025 22:21:04 +0200 Subject: [PATCH] fix: alinear bloque de prueba para que coincida con el original Co-authored-by: aider (openrouter/openai/gpt-5) --- tests/web/api.me.tasks.test.ts | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/web/api.me.tasks.test.ts b/tests/web/api.me.tasks.test.ts index 37bfd0a..5c24f97 100644 --- a/tests/web/api.me.tasks.test.ts +++ b/tests/web/api.me.tasks.test.ts @@ -126,4 +126,75 @@ describe('Web API - GET /api/me/tasks', () => { expect(json.items.length).toBe(1); expect(json.items[0].description).toContain('beta_100%'); }); + + it('permite actualizar la descripción de una tarea con PATCH', async () => { + // Localizar la tarea por búsqueda + const q = encodeURIComponent('beta_100%'); + const listRes = await fetch(`${server!.baseUrl}/api/me/tasks?limit=10&search=${q}`, { + headers: { Cookie: `sid=${sid}` } + }); + expect(listRes.status).toBe(200); + const list = await listRes.json(); + expect(list.items.length).toBe(1); + const taskId = list.items[0].id; + + // Actualizar descripción + const newDesc = 'beta renombrada'; + const patchRes = await fetch(`${server!.baseUrl}/api/tasks/${taskId}`, { + method: 'PATCH', + headers: { + Cookie: `sid=${sid}`, + 'content-type': 'application/json' + }, + body: JSON.stringify({ description: newDesc }) + }); + expect(patchRes.status).toBe(200); + const patched = await patchRes.json(); + expect(patched.task.description).toBe(newDesc); + + // Verificar en el listado + const q2 = encodeURIComponent('renombrada'); + const listRes2 = await fetch(`${server!.baseUrl}/api/me/tasks?limit=10&search=${q2}`, { + headers: { Cookie: `sid=${sid}` } + }); + expect(listRes2.status).toBe(200); + const list2 = await listRes2.json(); + expect(list2.items.length).toBe(1); + expect(list2.items[0].description).toContain('renombrada'); + }); + + it('rechaza descripciones vacías o demasiado largas', async () => { + // Reutiliza la misma tarea localizada arriba (buscar por 'renombrada') + const q = encodeURIComponent('renombrada'); + const listRes = await fetch(`${server!.baseUrl}/api/me/tasks?limit=10&search=${q}`, { + headers: { Cookie: `sid=${sid}` } + }); + expect(listRes.status).toBe(200); + const list = await listRes.json(); + expect(list.items.length).toBe(1); + const taskId = list.items[0].id; + + // Vacía/espacios + const resEmpty = await fetch(`${server!.baseUrl}/api/tasks/${taskId}`, { + method: 'PATCH', + headers: { + Cookie: `sid=${sid}`, + 'content-type': 'application/json' + }, + body: JSON.stringify({ description: ' ' }) + }); + expect(resEmpty.status).toBe(400); + + // Demasiado larga (>1000) + const longText = 'a'.repeat(1001); + const resLong = await fetch(`${server!.baseUrl}/api/tasks/${taskId}`, { + method: 'PATCH', + headers: { + Cookie: `sid=${sid}`, + 'content-type': 'application/json' + }, + body: JSON.stringify({ description: longText }) + }); + expect(resLong.status).toBe(400); + }); });