mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 07:26:30 +00:00
test(assistant): the new end to end tests create their book inside a request context
This commit is contained in:
@@ -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` };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user