test(assistant): the new end to end tests create their book inside a request context

This commit is contained in:
Maurice
2026-10-22 22:59:32 +00:00
parent 3eded5f5be
commit 7d736e1a34
2 changed files with 6 additions and 2 deletions
@@ -24,6 +24,7 @@
import { buildApp } from '../../src/bootstrap';
import { JourneyBookRevisions } from '../../src/db/entities/JourneyBookRevisions.entity';
import { JourneyContributors } from '../../src/db/entities/JourneyContributors.entity';
import { withRequestContext } from '../../src/nest/database/request-context';
import { JourneyBookEditService } from '../../src/nest/journey/journey-book-edit.service';
import { addJourneyContributor, makeJourney, makeJourneyEntry } from '../helpers/factories/journeys';
import { countRows, findRow, updateRows } from '../helpers/factories/rows';
@@ -246,7 +247,8 @@ async function journeyWithBook() {
const journey = await makeJourney(orm, user.id, { title: 'Lisbon' });
await makeJourneyEntry(orm, journey.id, user.id, { title: 'Alfama', story: 'Trams.', entry_date: '2026-05-02' });
await makeJourneyEntry(orm, journey.id, user.id, { title: 'Belem', story: 'Pasteis.', entry_date: '2026-05-03' });
const created = await books.createBook(journey.id, user.id, {});
// A service called from the test, not through a route, needs the request context a route gets.
const created = await withRequestContext(orm, () => books.createBook(journey.id, user.id, {}));
broadcasts.broadcastToUser.mockClear();
return { ownerId: user.id, journeyId: journey.id, created, base: `/api/journeys/${journey.id}/assistant` };
}
@@ -34,6 +34,7 @@ import { AnthropicMessagesClient } from '../../src/nest/ai-connections/providers
import { OpenAiChatClient } from '../../src/nest/ai-connections/providers/openai-chat.client';
import { OpenAiResponsesClient } from '../../src/nest/ai-connections/providers/openai-responses.client';
import type { AiFetch } from '../../src/nest/ai-connections/providers/provider-http';
import { withRequestContext } from '../../src/nest/database/request-context';
import { JourneyBookEditService } from '../../src/nest/journey/journey-book-edit.service';
import { makeJourney } from '../helpers/factories/journeys';
import { setAddonEnabled } from '../helpers/factories/settings';
@@ -281,7 +282,8 @@ function studioTab(journeyId: number, userId: number) {
async function ownerWithBook() {
const { user } = await makeUser(orm);
const journey = await makeJourney(orm, user.id, { title: 'Portugal by train' });
const created = await books.createBook(journey.id, user.id, {});
// A service called from the test, not through a route, needs the request context a route gets.
const created = await withRequestContext(orm, () => books.createBook(journey.id, user.id, {}));
const inner = created.pages.find((page) => page.role === 'inner')?.id ?? 'no inner page';
return { userId: user.id, journeyId: journey.id, inner, base: `/api/journeys/${journey.id}/assistant` };
}