Files
TREK/server/tests/helpers/factories/todos.ts
T
Maurice 188c6153d5 test: factories hand their overrides over apart from the row
The assistant tables gave Users three more relations, and a spread of
overrides checked against RequiredEntityData now ran tsc past its
instantiation depth (TS2589). Every factory passes its overrides as
createRow's own argument, the way rows.ts documents it.
2026-10-22 21:30:36 +00:00

37 lines
1.0 KiB
TypeScript

import { TodoItems } from '../../../src/db/entities/TodoItems.entity';
import { inContext, type FactoryOrm } from './context';
import { createRow } from './rows';
import type { EntityData, EntityDTO } from '@mikro-orm/core';
export type TodoItemRow = EntityDTO<TodoItems>;
/** An open to-do on the trip, appended after the trip's last one. */
export async function makeTodoItem(
orm: FactoryOrm,
tripId: number,
overrides: EntityData<TodoItems> = {},
): Promise<TodoItemRow> {
const sortOrder =
overrides.sort_order ??
(await inContext(orm, async (em) => {
const last = await em.findOne(
TodoItems,
{ trip: tripId },
{ orderBy: { sort_order: 'desc' }, disableIdentityMap: true },
);
return last?.sort_order == null ? 0 : last.sort_order + 1;
}));
return createRow(
orm,
TodoItems,
{
trip: tripId,
name: 'Test Todo',
checked: 0,
category: null,
sort_order: sortOrder,
},
{ ...overrides, sort_order: sortOrder },
);
}