Files
Void-Homelab/tests/api/dashboard.test.js
2026-06-02 22:19:37 +10:00

35 lines
1.3 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: {} });
});
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);
});
});