feat(dashboard): owner-only GET/PUT /api/dashboard/layout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
34
tests/api/dashboard.test.js
Normal file
34
tests/api/dashboard.test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user