mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user