Files
Void-Homelab/tests/api/dashboard.test.js
root 262be3e332 test: update dashboard_layout defaults to include geom/extras (2.8.0 follow-up)
These two assertions asserted the pre-2.8.0 shape; the canvas feature
added geom+extras to the repo/route defaults. push.sh doesn't run unit
tests, so they went red unnoticed until the full vitest run.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 00:17:48 +10:00

35 lines
1.4 KiB
JavaScript

import { describe, it, expect, beforeAll } from 'vitest';
import request from 'supertest';
import { setup } from './helpers.js';
let app, ownerHeaders;
beforeAll(async () => { ({ app, ownerHeaders } = await setup()); });
describe('dashboard layout api', () => {
it('401 without auth', async () => {
const res = await request(app).get('/api/dashboard/layout');
expect(res.status).toBe(401);
});
it('GET returns defaults', async () => {
const res = await request(app).get('/api/dashboard/layout').set(ownerHeaders);
expect(res.status).toBe(200);
expect(res.body).toEqual({ card_order: [], hidden: [], sizes: {}, geom: {}, extras: [] });
});
it('PUT persists and GET reflects it', async () => {
const body = { card_order: ['clock', 'weather'], hidden: [], sizes: { weather: 's' } };
const put = await request(app).put('/api/dashboard/layout').set(ownerHeaders).send(body);
expect(put.status).toBe(200);
const get = await request(app).get('/api/dashboard/layout').set(ownerHeaders);
expect(get.body.card_order).toEqual(['clock', 'weather']);
expect(get.body.sizes).toEqual({ weather: 's' });
});
it('PUT rejects a bad size value', async () => {
const res = await request(app).put('/api/dashboard/layout').set(ownerHeaders)
.send({ card_order: [], hidden: [], sizes: { weather: 'huge' } });
expect(res.status).toBe(400);
});
});