mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
test(server): seed the small specs through the repositories
The suites with one to three raw statements left now seed and read their rows through the ORM factories instead of hand-written SQLite on the better-sqlite3 handle. A legacy statement that serves as a parity oracle, the schema introspection and the bare backup file keep their raw SQL and say why with a test-sql-allow marker. Two database mocks still answered a getPlaceWithTags the module no longer exports; that dead branch goes too, and the budget seam suite stubs the reservations repository directly instead of a fake prepare().
This commit is contained in:
@@ -47,7 +47,11 @@ import { PermissionsService } from '../../src/nest/permissions/permissions.servi
|
||||
import { TrekExceptionFilter } from '../../src/nest/common/trek-exception.filter';
|
||||
import { ZodValidationPipe } from '../../src/nest/common/zod-validation.pipe';
|
||||
import { TestUnitOfWorkModule } from '../helpers/test-uow';
|
||||
import { createTestMikroOrmModule } from '../helpers/test-orm';
|
||||
import { createTestMikroOrmModule, createTestOrm } from '../helpers/test-orm';
|
||||
import { makeUser } from '../helpers/factories/users';
|
||||
import { makeTrip } from '../helpers/factories/trips';
|
||||
import { upsertRow } from '../helpers/factories/rows';
|
||||
import { Addons } from '../../src/db/entities/Addons.entity';
|
||||
|
||||
/** A one-page PDF whose text layer holds `lines`, in the standard Helvetica. */
|
||||
function pdfWithText(lines: string[]): Buffer {
|
||||
@@ -134,15 +138,23 @@ describe('Booking import e2e (#2477): a schema-bound provider on the upload rout
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
db.prepare(
|
||||
"INSERT INTO users (id, username, email, password_hash, role, password_version) VALUES (1, 'e2e-user', 'e2e@example.test', 'x', 'user', 0)",
|
||||
).run();
|
||||
tripId = Number(db.prepare("INSERT INTO trips (user_id, title) VALUES (1, 'Albania')").run().lastInsertRowid);
|
||||
const orm = await createTestOrm(db);
|
||||
await makeUser(orm, { id: 1, username: 'e2e-user', email: 'e2e@example.test', role: 'user', password_version: 0 });
|
||||
tripId = (await makeTrip(orm, 1, { title: 'Albania' })).id;
|
||||
// The instance config the reporter ran: Gemini behind the "openai" provider.
|
||||
db.prepare(
|
||||
`INSERT INTO addons (id, name, type, enabled, config) VALUES ('llm_parsing', 'AI Parsing', 'integration', 1, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET enabled = 1, config = excluded.config`,
|
||||
).run(JSON.stringify({ provider: 'openai', model: 'gemini-3.5-flash', baseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai' }));
|
||||
await upsertRow(
|
||||
orm,
|
||||
Addons,
|
||||
{
|
||||
id: 'llm_parsing',
|
||||
name: 'AI Parsing',
|
||||
type: 'integration',
|
||||
enabled: true,
|
||||
config: { provider: 'openai', model: 'gemini-3.5-flash', baseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai' },
|
||||
},
|
||||
['enabled', 'config'],
|
||||
);
|
||||
await orm.close();
|
||||
app = await build();
|
||||
vi.spyOn(app.get(PermissionsService), 'checkPermission').mockResolvedValue(true);
|
||||
server = app.getHttpServer();
|
||||
|
||||
@@ -58,7 +58,8 @@ import { db } from '../../src/db/database';
|
||||
import { createUser } from '../helpers/factories';
|
||||
import { AuthModule } from '../../src/nest/auth/auth.module';
|
||||
import { TestUnitOfWorkModule } from '../helpers/test-uow';
|
||||
import { createTestMikroOrmModule } from '../helpers/test-orm';
|
||||
import { createTestMikroOrmModule, createTestOrm } from '../helpers/test-orm';
|
||||
import { setAppSetting } from '../helpers/factories/settings';
|
||||
import { TrekExceptionFilter } from '../../src/nest/common/trek-exception.filter';
|
||||
import { ZodValidationPipe } from '../../src/nest/common/zod-validation.pipe';
|
||||
|
||||
@@ -105,10 +106,11 @@ describe('Mailer e2e: the header logo in a mail on the wire (#2507)', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
email = createUser(db as never, { username: 'mail-e2e', email: 'mail-e2e@example.test' }).user.email;
|
||||
const setting = db.prepare('INSERT OR REPLACE INTO app_settings (key, value) VALUES (?, ?)');
|
||||
setting.run('smtp_host', 'mail.internal.example');
|
||||
setting.run('smtp_port', '587');
|
||||
setting.run('smtp_from', 'trek@example.test');
|
||||
const orm = await createTestOrm(db);
|
||||
await setAppSetting(orm, 'smtp_host', 'mail.internal.example');
|
||||
await setAppSetting(orm, 'smtp_port', '587');
|
||||
await setAppSetting(orm, 'smtp_from', 'trek@example.test');
|
||||
await orm.close();
|
||||
app = await build();
|
||||
server = app.getHttpServer();
|
||||
|
||||
|
||||
@@ -37,7 +37,11 @@ import { RateLimitService } from '../../src/nest/common/rate-limit.service';
|
||||
import { TrekExceptionFilter } from '../../src/nest/common/trek-exception.filter';
|
||||
import { ZodValidationPipe } from '../../src/nest/common/zod-validation.pipe';
|
||||
import { TestUnitOfWorkModule } from '../helpers/test-uow';
|
||||
import { createTestMikroOrmModule } from '../helpers/test-orm';
|
||||
import { createTestMikroOrmModule, createTestOrm, type TestOrm } from '../helpers/test-orm';
|
||||
import { deleteRows } from '../helpers/factories/rows';
|
||||
import { setAppSetting } from '../helpers/factories/settings';
|
||||
import { AppSettings } from '../../src/db/entities/AppSettings.entity';
|
||||
import { PlaceDetailsCache } from '../../src/db/entities/PlaceDetailsCache.entity';
|
||||
|
||||
const BODY = { lat: 50.9, lng: 6.96, name: 'Museum Ludwig', placeId: 'way:12345' };
|
||||
|
||||
@@ -45,6 +49,7 @@ describe('Place enrichment e2e (real auth guard + real validation pipe)', () =>
|
||||
let server: Server;
|
||||
let app: Awaited<ReturnType<typeof build>>;
|
||||
let maps: MapsService;
|
||||
let orm: TestOrm;
|
||||
|
||||
async function build() {
|
||||
const moduleRef = await Test.createTestingModule({ imports: [await TestUnitOfWorkModule.forRoot(db), await createTestMikroOrmModule(db), PlaceEnrichmentModule] }).compile();
|
||||
@@ -60,6 +65,7 @@ describe('Place enrichment e2e (real auth guard + real validation pipe)', () =>
|
||||
|
||||
beforeAll(async () => {
|
||||
seedUser(db as never, { id: 1 });
|
||||
orm = await createTestOrm(db);
|
||||
app = await build();
|
||||
server = app.getHttpServer();
|
||||
|
||||
@@ -75,11 +81,12 @@ describe('Place enrichment e2e (real auth guard + real validation pipe)', () =>
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
await orm.close();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
db.prepare('DELETE FROM app_settings').run();
|
||||
db.prepare('DELETE FROM place_details_cache').run();
|
||||
await deleteRows(orm, AppSettings);
|
||||
await deleteRows(orm, PlaceDetailsCache);
|
||||
await app.get(RateLimitService).reset('place_enrichment');
|
||||
// spyOn hands back the same spy on a second call, so the call counts carry
|
||||
// over between tests unless they are cleared explicitly.
|
||||
@@ -159,7 +166,7 @@ describe('Place enrichment e2e (real auth guard + real validation pipe)', () =>
|
||||
});
|
||||
|
||||
it('200 with the disabled envelope once an admin switches enrichment off', async () => {
|
||||
db.prepare("INSERT INTO app_settings (key, value) VALUES ('places_enrich_enabled', 'false')").run();
|
||||
await setAppSetting(orm, 'places_enrich_enabled', 'false');
|
||||
|
||||
const res = await request(server).post('/api/maps/enrichment').set('Cookie', sessionCookie(1)).send(BODY);
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ vi.mock('../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled: () => plu
|
||||
|
||||
import { db } from '../../src/db/database';
|
||||
import { TestUnitOfWorkModule } from '../helpers/test-uow';
|
||||
import { createTestMikroOrmModule } from '../helpers/test-orm';
|
||||
import { createTestMikroOrmModule, createTestOrm } from '../helpers/test-orm';
|
||||
import { makeUser } from '../helpers/factories/users';
|
||||
import { makePlugin } from '../helpers/factories/plugins';
|
||||
|
||||
const trailheads = { id: 'trailheads', label: 'Trailheads', icon: 'Signpost', color: '#2f855a' };
|
||||
const query = { pluginId: 'trail-finder', category: 'trailheads', south: '47', west: '11', north: '47.5', east: '11.5', lang: 'de' };
|
||||
@@ -66,14 +68,16 @@ describe('Plugin POIs e2e (real guard chain + temp SQLite)', () => {
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
// harness.ts's seedUser() omits password_hash, which the migrated schema
|
||||
// requires NOT NULL (addons.e2e.test.ts does the same) — the same SeededUser
|
||||
// shape sessionCookie(1) needs, with the hash filled in.
|
||||
db.prepare(
|
||||
"INSERT INTO users (id, username, email, password_hash, role, password_version) VALUES (1, 'e2e-user', 'e2e@example.test', 'x', 'user', 0)",
|
||||
).run();
|
||||
db.prepare("INSERT INTO plugins (id, name, status, capabilities, granted_permissions) VALUES (?, ?, 'active', ?, ?)")
|
||||
.run('trail-finder', 'Trail Finder', JSON.stringify({ poiCategories: [trailheads] }), JSON.stringify(['hook:poi-category-provider']));
|
||||
// The user sessionCookie(1) is signed for, pinned to id 1.
|
||||
const orm = await createTestOrm(db);
|
||||
await makeUser(orm, { id: 1, username: 'e2e-user', email: 'e2e@example.test', role: 'user', password_version: 0 });
|
||||
await makePlugin(orm, 'trail-finder', {
|
||||
name: 'Trail Finder',
|
||||
status: 'active',
|
||||
capabilities: JSON.stringify({ poiCategories: [trailheads] }),
|
||||
granted_permissions: JSON.stringify(['hook:poi-category-provider']),
|
||||
});
|
||||
await orm.close();
|
||||
app = await build();
|
||||
const hooks = app.get(PluginHooks, { strict: false });
|
||||
providersOf = vi.spyOn(hooks, 'providersOf');
|
||||
|
||||
Reference in New Issue
Block a user