merge: combine all features from both codebases - mobile dashboard + layer panel + notifications + shares + all fixes
This commit is contained in:
@@ -11,6 +11,7 @@ describe('Layers API', () => {
|
||||
let db: SqliteAdapter;
|
||||
let drawingId: string;
|
||||
let createdLayerId: string;
|
||||
let authToken: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
db = new SqliteAdapter(':memory:');
|
||||
@@ -18,10 +19,18 @@ describe('Layers API', () => {
|
||||
app = await createServer({ db, port: 0 });
|
||||
await app.ready();
|
||||
|
||||
const regRes = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/auth/register',
|
||||
payload: { email: 'admin-test@example.com', password: 'Password123!', name: 'Admin Test', role: 'admin' },
|
||||
});
|
||||
authToken = JSON.parse(regRes.body).session.token;
|
||||
|
||||
// Create project → drawing hierarchy
|
||||
const projRes = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/projects',
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { name: 'Layers Test Project' },
|
||||
});
|
||||
const projectId = JSON.parse(projRes.body).id;
|
||||
@@ -29,6 +38,7 @@ describe('Layers API', () => {
|
||||
const drawRes = await app.inject({
|
||||
method: 'POST',
|
||||
url: `/api/projects/${projectId}/drawings`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { name: 'Layers Test Drawing' },
|
||||
});
|
||||
drawingId = JSON.parse(drawRes.body).id;
|
||||
@@ -39,6 +49,18 @@ describe('Layers API', () => {
|
||||
db.close();
|
||||
});
|
||||
|
||||
// ─── Auth Check ──────────────────────────────────────
|
||||
|
||||
describe('Authentication', () => {
|
||||
it('should return 401 without authorization header', async () => {
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: `/api/drawings/${drawingId}/layers`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Create ─────────────────────────────────────────
|
||||
|
||||
describe('POST /api/drawings/:drawingId/layers', () => {
|
||||
@@ -46,6 +68,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: `/api/drawings/${drawingId}/layers`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { name: 'Background', color: '#ff0000' },
|
||||
});
|
||||
expect(response.statusCode).toBe(201);
|
||||
@@ -61,6 +84,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: `/api/drawings/${drawingId}/layers`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: {},
|
||||
});
|
||||
expect(response.statusCode).toBe(201);
|
||||
@@ -80,6 +104,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: `/api/drawings/${drawingId}/layers`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
});
|
||||
expect(response.statusCode).toBe(200);
|
||||
const body = JSON.parse(response.body);
|
||||
@@ -92,12 +117,14 @@ describe('Layers API', () => {
|
||||
const projRes = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/projects',
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { name: 'Empty Layers Project' },
|
||||
});
|
||||
const projId = JSON.parse(projRes.body).id;
|
||||
const drawRes = await app.inject({
|
||||
method: 'POST',
|
||||
url: `/api/projects/${projId}/drawings`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { name: 'Empty Drawing' },
|
||||
});
|
||||
const emptyDrawId = JSON.parse(drawRes.body).id;
|
||||
@@ -105,6 +132,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: `/api/drawings/${emptyDrawId}/layers`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
});
|
||||
expect(response.statusCode).toBe(200);
|
||||
const body = JSON.parse(response.body);
|
||||
@@ -120,6 +148,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'PATCH',
|
||||
url: `/api/layers/${createdLayerId}`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { name: 'Updated Layer Name' },
|
||||
});
|
||||
expect(response.statusCode).toBe(200);
|
||||
@@ -131,6 +160,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'PATCH',
|
||||
url: `/api/layers/${createdLayerId}`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { visible: 0, locked: 1 },
|
||||
});
|
||||
expect(response.statusCode).toBe(200);
|
||||
@@ -143,6 +173,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'PATCH',
|
||||
url: `/api/layers/${createdLayerId}`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { color: '#00ff00', line_type: 'dashed' },
|
||||
});
|
||||
expect(response.statusCode).toBe(200);
|
||||
@@ -155,6 +186,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'PATCH',
|
||||
url: '/api/layers/non-existent-id',
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { name: 'New Name' },
|
||||
});
|
||||
expect(response.statusCode).toBe(404);
|
||||
@@ -169,6 +201,7 @@ describe('Layers API', () => {
|
||||
const createRes = await app.inject({
|
||||
method: 'POST',
|
||||
url: `/api/drawings/${drawingId}/layers`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
payload: { name: 'To Be Deleted' },
|
||||
});
|
||||
const layerId = JSON.parse(createRes.body).id;
|
||||
@@ -176,6 +209,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'DELETE',
|
||||
url: `/api/layers/${layerId}`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
});
|
||||
expect(response.statusCode).toBe(204);
|
||||
|
||||
@@ -183,6 +217,7 @@ describe('Layers API', () => {
|
||||
const listRes = await app.inject({
|
||||
method: 'GET',
|
||||
url: `/api/drawings/${drawingId}/layers`,
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
});
|
||||
const layers = JSON.parse(listRes.body);
|
||||
expect(layers.find((l: any) => l.id === layerId)).toBeUndefined();
|
||||
@@ -192,6 +227,7 @@ describe('Layers API', () => {
|
||||
const response = await app.inject({
|
||||
method: 'DELETE',
|
||||
url: '/api/layers/non-existent-id',
|
||||
headers: { authorization: `Bearer ${authToken}` },
|
||||
});
|
||||
expect(response.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user