test(server): seed the session, lease and rollback specs through the factories

The specs written alongside the session, transaction and lifecycle work
still seeded and read with raw statements. They go through the ORM
factories now; the few that test SQL below the ORM carry a test-sql-allow
reason. The raw SQL baseline holds 177 statements in 6 files.
This commit is contained in:
Maurice
2026-10-08 19:05:04 +02:00
parent ccf8c4309a
commit be016f180e
30 changed files with 254 additions and 438 deletions
@@ -17,6 +17,11 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { createSnapshotTestDb } from '../../helpers/db-mock';
import { createPluginRpcHostParts } from '../../helpers/plugin-host';
import { sharedTestOrm } from '../../helpers/test-uow';
import { updateRows } from '../../helpers/factories/rows';
import { readTripDays } from '../../helpers/factories/trips';
import { tagPlace } from '../../helpers/factories/places';
import { Trips } from '../../../src/db/entities/Trips.entity';
import {
addTripMember,
createBudgetItem,
@@ -63,6 +68,7 @@ const tableOf = (entity: PluginEntityName): string => {
};
const columnsOf = (table: string): string[] =>
// test-sql-allow: the check is against the columns the migrated table has, which only PRAGMA table_info reports.
(testDb.prepare(`PRAGMA table_info(${table})`).all() as Array<{ name: string }>).map((c) => c.name);
describe('the output contract against the migrated schema', () => {
@@ -138,13 +144,12 @@ describe('the output contract drops only the withheld fields', () => {
tripId = trip.id;
addTripMember(testDb, trip.id, member.id);
// A real credential in the row, so "withheld" is proven rather than vacuous.
testDb.prepare("UPDATE trips SET feed_token = 'feed-secret' WHERE id = ?").run(trip.id);
dayIds = (testDb.prepare('SELECT id FROM days WHERE trip_id = ? ORDER BY day_number').all(trip.id) as Array<{ id: number }>).map(
(d) => d.id,
);
const orm = await sharedTestOrm(testDb);
await updateRows(orm, Trips, { id: trip.id }, { feed_token: 'feed-secret' });
dayIds = (await readTripDays(orm, trip.id)).map((d) => d.id);
placeId = createPlace(testDb, trip.id).id;
const tag = createTag(testDb, owner.id);
testDb.prepare('INSERT INTO place_tags (place_id, tag_id) VALUES (?, ?)').run(placeId, tag.id);
await tagPlace(orm, placeId, [tag.id]);
createDayAssignment(testDb, dayIds[0], placeId);
createDayNote(testDb, dayIds[0], trip.id);
createBudgetItem(testDb, trip.id);
@@ -40,7 +40,7 @@ import { Plugins } from '../../../src/db/entities/Plugins.entity';
import { PluginOauthTokens } from '../../../src/db/entities/PluginOauthTokens.entity';
import { PluginOauthState } from '../../../src/db/entities/PluginOauthState.entity';
import { PluginSettingsFields } from '../../../src/db/entities/PluginSettingsFields.entity';
import { countRows, findRow, insertRow, updateRows } from '../../helpers/factories/rows';
import { countRows, findRow, findRows, insertRow, updateRows } from '../../helpers/factories/rows';
const CFG = {
oauth_authorize_url: 'https://provider.example/authorize',
@@ -130,8 +130,8 @@ describe('PluginOAuthService', () => {
const orm = await sharedTestOrm(getDb.current as Database.Database);
vi.spyOn(orm.repo(PluginOauthState), 'insertState').mockRejectedValueOnce(new Error('disk full'));
await expect(svc.startConnect('p', 42, NOW)).rejects.toThrow('disk full');
const rows = getDb.current as unknown as InstanceType<typeof Database>;
expect(rows.prepare('SELECT state FROM plugin_oauth_state WHERE user_id = 42').all()).toEqual([{ state: first }]);
const rows = await findRows(orm, PluginOauthState, { user_id: 42 });
expect(rows.map(({ state }) => ({ state }))).toEqual([{ state: first }]);
});
it('rejects a non-https / loopback / metadata / internal authorize endpoint', async () => {