mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
chore: move day-notes backend to proper DI
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
/**
|
||||
* Unit tests for MCP resources (resources.ts).
|
||||
* Tests all 10 legacy-registrar resources via InMemoryTransport + Client
|
||||
* Tests all 9 legacy-registrar resources via InMemoryTransport + Client
|
||||
* (trek://categories moved to the DI-discovered CategoriesMcp — see
|
||||
* tools-categories.test.ts; trek://trips/{tripId}/todos moved to TodoMcp —
|
||||
* see tools-todos.test.ts; trek://trips/{tripId}/packing and .../packing/bags
|
||||
* moved to PackingMcp — see tools-packing.test.ts).
|
||||
* moved to PackingMcp — see tools-packing.test.ts;
|
||||
* trek://trips/{tripId}/days/{dayId}/notes moved to DayNotesMcp — see
|
||||
* tools-notes.test.ts).
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll, afterEach } from 'vitest';
|
||||
|
||||
@@ -43,7 +45,7 @@ vi.mock('../../../src/websocket', () => ({ broadcast: vi.fn() }));
|
||||
import { createTables } from '../../../src/db/schema';
|
||||
import { runMigrations } from '../../../src/db/migrations';
|
||||
import { resetTestDb } from '../../helpers/test-db';
|
||||
import { createUser, createTrip, createDay, createPlace, addTripMember, createBudgetItem, createReservation, createDayNote, createCollabNote, createBucketListItem, createVisitedCountry, createDayAssignment, createDayAccommodation } from '../../helpers/factories';
|
||||
import { createUser, createTrip, createDay, createPlace, addTripMember, createBudgetItem, createReservation, createCollabNote, createBucketListItem, createVisitedCountry, createDayAssignment, createDayAccommodation } from '../../helpers/factories';
|
||||
import { createMcpHarness, parseResourceResult, type McpHarness } from '../../helpers/mcp-harness';
|
||||
|
||||
beforeAll(() => {
|
||||
@@ -268,45 +270,8 @@ describe('Resource: trek://trips/{tripId}/reservations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Resource: trek://trips/{tripId}/days/{dayId}/notes', () => {
|
||||
it('returns notes for a specific day', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
createDayNote(testDb, day.id, trip.id, { text: 'Check in at noon' });
|
||||
|
||||
await withHarness(user.id, async (harness) => {
|
||||
const result = await harness.client.readResource({ uri: `trek://trips/${trip.id}/days/${day.id}/notes` });
|
||||
const notes = parseResourceResult(result) as any[];
|
||||
expect(notes).toHaveLength(1);
|
||||
expect(notes[0].text).toBe('Check in at noon');
|
||||
});
|
||||
});
|
||||
|
||||
it('returns access denied for unauthorized trip', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { user: other } = createUser(testDb);
|
||||
const trip = createTrip(testDb, other.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
|
||||
await withHarness(user.id, async (harness) => {
|
||||
const result = await harness.client.readResource({ uri: `trek://trips/${trip.id}/days/${day.id}/notes` });
|
||||
const data = parseResourceResult(result) as any;
|
||||
expect(data.error).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns access denied for invalid dayId', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
|
||||
await withHarness(user.id, async (harness) => {
|
||||
const result = await harness.client.readResource({ uri: `trek://trips/${trip.id}/days/abc/notes` });
|
||||
const data = parseResourceResult(result) as any;
|
||||
expect(data.error).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
// The trek://trips/{tripId}/days/{dayId}/notes resource moved to the
|
||||
// DI-discovered DayNotesMcp — see tools-notes.test.ts.
|
||||
|
||||
describe('Resource: trek://trips/{tripId}/accommodations', () => {
|
||||
it('returns accommodations for a trip', async () => {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
/**
|
||||
* Unit tests for MCP note tools: create_day_note, update_day_note, delete_day_note,
|
||||
* create_collab_note, update_collab_note, delete_collab_note.
|
||||
* Unit tests for MCP note tools: create_day_note, update_day_note, delete_day_note
|
||||
* (DayNotesMcp, DI-discovered — attached via the nest-mcp registry inside
|
||||
* registerTools, so every harness here keeps withTools on) and
|
||||
* create_collab_note, update_collab_note, delete_collab_note (still on the
|
||||
* legacy registrar).
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
||||
|
||||
@@ -44,7 +47,7 @@ import { createTables } from '../../../src/db/schema';
|
||||
import { runMigrations } from '../../../src/db/migrations';
|
||||
import { resetTestDb } from '../../helpers/test-db';
|
||||
import { createUser, createTrip, createDay, createDayNote, createCollabNote } from '../../helpers/factories';
|
||||
import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';
|
||||
import { createMcpHarness, parseToolResult, parseResourceResult, type McpHarness } from '../../helpers/mcp-harness';
|
||||
|
||||
beforeAll(() => {
|
||||
createTables(testDb);
|
||||
@@ -258,6 +261,84 @@ describe('Tool: delete_day_note', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Scope gating (trips write, registration-time — the legacy registerDayTools
|
||||
// whole-registrar `canWrite(scopes, 'trips')` early return, now the
|
||||
// declarative access marker on every DayNotesMcp tool)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe('Day-note tools — scope gating', () => {
|
||||
const WRITE_TOOLS = ['create_day_note', 'update_day_note', 'delete_day_note'];
|
||||
|
||||
async function listToolNames(userId: number, scopes: string[] | null): Promise<string[]> {
|
||||
const h = await createMcpHarness({ userId, withResources: false, scopes });
|
||||
try {
|
||||
return (await h.client.listTools()).tools.map((t) => t.name);
|
||||
} finally {
|
||||
await h.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
it('registers all three tools with null scopes (full access)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const names = await listToolNames(user.id, null);
|
||||
for (const tool of WRITE_TOOLS) expect(names).toContain(tool);
|
||||
});
|
||||
|
||||
it('registers no day-note tools with trips:read only (all three are writes)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const names = await listToolNames(user.id, ['trips:read']);
|
||||
for (const tool of WRITE_TOOLS) expect(names).not.toContain(tool);
|
||||
});
|
||||
|
||||
it('registers no day-note tools for an unrelated scope', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const names = await listToolNames(user.id, ['budget:read']);
|
||||
for (const tool of WRITE_TOOLS) expect(names).not.toContain(tool);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// trek://trips/{tripId}/days/{dayId}/notes resource (moved from the legacy
|
||||
// registerResources to DayNotesMcp)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe('Resource: trek://trips/{tripId}/days/{dayId}/notes', () => {
|
||||
it('returns the day notes ordered by sort_order', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
createDayNote(testDb, day.id, trip.id, { text: 'Second', sort_order: 5 });
|
||||
createDayNote(testDb, day.id, trip.id, { text: 'First', sort_order: 1 });
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/days/${day.id}/notes` });
|
||||
const notes = parseResourceResult(result) as { text: string }[];
|
||||
expect(notes).toHaveLength(2);
|
||||
expect(notes[0].text).toBe('First');
|
||||
expect(notes[1].text).toBe('Second');
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the access-denied payload for a non-member', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { user: other } = createUser(testDb);
|
||||
const trip = createTrip(testDb, other.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/days/${day.id}/notes` });
|
||||
expect(parseResourceResult(result)).toEqual({ error: 'Trip not found or access denied' });
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the access-denied payload for a malformed id', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.readResource({ uri: 'trek://trips/1/days/not-a-number/notes' });
|
||||
expect(parseResourceResult(result)).toEqual({ error: 'Trip not found or access denied' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// create_collab_note
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* Unit tests for the DI-native DayNotesService — DAYNOTE-SVC-001 through
|
||||
* DAYNOTE-SVC-016. The legacy dayNoteService had no dedicated suite (it was
|
||||
* only covered transitively), so these cases are authored fresh with the DI
|
||||
* move to pin the relocated SQL and its quirks (trim-on-write, `||` empty-
|
||||
* string coercions vs the `??` sort_order default, JS-side update merge,
|
||||
* post-write re-selects). Uses a real in-memory SQLite DB so SQL logic is
|
||||
* exercised faithfully.
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
||||
|
||||
// ── DB setup ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const { testDb, dbMock } = vi.hoisted(() => {
|
||||
const Database = require('better-sqlite3');
|
||||
const db = new Database(':memory:');
|
||||
db.exec('PRAGMA journal_mode = WAL');
|
||||
db.exec('PRAGMA foreign_keys = ON');
|
||||
db.exec('PRAGMA busy_timeout = 5000');
|
||||
const mock = {
|
||||
db,
|
||||
closeDb: () => {},
|
||||
reinitialize: () => {},
|
||||
getPlaceWithTags: () => null,
|
||||
canAccessTrip: (tripId: number | string, 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),
|
||||
isOwner: (tripId: number | string, userId: number) =>
|
||||
!!db.prepare('SELECT id FROM trips WHERE id = ? AND user_id = ?').get(tripId, userId),
|
||||
};
|
||||
return { testDb: db, dbMock: mock };
|
||||
});
|
||||
|
||||
vi.mock('../../../src/db/database', () => dbMock);
|
||||
vi.mock('../../../src/config', () => ({
|
||||
JWT_SECRET: 'test-secret',
|
||||
ENCRYPTION_KEY: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2',
|
||||
updateJwtSecret: () => {},
|
||||
}));
|
||||
vi.mock('../../../src/websocket', () => ({ broadcast: vi.fn() }));
|
||||
|
||||
import { createTables } from '../../../src/db/schema';
|
||||
import { runMigrations } from '../../../src/db/migrations';
|
||||
import { resetTestDb } from '../../helpers/test-db';
|
||||
import { createUser, createTrip, createDay, addTripMember } from '../../helpers/factories';
|
||||
import { DatabaseService } from '../../../src/nest/database/database.service';
|
||||
import { DayNotesService } from '../../../src/nest/days/day-notes.service';
|
||||
import type { DayNote } from '../../../src/types';
|
||||
|
||||
const svc = new DayNotesService(new DatabaseService(testDb));
|
||||
|
||||
beforeAll(() => {
|
||||
createTables(testDb);
|
||||
runMigrations(testDb);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetTestDb(testDb);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
testDb.close();
|
||||
});
|
||||
|
||||
function seedTripAndDay() {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
return { user, trip, day };
|
||||
}
|
||||
|
||||
// ── verifyTripAccess ──────────────────────────────────────────────────────────
|
||||
|
||||
describe('verifyTripAccess', () => {
|
||||
it('DAYNOTE-SVC-001: returns trip for owner', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const result = svc.verifyTripAccess(trip.id, user.id);
|
||||
expect(result).toBeDefined();
|
||||
expect(result?.id).toBe(trip.id);
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-002: returns nothing for non-member', () => {
|
||||
const { user: owner } = createUser(testDb);
|
||||
const { user: stranger } = createUser(testDb);
|
||||
const trip = createTrip(testDb, owner.id);
|
||||
expect(svc.verifyTripAccess(trip.id, stranger.id)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-003: returns trip for member', () => {
|
||||
const { user: owner } = createUser(testDb);
|
||||
const { user: member } = createUser(testDb);
|
||||
const trip = createTrip(testDb, owner.id);
|
||||
addTripMember(testDb, trip.id, member.id);
|
||||
expect(svc.verifyTripAccess(trip.id, member.id)).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ── dayExists ─────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('dayExists', () => {
|
||||
it('DAYNOTE-SVC-004: truthy only when the day belongs to the trip', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const { user: other } = createUser(testDb);
|
||||
const otherTrip = createTrip(testDb, other.id);
|
||||
expect(svc.dayExists(day.id, trip.id)).toBeTruthy();
|
||||
expect(svc.dayExists(day.id, otherTrip.id)).toBeFalsy();
|
||||
expect(svc.dayExists(9999, trip.id)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
// ── create ────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('create', () => {
|
||||
it('DAYNOTE-SVC-005: inserts and returns the re-selected row', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const note = svc.create(day.id, trip.id, 'Lunch', '12:00', '🍜', 2) as DayNote;
|
||||
expect(note).toMatchObject({ day_id: day.id, trip_id: trip.id, text: 'Lunch', time: '12:00', icon: '🍜', sort_order: 2 });
|
||||
expect(note.id).toBeGreaterThan(0);
|
||||
const row = testDb.prepare('SELECT * FROM day_notes WHERE id = ?').get(note.id);
|
||||
expect(row).toEqual(note);
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-006: trims the text on insert', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const note = svc.create(day.id, trip.id, ' Lunch ') as DayNote;
|
||||
expect(note.text).toBe('Lunch');
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-007: empty-string time coerces to NULL (`||`, not `??`)', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
expect((svc.create(day.id, trip.id, 'a', '') as DayNote).time).toBeNull();
|
||||
expect((svc.create(day.id, trip.id, 'b', undefined) as DayNote).time).toBeNull();
|
||||
expect((svc.create(day.id, trip.id, 'c', null) as DayNote).time).toBeNull();
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-008: empty/absent icon falls back to 📝 (`||`, not `??`)', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
expect((svc.create(day.id, trip.id, 'a', undefined, '') as DayNote).icon).toBe('📝');
|
||||
expect((svc.create(day.id, trip.id, 'b') as DayNote).icon).toBe('📝');
|
||||
expect((svc.create(day.id, trip.id, 'c', undefined, null) as DayNote).icon).toBe('📝');
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-009: sort_order 0 is preserved, only undefined defaults to 9999 (`??`)', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
expect((svc.create(day.id, trip.id, 'a', undefined, undefined, 0) as DayNote).sort_order).toBe(0);
|
||||
expect((svc.create(day.id, trip.id, 'b') as DayNote).sort_order).toBe(9999);
|
||||
});
|
||||
});
|
||||
|
||||
// ── list ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('list', () => {
|
||||
it('DAYNOTE-SVC-010: returns [] for a day without notes', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
expect(svc.list(day.id, trip.id)).toEqual([]);
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-011: orders by sort_order then created_at and scopes to day+trip', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const otherDay = createDay(testDb, trip.id);
|
||||
const second = svc.create(day.id, trip.id, 'second', undefined, undefined, 5) as DayNote;
|
||||
const first = svc.create(day.id, trip.id, 'first', undefined, undefined, 1) as DayNote;
|
||||
svc.create(otherDay.id, trip.id, 'elsewhere');
|
||||
const notes = svc.list(day.id, trip.id) as DayNote[];
|
||||
expect(notes.map((n) => n.id)).toEqual([first.id, second.id]);
|
||||
});
|
||||
});
|
||||
|
||||
// ── getNote ───────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('getNote', () => {
|
||||
it('DAYNOTE-SVC-012: returns the note only under its own day and trip', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const otherDay = createDay(testDb, trip.id);
|
||||
const note = svc.create(day.id, trip.id, 'Lunch') as DayNote;
|
||||
expect(svc.getNote(note.id, day.id, trip.id)).toEqual(note);
|
||||
expect(svc.getNote(note.id, otherDay.id, trip.id)).toBeUndefined();
|
||||
expect(svc.getNote(note.id, day.id, trip.id + 1)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ── update ────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('update', () => {
|
||||
it('DAYNOTE-SVC-013: merges omitted fields from the current row (JS-side, full-row UPDATE)', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const note = svc.create(day.id, trip.id, 'Lunch', '12:00', '🍜', 2) as DayNote;
|
||||
const updated = svc.update(note.id, note, { icon: '🍣' }) as DayNote;
|
||||
expect(updated).toMatchObject({ id: note.id, text: 'Lunch', time: '12:00', icon: '🍣', sort_order: 2 });
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-014: explicit null time clears it, undefined keeps it', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const note = svc.create(day.id, trip.id, 'Lunch', '12:00') as DayNote;
|
||||
const kept = svc.update(note.id, note, { text: 'Lunch!' }) as DayNote;
|
||||
expect(kept.time).toBe('12:00');
|
||||
const cleared = svc.update(note.id, kept, { time: null }) as DayNote;
|
||||
expect(cleared.time).toBeNull();
|
||||
});
|
||||
|
||||
it('DAYNOTE-SVC-015: trims only the new text and preserves sort_order 0 writes', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const note = svc.create(day.id, trip.id, 'Lunch', undefined, undefined, 5) as DayNote;
|
||||
const updated = svc.update(note.id, note, { text: ' Dinner ', sort_order: 0 }) as DayNote;
|
||||
expect(updated.text).toBe('Dinner');
|
||||
expect(updated.sort_order).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── remove ────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('remove', () => {
|
||||
it('DAYNOTE-SVC-016: deletes by bare id (trip-scoping is the caller getNote)', () => {
|
||||
const { trip, day } = seedTripAndDay();
|
||||
const note = svc.create(day.id, trip.id, 'Lunch') as DayNote;
|
||||
svc.remove(note.id);
|
||||
expect(testDb.prepare('SELECT * FROM day_notes WHERE id = ?').get(note.id)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -3,9 +3,9 @@
|
||||
* capability host to the real privileged modules (#plugins, M1). Verifies the
|
||||
* per-plugin data db is cached, a granted db:own call works through the wired
|
||||
* host, and trip broadcasts are force-namespaced to plugin:{id}:{event}.
|
||||
* DI-native domains (budget/reservations/tags/categories/todo/packing/oauth)
|
||||
* are constructor-injected stubs; legacy services/* domains stay path-mocked
|
||||
* until their own DI migration lands.
|
||||
* DI-native domains (budget/reservations/tags/categories/todo/packing/
|
||||
* day-notes/oauth) are constructor-injected stubs; legacy services/* domains
|
||||
* stay path-mocked until their own DI migration lands.
|
||||
*/
|
||||
import { describe, it, expect, beforeAll, beforeEach, afterAll, vi } from 'vitest';
|
||||
import fs from 'node:fs';
|
||||
@@ -273,14 +273,15 @@ vi.mock('../../../src/services/collectionsService', () => {
|
||||
deletePlace: vi.fn((_uid: number, placeId: number) => { if (placeId === 404) httpError(404, 'Collection not found'); }),
|
||||
};
|
||||
});
|
||||
vi.mock('../../../src/services/dayNoteService', () => ({
|
||||
listNotes: vi.fn((dayId: number, tripId: number) => [{ id: 1, day_id: dayId, trip_id: tripId }]),
|
||||
createNote: vi.fn((dayId: number, _tripId: number, text: string) => ({ id: 50, day_id: dayId, text })),
|
||||
// Day notes are a constructor-injected stub (same behaviors as the old path mock).
|
||||
const dayNotesStub = {
|
||||
list: vi.fn((dayId: number, tripId: number) => [{ id: 1, day_id: dayId, trip_id: tripId }]),
|
||||
create: vi.fn((dayId: number, _tripId: number, text: string) => ({ id: 50, day_id: dayId, text })),
|
||||
getNote: vi.fn((id: number) => (id === 99 ? undefined : { id, text: 'Old' })),
|
||||
updateNote: vi.fn((id: number, _current: unknown, fields: Record<string, unknown>) => ({ id, ...fields })),
|
||||
deleteNote: vi.fn(),
|
||||
update: vi.fn((id: number, _current: unknown, fields: Record<string, unknown>) => ({ id, ...fields })),
|
||||
remove: vi.fn(),
|
||||
dayExists: vi.fn((dayId: number) => dayId === 3),
|
||||
}));
|
||||
} as unknown as DayNotesService;
|
||||
|
||||
import { PluginHostDepsFactory, type PluginCallRouter } from '../../../src/nest/plugins/host/plugin-host-deps.factory';
|
||||
import { getPluginDataDb, closePluginDataDb } from '../../../src/nest/plugins/host/plugin-host-state';
|
||||
@@ -291,12 +292,13 @@ import type { TagsService } from '../../../src/nest/tags/tags.service';
|
||||
import type { CategoriesService } from '../../../src/nest/categories/categories.service';
|
||||
import type { TodoService } from '../../../src/nest/todo/todo.service';
|
||||
import type { PackingService } from '../../../src/nest/packing/packing.service';
|
||||
import type { DayNotesService } from '../../../src/nest/days/day-notes.service';
|
||||
import type { PluginOAuthService } from '../../../src/nest/plugins/plugin-oauth.service';
|
||||
|
||||
// The factory under test, wired exactly like PluginsModule does — but with the
|
||||
// DI-native domain services replaced by the stubs above. The shim keeps the
|
||||
// ~45 historical call sites unchanged and supplies a default no-op router.
|
||||
const factory = new PluginHostDepsFactory(budgetStub, reservationsStub, tagsStub, categoriesStub, todoStub, packingStub, oauthStub);
|
||||
const factory = new PluginHostDepsFactory(budgetStub, reservationsStub, tagsStub, categoriesStub, todoStub, packingStub, oauthStub, dayNotesStub);
|
||||
const stubRouter: PluginCallRouter = { callPlugin: async () => undefined, emitPluginEvent: () => {} };
|
||||
const createRealRpcHost = (id: string, granted: ReadonlySet<string>, router: PluginCallRouter = stubRouter) => factory.create(id, granted, router);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user