Files
TREK/server/tests/helpers/factories/places.ts
T
Maurice c37d3f773e fix(assistant): readable cards for any tool, and the CI round
- A card for a tool without one of its own names what it works on: the place
  of an assignment, the day, the note, the booking; its arguments sit under
  the labels the other cards use, a new order reads as the names in order.
  28 frequent tools carry their own action name in every language.
- The server's own steps without a card still refuse, as before.
- Tests: the rate limit is asked one request after another, the mention list
  closes on the caret move a browser reports, the place factory hands its
  category over as a plain id, eleven files formatted.
2026-10-22 21:30:37 +00:00

76 lines
2.4 KiB
TypeScript

import { Categories } from '../../../src/db/entities/Categories.entity';
import { Places } from '../../../src/db/entities/Places.entity';
import { Tags } from '../../../src/db/entities/Tags.entity';
import { inContext, nextSeq, type FactoryOrm } from './context';
import { createRow } from './rows';
import type { EntityData, EntityDTO } from '@mikro-orm/core';
export type PlaceRow = EntityDTO<Places>;
export type CategoryRow = EntityDTO<Categories>;
export type TagRow = EntityDTO<Tags>;
/** A category; global unless `user` names an owner. */
export function makeCategory(orm: FactoryOrm, overrides: EntityData<Categories> = {}): Promise<CategoryRow> {
return createRow(
orm,
Categories,
{ name: `Test Category ${nextSeq('category')}`, color: '#6366f1', icon: '📍' },
overrides,
);
}
/** A tag owned by `userId`. */
export function makeTag(orm: FactoryOrm, userId: number, overrides: EntityData<Tags> = {}): Promise<TagRow> {
return createRow(
orm,
Tags,
{
user: userId,
name: `Test Tag ${nextSeq('tag')}`,
color: '#10b981',
},
overrides,
);
}
/** The lowest-id category, the one a place gets when the test names none. */
function firstCategoryId(orm: FactoryOrm): Promise<number | null> {
return inContext(orm, async (em) => {
const [first] = await em.find(Categories, {}, { orderBy: { id: 'asc' }, limit: 1, disableIdentityMap: true });
return first?.id ?? null;
});
}
/**
* A place on the trip, in Paris unless told otherwise, filed under the first
* seeded category when `category` is not given (pass `category: null` for
* an uncategorised one).
*/
export async function makePlace(
orm: FactoryOrm,
tripId: number,
overrides: EntityData<Places> = {},
): Promise<PlaceRow> {
// A plain id (or null): the relation's own type, checked against the whole row, runs tsc past its depth.
const given = 'category' in overrides ? overrides.category : await firstCategoryId(orm);
const category = (given ?? null) as number | null;
return createRow(
orm,
Places,
{
trip: tripId,
name: 'Test Place',
lat: 48.8566,
lng: 2.3522,
description: null,
category,
},
{ ...overrides, category },
);
}
/** Puts the tags on the place; tags it already has are skipped. */
export async function tagPlace(orm: FactoryOrm, placeId: number, tagIds: number[]): Promise<void> {
await inContext(orm, (em) => em.getRepository(Tags).insertIgnore(placeId, tagIds));
}