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
+124 -27
View File
@@ -2,6 +2,19 @@
* Unit tests for MCP reservation tools: create_reservation, update_reservation,
* delete_reservation, link_hotel_accommodation.
*/
import { runMigrations } from '../../../src/db/migrations';
import { createTables } from '../../../src/db/schema';
import {
createUser,
createTrip,
createDay,
createPlace,
createReservation,
createDayAssignment,
} from '../../helpers/factories';
import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';
import { resetTestDb } from '../../helpers/test-db';
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
const { testDb, dbMock } = vi.hoisted(() => {
@@ -16,7 +29,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),
};
@@ -33,12 +50,6 @@ vi.mock('../../../src/config', () => ({
const { broadcastMock } = vi.hoisted(() => ({ broadcastMock: vi.fn() }));
vi.mock('../../../src/websocket', () => ({ broadcast: broadcastMock }));
import { createTables } from '../../../src/db/schema';
import { runMigrations } from '../../../src/db/migrations';
import { resetTestDb } from '../../helpers/test-db';
import { createUser, createTrip, createDay, createPlace, createReservation, createDayAssignment } from '../../helpers/factories';
import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';
beforeAll(() => {
createTables(testDb);
runMigrations(testDb);
@@ -56,7 +67,11 @@ afterAll(() => {
async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {
const h = await createMcpHarness({ userId, withResources: false });
try { await fn(h); } finally { await h.cleanup(); }
try {
await fn(h);
} finally {
await h.cleanup();
}
}
// ---------------------------------------------------------------------------
@@ -104,7 +119,9 @@ describe('Tool: create_reservation', () => {
expect(data.reservation.type).toBe('hotel');
expect(data.reservation.accommodation_id).not.toBeNull();
// accommodation was created
const acc = testDb.prepare('SELECT * FROM day_accommodations WHERE id = ?').get(data.reservation.accommodation_id) as any;
const acc = testDb
.prepare('SELECT * FROM day_accommodations WHERE id = ?')
.get(data.reservation.accommodation_id) as any;
expect(acc.place_id).toBe(hotel.id);
expect(acc.check_in).toBe('15:00');
});
@@ -144,7 +161,10 @@ describe('Tool: create_reservation', () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({ name: 'create_reservation', arguments: { tripId: trip.id, title: 'Bus', type: 'other' } });
await h.client.callTool({
name: 'create_reservation',
arguments: { tripId: trip.id, title: 'Bus', type: 'other' },
});
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'reservation:created', expect.any(Object));
});
});
@@ -158,7 +178,14 @@ describe('Tool: create_reservation', () => {
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'create_reservation',
arguments: { tripId: trip.id, title: 'Hotel', type: 'hotel', place_id: hotel.id, start_day_id: day1.id, end_day_id: day2.id },
arguments: {
tripId: trip.id,
title: 'Hotel',
type: 'hotel',
place_id: hotel.id,
start_day_id: day1.id,
end_day_id: day2.id,
},
});
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'accommodation:created', expect.any(Object));
});
@@ -169,7 +196,10 @@ describe('Tool: create_reservation', () => {
const { user: other } = createUser(testDb);
const trip = createTrip(testDb, other.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'create_reservation', arguments: { tripId: trip.id, title: 'X', type: 'flight' } });
const result = await h.client.callTool({
name: 'create_reservation',
arguments: { tripId: trip.id, title: 'X', type: 'flight' },
});
expect(result.isError).toBe(true);
});
});
@@ -214,7 +244,10 @@ describe('Tool: update_reservation', () => {
const trip = createTrip(testDb, user.id);
const reservation = createReservation(testDb, trip.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({ name: 'update_reservation', arguments: { tripId: trip.id, reservationId: reservation.id, title: 'Updated' } });
await h.client.callTool({
name: 'update_reservation',
arguments: { tripId: trip.id, reservationId: reservation.id, title: 'Updated' },
});
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'reservation:updated', expect.any(Object));
});
});
@@ -223,7 +256,10 @@ describe('Tool: update_reservation', () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'update_reservation', arguments: { tripId: trip.id, reservationId: 99999, title: 'X' } });
const result = await h.client.callTool({
name: 'update_reservation',
arguments: { tripId: trip.id, reservationId: 99999, title: 'X' },
});
expect(result.isError).toBe(true);
});
});
@@ -249,7 +285,10 @@ describe('Tool: update_reservation', () => {
const trip = createTrip(testDb, other.id);
const reservation = createReservation(testDb, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'update_reservation', arguments: { tripId: trip.id, reservationId: reservation.id, title: 'X' } });
const result = await h.client.callTool({
name: 'update_reservation',
arguments: { tripId: trip.id, reservationId: reservation.id, title: 'X' },
});
expect(result.isError).toBe(true);
});
});
@@ -265,7 +304,10 @@ describe('Tool: delete_reservation', () => {
const trip = createTrip(testDb, user.id);
const reservation = createReservation(testDb, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'delete_reservation', arguments: { tripId: trip.id, reservationId: reservation.id } });
const result = await h.client.callTool({
name: 'delete_reservation',
arguments: { tripId: trip.id, reservationId: reservation.id },
});
const data = parseToolResult(result) as any;
expect(data.success).toBe(true);
expect(testDb.prepare('SELECT id FROM reservations WHERE id = ?').get(reservation.id)).toBeUndefined();
@@ -283,12 +325,20 @@ describe('Tool: delete_reservation', () => {
await withHarness(user.id, async (h) => {
const r = await h.client.callTool({
name: 'create_reservation',
arguments: { tripId: trip.id, title: 'Hotel', type: 'hotel', place_id: hotel.id, start_day_id: day1.id, end_day_id: day2.id },
arguments: {
tripId: trip.id,
title: 'Hotel',
type: 'hotel',
place_id: hotel.id,
start_day_id: day1.id,
end_day_id: day2.id,
},
});
reservationId = (parseToolResult(r) as any).reservation.id;
});
const accId = (testDb.prepare('SELECT accommodation_id FROM reservations WHERE id = ?').get(reservationId!) as any).accommodation_id;
const accId = (testDb.prepare('SELECT accommodation_id FROM reservations WHERE id = ?').get(reservationId!) as any)
.accommodation_id;
expect(accId).not.toBeNull();
await withHarness(user.id, async (h) => {
@@ -303,7 +353,10 @@ describe('Tool: delete_reservation', () => {
const trip = createTrip(testDb, user.id);
const reservation = createReservation(testDb, trip.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({ name: 'delete_reservation', arguments: { tripId: trip.id, reservationId: reservation.id } });
await h.client.callTool({
name: 'delete_reservation',
arguments: { tripId: trip.id, reservationId: reservation.id },
});
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'reservation:deleted', expect.any(Object));
});
});
@@ -312,7 +365,10 @@ describe('Tool: delete_reservation', () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'delete_reservation', arguments: { tripId: trip.id, reservationId: 99999 } });
const result = await h.client.callTool({
name: 'delete_reservation',
arguments: { tripId: trip.id, reservationId: 99999 },
});
expect(result.isError).toBe(true);
});
});
@@ -323,7 +379,10 @@ describe('Tool: delete_reservation', () => {
const trip = createTrip(testDb, other.id);
const reservation = createReservation(testDb, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'delete_reservation', arguments: { tripId: trip.id, reservationId: reservation.id } });
const result = await h.client.callTool({
name: 'delete_reservation',
arguments: { tripId: trip.id, reservationId: reservation.id },
});
expect(result.isError).toBe(true);
});
});
@@ -345,7 +404,15 @@ describe('Tool: link_hotel_accommodation', () => {
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'link_hotel_accommodation',
arguments: { tripId: trip.id, reservationId: reservation.id, place_id: hotel.id, start_day_id: day1.id, end_day_id: day2.id, check_in: '14:00', check_out: '12:00' },
arguments: {
tripId: trip.id,
reservationId: reservation.id,
place_id: hotel.id,
start_day_id: day1.id,
end_day_id: day2.id,
check_in: '14:00',
check_out: '12:00',
},
});
const data = parseToolResult(result) as any;
expect(data.reservation.accommodation_id).not.toBeNull();
@@ -368,7 +435,13 @@ describe('Tool: link_hotel_accommodation', () => {
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'link_hotel_accommodation',
arguments: { tripId: trip.id, reservationId: reservation.id, place_id: hotel.id, start_day_id: day1.id, end_day_id: day2.id },
arguments: {
tripId: trip.id,
reservationId: reservation.id,
place_id: hotel.id,
start_day_id: day1.id,
end_day_id: day2.id,
},
});
});
@@ -376,7 +449,13 @@ describe('Tool: link_hotel_accommodation', () => {
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'link_hotel_accommodation',
arguments: { tripId: trip.id, reservationId: reservation.id, place_id: hotel2.id, start_day_id: day2.id, end_day_id: day3.id },
arguments: {
tripId: trip.id,
reservationId: reservation.id,
place_id: hotel2.id,
start_day_id: day2.id,
end_day_id: day3.id,
},
});
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'accommodation:updated', expect.any(Object));
});
@@ -392,7 +471,13 @@ describe('Tool: link_hotel_accommodation', () => {
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'link_hotel_accommodation',
arguments: { tripId: trip.id, reservationId: reservation.id, place_id: place.id, start_day_id: day1.id, end_day_id: day2.id },
arguments: {
tripId: trip.id,
reservationId: reservation.id,
place_id: place.id,
start_day_id: day1.id,
end_day_id: day2.id,
},
});
expect(result.isError).toBe(true);
});
@@ -409,7 +494,13 @@ describe('Tool: link_hotel_accommodation', () => {
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'link_hotel_accommodation',
arguments: { tripId: trip1.id, reservationId: reservation.id, place_id: placeFromTrip2.id, start_day_id: day1.id, end_day_id: day2.id },
arguments: {
tripId: trip1.id,
reservationId: reservation.id,
place_id: placeFromTrip2.id,
start_day_id: day1.id,
end_day_id: day2.id,
},
});
expect(result.isError).toBe(true);
});
@@ -426,7 +517,13 @@ describe('Tool: link_hotel_accommodation', () => {
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'link_hotel_accommodation',
arguments: { tripId: trip.id, reservationId: reservation.id, place_id: place.id, start_day_id: day1.id, end_day_id: day2.id },
arguments: {
tripId: trip.id,
reservationId: reservation.id,
place_id: place.id,
start_day_id: day1.id,
end_day_id: day2.id,
},
});
expect(result.isError).toBe(true);
});