|
|
|
@ -74,4 +74,93 @@ describe('Web API - GET /api/me/preferences', () => {
|
|
|
|
const json = await res.json();
|
|
|
|
const json = await res.json();
|
|
|
|
expect(json).toEqual({ freq: 'off', time: '08:30' });
|
|
|
|
expect(json).toEqual({ freq: 'off', time: '08:30' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('POST /api/me/preferences - flujo completo', async () => {
|
|
|
|
|
|
|
|
const sid = 'sid-test-pref';
|
|
|
|
|
|
|
|
const base = server!.baseUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1) daily sin hora -> usa default '08:30'
|
|
|
|
|
|
|
|
let res = await fetch(`${base}/api/me/preferences`, {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: { 'content-type': 'application/json', Cookie: `sid=${sid}` },
|
|
|
|
|
|
|
|
body: JSON.stringify({ freq: 'daily' })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
let json = await res.json();
|
|
|
|
|
|
|
|
expect(json).toEqual({ freq: 'daily', time: '08:30' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET refleja lo guardado
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, { headers: { Cookie: `sid=${sid}` } });
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
json = await res.json();
|
|
|
|
|
|
|
|
expect(json).toEqual({ freq: 'daily', time: '08:30' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2) weekly con hora '7:5' → normaliza a '07:05'
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: { 'content-type': 'application/json', Cookie: `sid=${sid}` },
|
|
|
|
|
|
|
|
body: JSON.stringify({ freq: 'weekly', time: '7:5' })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
json = await res.json();
|
|
|
|
|
|
|
|
expect(json).toEqual({ freq: 'weekly', time: '07:05' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3) weekdays con hora inválida → 400
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: { 'content-type': 'application/json', Cookie: `sid=${sid}` },
|
|
|
|
|
|
|
|
body: JSON.stringify({ freq: 'weekdays', time: '25:00' })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.status).toBe(400);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4) freq inválida → 400
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: { 'content-type': 'application/json', Cookie: `sid=${sid}` },
|
|
|
|
|
|
|
|
body: JSON.stringify({ freq: 'foo', time: '08:00' })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.status).toBe(400);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 5) off sin hora → conserva última ('07:05')
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: { 'content-type': 'application/json', Cookie: `sid=${sid}` },
|
|
|
|
|
|
|
|
body: JSON.stringify({ freq: 'off' })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
json = await res.json();
|
|
|
|
|
|
|
|
expect(json).toEqual({ freq: 'off', time: '07:05' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET refleja off con hora conservada
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, { headers: { Cookie: `sid=${sid}` } });
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
json = await res.json();
|
|
|
|
|
|
|
|
expect(json).toEqual({ freq: 'off', time: '07:05' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 6) weekdays con hora válida
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: { 'content-type': 'application/json', Cookie: `sid=${sid}` },
|
|
|
|
|
|
|
|
body: JSON.stringify({ freq: 'weekdays', time: '18:45' })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
json = await res.json();
|
|
|
|
|
|
|
|
expect(json).toEqual({ freq: 'weekdays', time: '18:45' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 7) daily con hora '6:7' -> normaliza '06:07'
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: { 'content-type': 'application/json', Cookie: `sid=${sid}` },
|
|
|
|
|
|
|
|
body: JSON.stringify({ freq: 'daily', time: '6:7' })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
json = await res.json();
|
|
|
|
|
|
|
|
expect(json).toEqual({ freq: 'daily', time: '06:07' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET final
|
|
|
|
|
|
|
|
res = await fetch(`${base}/api/me/preferences`, { headers: { Cookie: `sid=${sid}` } });
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
json = await res.json();
|
|
|
|
|
|
|
|
expect(json).toEqual({ freq: 'daily', time: '06:07' });
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|