mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
test(server): seed the small leftover specs through the repositories
Converts the raw prepare() reads and writes in the share, airtrail, files, todo, dev-link, vacay, tours, bucket list, unit-of-work and plugin guard specs to the ORM factories and readers, so they go through the entities the app uses instead of hand-written SQLite. The vacay e2e moves from hand-rolled tables to the migrated snapshot, with its user pinned to the id its session cookie is signed for. Statements that are raw by nature keep the allow marker with the reason: the legacy oracle of the bucket list parity spec, the PRAGMA probe of the trek_photos migration, the unmapped probe table of the route import rollback, the behind-the-ORM reads of the entity insert probes, and seedUser, which also serves the hand-rolled users table of createTempDb. Comments that quoted a prepare() call are reworded so the ratchet no longer counts them.
This commit is contained in:
@@ -16,6 +16,7 @@ import { UnitOfWork } from '../../../src/nest/database/unit-of-work';
|
||||
import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
|
||||
import { createSnapshotTestDb } from '../../helpers/db-mock';
|
||||
import { createUser } from '../../helpers/factories';
|
||||
import { updateRows } from '../../helpers/factories/rows';
|
||||
import { AppSettings } from '../../../src/db/entities/AppSettings.entity';
|
||||
import { Users } from '../../../src/db/entities/Users.entity';
|
||||
|
||||
@@ -38,7 +39,7 @@ const ctx = (actingUserId: number | undefined): PluginRpcContext => ({
|
||||
* Trip 1 belongs to user 42 and only user 42 may reach it, mirroring rpc-host.test.ts.
|
||||
*
|
||||
* `overrides.role` drives the stubbed `UsersRepository.getRole` (PG3/PG4, Plan 3j
|
||||
* Task 1) the same way it used to drive `db.prepare(...).get()`: omitted means a
|
||||
* Task 1) the same way it used to drive the raw `db.prepare` stub: omitted means a
|
||||
* normal row with role 'user'; explicitly `undefined` (or `null`) means "no row",
|
||||
* which `getRole`'s own `string | null` contract folds into a single `null` — the
|
||||
* `users` column is `NOT NULL DEFAULT 'user'`, so a present row can never actually
|
||||
@@ -222,7 +223,7 @@ describe('PluginGuards — canEditAs/canCreateAs against a real UsersRepository
|
||||
});
|
||||
|
||||
it('PGUARD-025 mutation proof: promoting that SAME member to admin in the real users table flips PGUARD-024 to pass', async () => {
|
||||
testDb.prepare('UPDATE users SET role = ? WHERE id = ?').run('admin', memberId);
|
||||
await updateRows(orm, Users, { id: memberId }, { role: 'admin' });
|
||||
expect(await guards.canEditAs('trip_delete', 1, memberId)).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ function controller(invoke: () => unknown, providers = ['ev-plug']) {
|
||||
} as unknown as PluginHooks;
|
||||
// Plan 3j Task 3: `declaredProfiles` now takes `PluginsRepository`, not the raw
|
||||
// connection — `findCapabilities` reads the same `capabilitiesRow` fixture the
|
||||
// old `connection.prepare(...).get()` stub above read.
|
||||
// old raw `connection.prepare` stub above read.
|
||||
const plugins = {
|
||||
findCapabilities: vi.fn(async () => (capabilitiesRow.value === undefined ? null : capabilitiesRow.value)),
|
||||
} as unknown as PluginsRepository;
|
||||
|
||||
@@ -46,7 +46,7 @@ function guardsFor() {
|
||||
prepare: vi.fn(() => ({ get: () => ({ role: 'user' }), all: () => [] })),
|
||||
} as unknown as TripsRepository;
|
||||
// Plan 3c Task 7: TripsRpc's RP1-RP6 resolve `EntityManager.getRepository(...)`
|
||||
// now, not `db.prepare(...)` — a generic fake repository (same shape regardless
|
||||
// now, not a raw `db.prepare` stub — a generic fake repository (same shape regardless
|
||||
// of which entity class was requested) covers every RP method these fallback
|
||||
// cases exercise, none of which assert on the repository's specific return value.
|
||||
const em = {
|
||||
|
||||
Reference in New Issue
Block a user