mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-24 07:53:09 +00:00
1bba65634c
The server suite seeds and reads its database through some 5,500 raw better-sqlite3 statements on the sync handle. They restate the schema by hand, skip the repositories the app goes through and run on SQLite only, so nothing in the suite could ever exercise the dialect layer on another engine. tests/helpers/factories/ adds typed factories per domain (users, trips and days, places, assignments, bookings, budget, packing, to-dos, files, journeys, tours, collections, notifications, settings, plugins, tokens, atlas, vacay, photos, collab) and generic readers (findRow, findRows, countRows, updateRows, deleteRows) that go through MikroORM in a request context of their own, against the app's ORM or a createTestOrm handle. They refuse a write to a read-only foreign-key twin, which MikroORM would otherwise drop without a word. The README there is the conversion guide. The categories integration suite and the tags and calendar-feed e2e suites are converted in full as worked examples; the tags suite also moves from hand-rolled tables to the migrated snapshot. lint:test-sql (scripts/test-sql-ratchet.mjs) holds the raw statements left to a per-file baseline: growth and stale entries fail, files whose subject is raw SQL are exempt with a reason, and a single statement can be allowed with a test-sql-allow comment. CI runs it next to lint:boundaries.
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import type { EntityData, EntityDTO } from '@mikro-orm/core';
|
|
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';
|
|
|
|
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 });
|
|
}
|