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.
This commit is contained in:
Maurice
2026-10-21 21:58:09 +02:00
parent ea7120e141
commit 77ad0a06d0
15 changed files with 239 additions and 159 deletions
+13 -9
View File
@@ -13,15 +13,19 @@ export function makeBucketListItem(
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,
});
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. */
+12 -8
View File
@@ -13,13 +13,17 @@ export function makeBudgetItem(
tripId: number,
overrides: EntityData<BudgetItems> = {},
): Promise<BudgetItemRow> {
return createRow(orm, BudgetItems, {
trip: tripId,
name: 'Test Budget Item',
category: 'Transport',
total_price: 100,
...overrides,
});
return createRow(
orm,
BudgetItems,
{
trip: tripId,
name: 'Test Budget Item',
category: 'Transport',
total_price: 100,
},
overrides,
);
}
/** Adds the user to the expense's split, with an explicit share when `amount` is given. */
@@ -29,7 +33,7 @@ export function addBudgetItemMember(
userId: number,
overrides: EntityData<BudgetItemMembers> = {},
): Promise<EntityDTO<BudgetItemMembers>> {
return createRow(orm, BudgetItemMembers, { budgetItem: budgetItemId, user: userId, ...overrides });
return createRow(orm, BudgetItemMembers, { budgetItem: budgetItemId, user: userId }, overrides);
}
/** Records that the user paid `amount` of the expense. */
+14 -10
View File
@@ -14,15 +14,19 @@ export function makeCollabNote(
userId: number,
overrides: EntityData<CollabNotes> = {},
): Promise<CollabNoteRow> {
return createRow(orm, CollabNotes, {
trip: tripId,
user: userId,
title: 'Test Note',
content: null,
category: 'General',
color: '#6366f1',
...overrides,
});
return createRow(
orm,
CollabNotes,
{
trip: tripId,
user: userId,
title: 'Test Note',
content: null,
category: 'General',
color: '#6366f1',
},
overrides,
);
}
/** A chat message on the trip; `replyToRef` makes it a reply. */
@@ -32,5 +36,5 @@ export function makeCollabMessage(
userId: number,
overrides: EntityData<CollabMessages> = {},
): Promise<CollabMessageRow> {
return createRow(orm, CollabMessages, { trip: tripId, user: userId, text: 'Test message', ...overrides });
return createRow(orm, CollabMessages, { trip: tripId, user: userId, text: 'Test message' }, overrides);
}
+32 -20
View File
@@ -14,11 +14,15 @@ export function makeCollection(
ownerId: number,
overrides: EntityData<Collections> = {},
): Promise<CollectionRow> {
return createRow(orm, Collections, {
owner: ownerId,
name: `Test Collection ${nextSeq('collection')}`,
...overrides,
});
return createRow(
orm,
Collections,
{
owner: ownerId,
name: `Test Collection ${nextSeq('collection')}`,
},
overrides,
);
}
/** Invites the user into the collection; `status: 'accepted'` makes them a member right away. */
@@ -28,13 +32,17 @@ export function addCollectionMember(
userId: number,
overrides: EntityData<CollectionMembers> = {},
): Promise<EntityDTO<CollectionMembers>> {
return createRow(orm, CollectionMembers, {
collection: collectionId,
user: userId,
status: 'accepted',
role: 'editor',
...overrides,
});
return createRow(
orm,
CollectionMembers,
{
collection: collectionId,
user: userId,
status: 'accepted',
role: 'editor',
},
overrides,
);
}
/** A place saved into the collection by `ownerId`. */
@@ -44,14 +52,18 @@ export function makeCollectionPlace(
ownerId: number,
overrides: EntityData<CollectionPlaces> = {},
): Promise<CollectionPlaceRow> {
return createRow(orm, CollectionPlaces, {
collection: collectionId,
owner: ownerId,
name: `Saved Place ${nextSeq('collection-place')}`,
lat: 48.8566,
lng: 2.3522,
...overrides,
});
return createRow(
orm,
CollectionPlaces,
{
collection: collectionId,
owner: ownerId,
name: `Saved Place ${nextSeq('collection-place')}`,
lat: 48.8566,
lng: 2.3522,
},
overrides,
);
}
/** Puts the tags on the saved place. */
+12 -8
View File
@@ -17,14 +17,18 @@ export function makeTripFile(
overrides: EntityData<TripFiles> = {},
): Promise<TripFileRow> {
const n = nextSeq('trip-file');
return createRow(orm, TripFiles, {
trip: tripId,
filename: `test-file-${n}.pdf`,
original_name: `Test File ${n}.pdf`,
file_size: 1024,
mime_type: 'application/pdf',
...overrides,
});
return createRow(
orm,
TripFiles,
{
trip: tripId,
filename: `test-file-${n}.pdf`,
original_name: `Test File ${n}.pdf`,
file_size: 1024,
mime_type: 'application/pdf',
},
overrides,
);
}
/** Links the file to a booking, an assignment, a place or an expense (name exactly one in `target`). */
+28 -20
View File
@@ -20,15 +20,19 @@ export async function makeJourney(
overrides: EntityData<Journeys> = {},
): Promise<JourneyRow> {
const now = Date.now();
const journey = await createRow(orm, Journeys, {
user: userId,
title: `Test Journey ${nextSeq('journey')}`,
subtitle: null,
status: 'active',
created_at: now,
updated_at: now,
...overrides,
});
const journey = await createRow(
orm,
Journeys,
{
user: userId,
title: `Test Journey ${nextSeq('journey')}`,
subtitle: null,
status: 'active',
created_at: now,
updated_at: now,
},
overrides,
);
await insertRow(orm, JourneyContributors, { journey: journey.id, user: userId, role: 'owner', added_at: now });
return journey;
}
@@ -41,17 +45,21 @@ export function makeJourneyEntry(
overrides: EntityData<JourneyEntries> = {},
): Promise<JourneyEntryRow> {
const now = Date.now();
return createRow(orm, JourneyEntries, {
journey: journeyId,
author: authorId,
type: 'entry',
entry_date: '2026-01-15',
visibility: 'private',
sort_order: 0,
created_at: now,
updated_at: now,
...overrides,
});
return createRow(
orm,
JourneyEntries,
{
journey: journeyId,
author: authorId,
type: 'entry',
entry_date: '2026-01-15',
visibility: 'private',
sort_order: 0,
created_at: now,
updated_at: now,
},
overrides,
);
}
/** Adds the user as a contributor; an existing contributor keeps their role. */
+14 -10
View File
@@ -13,16 +13,20 @@ export function makeNotification(
recipientId: number,
overrides: EntityData<Notifications> = {},
): Promise<NotificationRow> {
return createRow(orm, Notifications, {
recipient: recipientId,
type: 'simple',
scope: 'user',
target: recipientId,
title_key: 'notifications.test.title',
text_key: 'notifications.test.text',
is_read: 0,
...overrides,
});
return createRow(
orm,
Notifications,
{
recipient: recipientId,
type: 'simple',
scope: 'user',
target: recipientId,
title_key: 'notifications.test.title',
text_key: 'notifications.test.text',
is_read: 0,
},
overrides,
);
}
/** Sets the instance's active notification channels ('email', 'webhook', 'email,webhook', 'none'). */
+20 -12
View File
@@ -13,13 +13,17 @@ export function makePackingItem(
tripId: number,
overrides: EntityData<PackingItems> = {},
): Promise<PackingItemRow> {
return createRow(orm, PackingItems, {
trip: tripId,
name: 'Test Item',
category: 'Clothing',
checked: 0,
...overrides,
});
return createRow(
orm,
PackingItems,
{
trip: tripId,
name: 'Test Item',
category: 'Clothing',
checked: 0,
},
overrides,
);
}
/** A bag on the trip. */
@@ -28,11 +32,15 @@ export function makePackingBag(
tripId: number,
overrides: EntityData<PackingBags> = {},
): Promise<PackingBagRow> {
return createRow(orm, PackingBags, {
trip: tripId,
name: `Bag ${nextSeq('packing-bag')}`,
...overrides,
});
return createRow(
orm,
PackingBags,
{
trip: tripId,
name: `Bag ${nextSeq('packing-bag')}`,
},
overrides,
);
}
/** Shares the bag with the users; pairs that already exist are skipped. */
+23 -15
View File
@@ -21,12 +21,16 @@ export function makeCategory(orm: FactoryOrm, overrides: EntityData<Categories>
/** 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,
});
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. */
@@ -48,15 +52,19 @@ export async function makePlace(
overrides: EntityData<Places> = {},
): Promise<PlaceRow> {
const category = 'category' in overrides ? overrides.category : await firstCategoryId(orm);
return createRow(orm, Places, {
trip: tripId,
name: 'Test Place',
lat: 48.8566,
lng: 2.3522,
description: null,
...overrides,
category,
});
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. */
+11 -7
View File
@@ -14,7 +14,7 @@ export type PluginRow = EntityDTO<Plugins>;
* settings surface wants.
*/
export async function makePlugin(orm: FactoryOrm, id: string, overrides: EntityData<Plugins> = {}): Promise<PluginRow> {
await insertRow(orm, Plugins, { id, name: id, version: '1.0.0', ...overrides });
await insertRow(orm, Plugins, { id, name: id, version: '1.0.0' }, overrides);
const plugin = await findRow(orm, Plugins, { id });
if (!plugin) throw new Error(`makePlugin: no plugin ${id} after its insert`);
return plugin;
@@ -27,12 +27,16 @@ export function makePluginSettingsField(
fieldKey: string,
overrides: EntityData<PluginSettingsFields> = {},
): Promise<EntityDTO<PluginSettingsFields>> {
return createRow(orm, PluginSettingsFields, {
plugin_id: pluginId,
field_key: fieldKey,
label: fieldKey,
...overrides,
});
return createRow(
orm,
PluginSettingsFields,
{
plugin_id: pluginId,
field_key: fieldKey,
label: fieldKey,
},
overrides,
);
}
/** Stores the user's config for the plugin as JSON, replacing any earlier one. */
+25 -17
View File
@@ -14,13 +14,17 @@ export function makeReservation(
tripId: number,
overrides: EntityData<Reservations> = {},
): Promise<ReservationRow> {
return createRow(orm, Reservations, {
trip: tripId,
title: 'Test Reservation',
type: 'flight',
day: null,
...overrides,
});
return createRow(
orm,
Reservations,
{
trip: tripId,
title: 'Test Reservation',
type: 'flight',
day: null,
},
overrides,
);
}
/**
@@ -32,16 +36,20 @@ export function makeReservationEndpoint(
reservationId: number,
overrides: EntityData<ReservationEndpoints> = {},
): Promise<ReservationEndpointRow> {
return createRow(orm, ReservationEndpoints, {
reservation: reservationId,
role: 'from',
sequence: 0,
name: 'Paris Charles de Gaulle',
code: 'CDG',
lat: 49.0097,
lng: 2.5479,
...overrides,
});
return createRow(
orm,
ReservationEndpoints,
{
reservation: reservationId,
role: 'from',
sequence: 0,
name: 'Paris Charles de Gaulle',
code: 'CDG',
lat: 49.0097,
lng: 2.5479,
},
overrides,
);
}
/** Puts the user on the booking's traveller list. */
+12 -8
View File
@@ -21,12 +21,16 @@ export async function makeTodoItem(
);
return last?.sort_order == null ? 0 : last.sort_order + 1;
}));
return createRow(orm, TodoItems, {
trip: tripId,
name: 'Test Todo',
checked: 0,
category: null,
...overrides,
sort_order: sortOrder,
});
return createRow(
orm,
TodoItems,
{
trip: tripId,
name: 'Test Todo',
checked: 0,
category: null,
sort_order: sortOrder,
},
{ ...overrides, sort_order: sortOrder },
);
}
+11 -7
View File
@@ -65,11 +65,15 @@ export function makeInviteToken(
createdBy: number,
overrides: EntityData<InviteTokens> = {},
): Promise<EntityDTO<InviteTokens>> {
return createRow(orm, InviteTokens, {
token: `test-invite-${nextSeq('invite-token')}`,
max_uses: 1,
used_count: 0,
createdByRef: createdBy,
...overrides,
});
return createRow(
orm,
InviteTokens,
{
token: `test-invite-${nextSeq('invite-token')}`,
max_uses: 1,
used_count: 0,
createdByRef: createdBy,
},
overrides,
);
}
+10 -6
View File
@@ -122,10 +122,14 @@ export function makeShareToken(
>
> = {},
): Promise<EntityDTO<ShareTokens>> {
return createRow(orm, ShareTokens, {
trip: tripId,
createdByRef: createdBy,
token: overrides.token ?? `share-${nextSeq('share-token')}-${tripId}`,
...overrides,
});
return createRow(
orm,
ShareTokens,
{
trip: tripId,
createdByRef: createdBy,
token: overrides.token ?? `share-${nextSeq('share-token')}-${tripId}`,
},
overrides,
);
}
+2 -2
View File
@@ -13,7 +13,7 @@ export function makeVacayPlan(
ownerId: number,
overrides: EntityData<VacayPlans> = {},
): Promise<VacayPlanRow> {
return createRow(orm, VacayPlans, { owner: ownerId, ...overrides });
return createRow(orm, VacayPlans, { owner: ownerId }, overrides);
}
/** Invites the user into the plan; `status: 'accepted'` (the default here) makes them a member. */
@@ -34,5 +34,5 @@ export function makeVacayEntry(
date: string,
overrides: EntityData<VacayEntries> = {},
): Promise<EntityDTO<VacayEntries>> {
return createRow(orm, VacayEntries, { plan: planId, user: userId, date, ...overrides });
return createRow(orm, VacayEntries, { plan: planId, user: userId, date }, overrides);
}