chore: apply prettier on the entire project

This commit is contained in:
jubnl
2026-05-25 21:59:42 +02:00
parent c130ed41be
commit 6bcdfbc34b
488 changed files with 82986 additions and 45830 deletions
+24 -25
View File
@@ -2,9 +2,17 @@
* Categories integration tests — CAT-001 through CAT-009.
* Covers GET/POST/PUT/DELETE /api/categories.
*/
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
import request from 'supertest';
import { createApp } from '../../src/app';
import { runMigrations } from '../../src/db/migrations';
import { createTables } from '../../src/db/schema';
import { loginAttempts, mfaAttempts } from '../../src/routes/auth';
import { authCookie } from '../helpers/auth';
import { createUser, createAdmin } from '../helpers/factories';
import { resetTestDb } from '../helpers/test-db';
import type { Application } from 'express';
import request from 'supertest';
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
const { testDb, dbMock } = vi.hoisted(() => {
const Database = require('better-sqlite3');
@@ -18,7 +26,11 @@ const { testDb, dbMock } = vi.hoisted(() => {
reinitialize: () => {},
getPlaceWithTags: () => null,
canAccessTrip: (tripId: any, userId: number) =>
db.prepare(`SELECT t.id, t.user_id FROM trips t LEFT JOIN trip_members m ON m.trip_id = t.id AND m.user_id = ? WHERE t.id = ? AND (t.user_id = ? OR m.user_id IS NOT NULL)`).get(userId, tripId, userId),
db
.prepare(
`SELECT t.id, t.user_id FROM trips t LEFT JOIN trip_members m ON m.trip_id = t.id AND m.user_id = ? WHERE t.id = ? AND (t.user_id = ? OR m.user_id IS NOT NULL)`,
)
.get(userId, tripId, userId),
isOwner: (tripId: any, userId: number) =>
!!db.prepare('SELECT id FROM trips WHERE id = ? AND user_id = ?').get(tripId, userId),
};
@@ -32,14 +44,6 @@ vi.mock('../../src/config', () => ({
updateJwtSecret: () => {},
}));
import { createApp } from '../../src/app';
import { createTables } from '../../src/db/schema';
import { runMigrations } from '../../src/db/migrations';
import { resetTestDb } from '../helpers/test-db';
import { createUser, createAdmin } from '../helpers/factories';
import { authCookie } from '../helpers/auth';
import { loginAttempts, mfaAttempts } from '../../src/routes/auth';
const app: Application = createApp();
beforeAll(() => {
@@ -60,14 +64,16 @@ afterAll(() => {
describe('Categories', () => {
it('CAT-001: GET /api/categories returns seeded default categories', async () => {
const { user } = createUser(testDb);
const res = await request(app)
.get('/api/categories')
.set('Cookie', authCookie(user.id));
const res = await request(app).get('/api/categories').set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(Array.isArray(res.body.categories)).toBe(true);
// 10 default categories are seeded on reset
expect(res.body.categories.length).toBeGreaterThanOrEqual(10);
expect(res.body.categories[0]).toMatchObject({ name: expect.any(String), color: expect.any(String), icon: expect.any(String) });
expect(res.body.categories[0]).toMatchObject({
name: expect.any(String),
color: expect.any(String),
icon: expect.any(String),
});
});
it('CAT-002: POST /api/categories - admin creates a new category', async () => {
@@ -83,10 +89,7 @@ describe('Categories', () => {
it('CAT-003: POST /api/categories - non-admin returns 403', async () => {
const { user } = createUser(testDb);
const res = await request(app)
.post('/api/categories')
.set('Cookie', authCookie(user.id))
.send({ name: 'Museum' });
const res = await request(app).post('/api/categories').set('Cookie', authCookie(user.id)).send({ name: 'Museum' });
expect(res.status).toBe(403);
});
@@ -148,9 +151,7 @@ describe('Categories', () => {
.send({ name: 'To Delete' });
const catId = createRes.body.category.id;
const res = await request(app)
.delete(`/api/categories/${catId}`)
.set('Cookie', authCookie(admin.id));
const res = await request(app).delete(`/api/categories/${catId}`).set('Cookie', authCookie(admin.id));
expect(res.status).toBe(200);
expect(res.body.success).toBe(true);
@@ -162,9 +163,7 @@ describe('Categories', () => {
it('CAT-009: DELETE /api/categories/:id - non-admin returns 403', async () => {
const { user } = createUser(testDb);
const cat = testDb.prepare('SELECT id FROM categories LIMIT 1').get() as { id: number };
const res = await request(app)
.delete(`/api/categories/${cat.id}`)
.set('Cookie', authCookie(user.id));
const res = await request(app).delete(`/api/categories/${cat.id}`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(403);
});