Files
TREK/server/tests/helpers/factories/atlas.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

44 lines
1.5 KiB
TypeScript

import { BucketList } from '../../../src/db/entities/BucketList.entity';
import { VisitedCountries } from '../../../src/db/entities/VisitedCountries.entity';
import { VisitedRegions } from '../../../src/db/entities/VisitedRegions.entity';
import type { FactoryOrm } from './context';
import { createRow, insertRowIgnoringConflict } from './rows';
import type { EntityData, EntityDTO } from '@mikro-orm/core';
export type BucketListRow = EntityDTO<BucketList>;
/** A destination on the user's bucket list. */
export function makeBucketListItem(
orm: FactoryOrm,
userId: number,
overrides: EntityData<BucketList> = {},
): Promise<BucketListRow> {
return createRow(
orm,
BucketList,
{
user: userId,
name: 'Test Destination',
lat: null,
lng: null,
country_code: null,
notes: null,
},
overrides,
);
}
/** Marks the country visited by hand; marking it twice is a no-op. The code is upper-cased as the atlas stores it. */
export async function markCountryVisited(orm: FactoryOrm, userId: number, countryCode: string): Promise<void> {
await insertRowIgnoringConflict(orm, VisitedCountries, { user: userId, country_code: countryCode.toUpperCase() });
}
/** Marks the region visited; marking it twice is a no-op. */
export async function markRegionVisited(
orm: FactoryOrm,
userId: number,
region: { region_code: string; region_name: string; country_code: string },
): Promise<void> {
await insertRowIgnoringConflict(orm, VisitedRegions, { user: userId, ...region });
}