mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
test(server): seed the atlas, settings, budget and notification specs through the factories
Eleven more suites (atlas and settings e2e, the bucket list, shadow pick
and Dawarich suggestion repositories, the budget and collab MCP tools,
notification preferences, VAPID keys, school holidays and tours) write
and read their rows through the ORM factories. Time-relative fixtures
that leaned on SQLite's date('now', ...) build the same text in JS with
dbNow(), and helpers that returned undefined for a missing row keep doing
so where an assertion depends on it. The legacy statements the parity
cases compare against stay raw, marked as oracles.
This commit is contained in:
@@ -35,12 +35,23 @@ import { AtlasModule } from '../../src/nest/atlas/atlas.module';
|
||||
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 { countRows, deleteRows, findRow, upsertRow } from '../helpers/factories/rows';
|
||||
import { markCountryVisited } from '../helpers/factories/atlas';
|
||||
import { makePlace } from '../helpers/factories/places';
|
||||
import { makeReservation, makeReservationEndpoint } from '../helpers/factories/reservations';
|
||||
import { makeMcpToken } from '../helpers/factories/tokens';
|
||||
import { BucketList } from '../../src/db/entities/BucketList.entity';
|
||||
import { HiddenCountries } from '../../src/db/entities/HiddenCountries.entity';
|
||||
import { PlaceRegions } from '../../src/db/entities/PlaceRegions.entity';
|
||||
import { VisitedCountries } from '../../src/db/entities/VisitedCountries.entity';
|
||||
import { VisitedRegions } from '../../src/db/entities/VisitedRegions.entity';
|
||||
|
||||
describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
let server: Server;
|
||||
let app: Awaited<ReturnType<typeof build>>;
|
||||
let userId: number;
|
||||
let orm: TestOrm;
|
||||
|
||||
async function build() {
|
||||
const moduleRef = await Test.createTestingModule({ imports: [await TestUnitOfWorkModule.forRoot(db), await createTestMikroOrmModule(db), AtlasModule] }).compile();
|
||||
@@ -56,12 +67,14 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
userId = createUser(db as never, { username: 'atlas-e2e', email: 'atlas-e2e@test.example' }).user.id;
|
||||
orm = await createTestOrm(db);
|
||||
app = await build();
|
||||
server = app.getHttpServer();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
await orm.close();
|
||||
});
|
||||
|
||||
it('401 without a session cookie', async () => {
|
||||
@@ -80,7 +93,7 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('200 stats for an authenticated user — the trip-less branch keeps its bespoke shape', async () => {
|
||||
db.prepare('INSERT OR IGNORE INTO visited_countries (user_id, country_code) VALUES (?, ?)').run(userId, 'JP');
|
||||
await markCountryVisited(orm, userId, 'JP');
|
||||
const res = await request(server).get('/api/addons/atlas/stats').set('Cookie', sessionCookie(userId));
|
||||
expect(res.status).toBe(200);
|
||||
// Zero-trip early return: has a `trips` key and only the four base stats —
|
||||
@@ -90,17 +103,17 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
trips: [],
|
||||
stats: { totalTrips: 0, totalPlaces: 0, totalCountries: 1, totalDays: 0 },
|
||||
});
|
||||
db.prepare('DELETE FROM visited_countries WHERE user_id = ?').run(userId);
|
||||
await deleteRows(orm, VisitedCountries, { user: userId });
|
||||
});
|
||||
|
||||
it('200 (not 201) on POST country mark, with upper-cased code written to the db', async () => {
|
||||
const res = await request(server).post('/api/addons/atlas/country/de/mark').set('Cookie', sessionCookie(userId));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ success: true });
|
||||
const row = db.prepare('SELECT country_code FROM visited_countries WHERE user_id = ?').get(userId);
|
||||
expect(row).toEqual({ country_code: 'DE' });
|
||||
db.prepare('DELETE FROM visited_countries WHERE user_id = ?').run(userId);
|
||||
db.prepare('DELETE FROM hidden_countries WHERE user_id = ?').run(userId);
|
||||
const row = await findRow(orm, VisitedCountries, { user: userId });
|
||||
expect(row?.country_code).toBe('DE');
|
||||
await deleteRows(orm, VisitedCountries, { user: userId });
|
||||
await deleteRows(orm, HiddenCountries, { user: userId });
|
||||
});
|
||||
|
||||
it('400 on region mark without country_code (ZodValidationPipe envelope)', async () => {
|
||||
@@ -109,7 +122,7 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
// The legacy hand-rolled 'name and country_code are required' body became
|
||||
// the pipe's `field: message` envelope with the atlas DTO ratchet.
|
||||
expect(res.body.error).toMatch(/^country_code: /);
|
||||
expect(db.prepare('SELECT COUNT(*) AS n FROM visited_regions WHERE user_id = ?').get(userId)).toEqual({ n: 0 });
|
||||
expect(await countRows(orm, VisitedRegions, { user: userId })).toBe(0);
|
||||
});
|
||||
|
||||
it("400 'Name is required' on whitespace-only bucket name (legacy trim guard survives the DTO)", async () => {
|
||||
@@ -136,8 +149,8 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
const res = await request(server).post('/api/addons/atlas/bucket-list').set('Cookie', sessionCookie(userId)).send({ name: 'Kyoto' });
|
||||
expect(res.status).toBe(201);
|
||||
expect(res.body.item.name).toBe('Kyoto');
|
||||
const row = db.prepare('SELECT name, user_id FROM bucket_list WHERE id = ?').get(res.body.item.id);
|
||||
expect(row).toEqual({ name: 'Kyoto', user_id: userId });
|
||||
const row = await findRow(orm, BucketList, { id: res.body.item.id });
|
||||
expect({ name: row?.name, user_id: row?.user_id }).toEqual({ name: 'Kyoto', user_id: userId });
|
||||
});
|
||||
|
||||
it('keeps a wished-for region, and refuses one outside the item country (#1901)', async () => {
|
||||
@@ -166,9 +179,9 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
const past = createTrip(db as never, plannerId, { title: 'Rome, last month', start_date: iso(-40), end_date: iso(-30) });
|
||||
const future = createTrip(db as never, plannerId, { title: 'Tokyo, next month', start_date: iso(30), end_date: iso(40) });
|
||||
// Address-only (no lat/lng), keeping the file's no-background-geocode property.
|
||||
const insertPlace = db.prepare('INSERT INTO places (trip_id, name, address) VALUES (?, ?, ?)');
|
||||
insertPlace.run(past.id, 'Colosseum', 'Piazza del Colosseo, Rome, Italy');
|
||||
insertPlace.run(future.id, 'Senso-ji', 'Asakusa, Tokyo, Japan');
|
||||
const unplaced = { lat: null, lng: null, category: null };
|
||||
await makePlace(orm, past.id, { ...unplaced, name: 'Colosseum', address: 'Piazza del Colosseo, Rome, Italy' });
|
||||
await makePlace(orm, future.id, { ...unplaced, name: 'Senso-ji', address: 'Asakusa, Tokyo, Japan' });
|
||||
|
||||
const res = await request(server).get('/api/addons/atlas/stats').set('Cookie', sessionCookie(plannerId));
|
||||
expect(res.status).toBe(200);
|
||||
@@ -200,16 +213,25 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
end_date: iso(-10),
|
||||
});
|
||||
const day = iso(-15);
|
||||
const insertFlight = db.prepare("INSERT INTO reservations (trip_id, title, type) VALUES (?, ?, 'flight')");
|
||||
const insertEndpoint = db.prepare(
|
||||
'INSERT INTO reservation_endpoints (reservation_id, role, sequence, name, lat, lng, code, local_date, local_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
);
|
||||
const inbound = insertFlight.run(trip.id, 'BRU-HEL').lastInsertRowid;
|
||||
insertEndpoint.run(inbound, 'from', 0, 'Brussels', 50.9014, 4.4844, 'BRU', day, '07:00');
|
||||
insertEndpoint.run(inbound, 'to', 1, 'Helsinki', 60.3172, 24.9633, 'HEL', day, '09:30');
|
||||
const onward = insertFlight.run(trip.id, 'HEL-JFK').lastInsertRowid;
|
||||
insertEndpoint.run(onward, 'from', 0, 'Helsinki', 60.3172, 24.9633, 'HEL', day, '11:00');
|
||||
insertEndpoint.run(onward, 'to', 1, 'New York', 40.6413, -73.7781, 'JFK', day, '15:00');
|
||||
const insertFlight = async (title: string) => (await makeReservation(orm, trip.id, { title, type: 'flight' })).id;
|
||||
const insertEndpoint = (
|
||||
reservationId: number,
|
||||
role: string,
|
||||
sequence: number,
|
||||
name: string,
|
||||
lat: number,
|
||||
lng: number,
|
||||
code: string,
|
||||
localDate: string,
|
||||
localTime: string,
|
||||
) =>
|
||||
makeReservationEndpoint(orm, reservationId, { role, sequence, name, lat, lng, code, local_date: localDate, local_time: localTime });
|
||||
const inbound = await insertFlight('BRU-HEL');
|
||||
await insertEndpoint(inbound, 'from', 0, 'Brussels', 50.9014, 4.4844, 'BRU', day, '07:00');
|
||||
await insertEndpoint(inbound, 'to', 1, 'Helsinki', 60.3172, 24.9633, 'HEL', day, '09:30');
|
||||
const onward = await insertFlight('HEL-JFK');
|
||||
await insertEndpoint(onward, 'from', 0, 'Helsinki', 60.3172, 24.9633, 'HEL', day, '11:00');
|
||||
await insertEndpoint(onward, 'to', 1, 'New York', 40.6413, -73.7781, 'JFK', day, '15:00');
|
||||
|
||||
const res = await request(server).get('/api/addons/atlas/stats').set('Cookie', sessionCookie(flyerId));
|
||||
expect(res.status).toBe(200);
|
||||
@@ -263,12 +285,11 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
// is the suite that already boots the real AtlasModule against a full schema —
|
||||
// the public-api e2e builds a hand-rolled minimal one and could not.
|
||||
describe('public API stats', () => {
|
||||
function mintApiKey(uid: number, kind = 'api'): string {
|
||||
async function mintApiKey(uid: number, kind = 'api'): Promise<string> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const { createHash, randomBytes } = require('crypto');
|
||||
const { randomBytes } = require('crypto');
|
||||
const raw = 'trek_' + randomBytes(24).toString('hex');
|
||||
db.prepare('INSERT INTO mcp_tokens (user_id, name, token_hash, token_prefix, kind) VALUES (?, ?, ?, ?, ?)')
|
||||
.run(uid, `key-${kind}-${uid}`, createHash('sha256').update(raw).digest('hex'), raw.slice(0, 12), kind);
|
||||
await makeMcpToken(orm, uid, { rawToken: raw, name: `key-${kind}-${uid}`, kind });
|
||||
return raw;
|
||||
}
|
||||
|
||||
@@ -281,7 +302,7 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('401 for an MCP token — the wrong kind is indistinguishable from no token', async () => {
|
||||
const mcpKey = mintApiKey(userId, 'mcp');
|
||||
const mcpKey = await mintApiKey(userId, 'mcp');
|
||||
const res = await request(server).get('/api/v1/stats').set('X-API-Key', mcpKey);
|
||||
expect(res.status).toBe(401);
|
||||
expect(res.body).toEqual({ error: 'Invalid API token', code: 'API_TOKEN_INVALID' });
|
||||
@@ -289,18 +310,15 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
|
||||
it('200 with counts and the last started trip, over both header spellings', async () => {
|
||||
const { user } = createUser(db as never, { username: 'stats-e2e', email: 'stats-e2e@test.example' });
|
||||
const key = mintApiKey(user.id);
|
||||
const key = await mintApiKey(user.id);
|
||||
const iso = (offset: number) => new Date(Date.now() + offset * 86400000).toISOString().slice(0, 10);
|
||||
|
||||
createTrip(db as never, user.id, { title: 'Older', start_date: iso(-90), end_date: iso(-80) });
|
||||
const recent = createTrip(db as never, user.id, { title: 'Recent', start_date: iso(-40), end_date: iso(-30) });
|
||||
createTrip(db as never, user.id, { title: 'Booked', start_date: iso(30), end_date: iso(40) });
|
||||
const cat = db.prepare('SELECT id FROM categories LIMIT 1').get() as { id: number } | undefined;
|
||||
const placeId = db
|
||||
.prepare('INSERT INTO places (trip_id, name, address, category_id) VALUES (?, ?, ?, ?)')
|
||||
.run(recent.id, 'Trevi', 'Piazza di Trevi, 00187, Roma, Italy', cat?.id ?? null).lastInsertRowid as number;
|
||||
db.prepare('INSERT OR REPLACE INTO place_regions (place_id, country_code, region_code, region_name) VALUES (?, ?, ?, ?)')
|
||||
.run(placeId, 'IT', 'IT-62', 'Lazio');
|
||||
// In the first category, with no coordinates of its own.
|
||||
const placeId = (await makePlace(orm, recent.id, { name: 'Trevi', address: 'Piazza di Trevi, 00187, Roma, Italy', lat: null, lng: null })).id;
|
||||
await upsertRow(orm, PlaceRegions, { place: placeId, country_code: 'IT', region_code: 'IT-62', region_name: 'Lazio' });
|
||||
|
||||
const res = await request(server).get('/api/v1/stats').set('Authorization', `Bearer ${key}`);
|
||||
expect(res.status).toBe(200);
|
||||
@@ -322,7 +340,7 @@ describe('Atlas e2e (real auth guard + real service + temp SQLite)', () => {
|
||||
|
||||
it('counts only the caller own trips', async () => {
|
||||
const { user: stranger } = createUser(db as never, { username: 'stats-other', email: 'stats-other@test.example' });
|
||||
const key = mintApiKey(stranger.id);
|
||||
const key = await mintApiKey(stranger.id);
|
||||
const res = await request(server).get('/api/v1/stats').set('X-API-Key', key);
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toMatchObject({ total_trips: 0, total_countries: 0, last_trip: null, next_trip: null });
|
||||
|
||||
@@ -31,11 +31,19 @@ import { SettingsModule } from '../../src/nest/settings/settings.module';
|
||||
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 { countRows, deleteRows, findRow, findRows, insertRow } from '../helpers/factories/rows';
|
||||
import { readUserSetting } from '../helpers/factories/settings';
|
||||
import { AppSettings } from '../../src/db/entities/AppSettings.entity';
|
||||
import { Settings } from '../../src/db/entities/Settings.entity';
|
||||
|
||||
describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
let server: Server;
|
||||
let app: Awaited<ReturnType<typeof build>>;
|
||||
let orm: TestOrm;
|
||||
|
||||
/** The stored value of one of `userId`'s settings, or null. */
|
||||
const userSetting = (userId: number, key: string) => readUserSetting(orm, userId, key);
|
||||
|
||||
async function build() {
|
||||
const moduleRef = await Test.createTestingModule({ imports: [await TestUnitOfWorkModule.forRoot(db), await createTestMikroOrmModule(db), SettingsModule] }).compile();
|
||||
@@ -50,17 +58,19 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
beforeAll(async () => {
|
||||
seedUser(db as never, { id: 1 });
|
||||
seedUser(db as never, { id: 2, role: 'admin', email: 'e2e-admin@example.test' });
|
||||
orm = await createTestOrm(db);
|
||||
app = await build();
|
||||
server = app.getHttpServer();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
db.exec('DELETE FROM settings');
|
||||
db.exec('DELETE FROM app_settings');
|
||||
beforeEach(async () => {
|
||||
await deleteRows(orm, Settings);
|
||||
await deleteRows(orm, AppSettings);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
await orm.close();
|
||||
});
|
||||
|
||||
it('401 without a session cookie', async () => {
|
||||
@@ -68,7 +78,7 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('200 list with a session', async () => {
|
||||
db.prepare("INSERT INTO settings (user_id, key, value) VALUES (1, 'theme', 'dark')").run();
|
||||
await insertRow(orm, Settings, { user: 1, key: 'theme', value: 'dark' });
|
||||
const res = await request(server).get('/api/settings').set('Cookie', sessionCookie(1));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ settings: { theme: 'dark' } });
|
||||
@@ -78,7 +88,7 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
const res = await request(server).put('/api/settings').set('Cookie', sessionCookie(1)).send({ value: 'x' });
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toMatch(/^key: /);
|
||||
expect(db.prepare('SELECT COUNT(*) AS n FROM settings').get()).toEqual({ n: 0 });
|
||||
expect(await countRows(orm, Settings)).toBe(0);
|
||||
});
|
||||
|
||||
it('POST /bulk 400 without a settings object (pipe envelope via SettingsBulkDto)', async () => {
|
||||
@@ -91,22 +101,21 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
const res = await request(server).put('/api/settings').set('Cookie', sessionCookie(1)).send({ key: 'language', value: 'fr' });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ success: true, key: 'language', value: 'fr' });
|
||||
const row = db.prepare("SELECT value FROM settings WHERE user_id = 1 AND key = 'language'").get() as { value: string };
|
||||
expect(row.value).toBe('fr');
|
||||
expect(await userSetting(1, 'language')).toBe('fr');
|
||||
});
|
||||
|
||||
it('PUT no-ops on the masked sentinel', async () => {
|
||||
const res = await request(server).put('/api/settings').set('Cookie', sessionCookie(1)).send({ key: 'secret', value: '••••••••' });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ success: true, key: 'secret', unchanged: true });
|
||||
expect(db.prepare("SELECT COUNT(*) AS n FROM settings WHERE user_id = 1 AND key = 'secret'").get()).toEqual({ n: 0 });
|
||||
expect(await countRows(orm, Settings, { user: 1, key: 'secret' })).toBe(0);
|
||||
});
|
||||
|
||||
it('POST /bulk 200', async () => {
|
||||
const res = await request(server).post('/api/settings/bulk').set('Cookie', sessionCookie(1)).send({ settings: { a: 1, b: 2 } });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ success: true, updated: 2 });
|
||||
const rows = db.prepare('SELECT key, value FROM settings WHERE user_id = 1 ORDER BY key').all();
|
||||
const rows = (await findRows(orm, Settings, { user: 1 }, { key: 'asc' })).map((r) => ({ key: r.key, value: r.value }));
|
||||
expect(rows).toEqual([
|
||||
{ key: 'a', value: '1' },
|
||||
{ key: 'b', value: '2' },
|
||||
@@ -114,32 +123,32 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('POST /bulk skips masked-sentinel values (a stored secret survives)', async () => {
|
||||
db.prepare("INSERT INTO settings (user_id, key, value) VALUES (1, 'ntfy_token', 'tok-real')").run();
|
||||
await insertRow(orm, Settings, { user: 1, key: 'ntfy_token', value: 'tok-real' });
|
||||
const res = await request(server).post('/api/settings/bulk').set('Cookie', sessionCookie(1))
|
||||
.send({ settings: { ntfy_topic: 'trek', ntfy_token: '••••••••' } });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ success: true, updated: 1 });
|
||||
expect(db.prepare("SELECT value FROM settings WHERE user_id = 1 AND key = 'ntfy_token'").get()).toEqual({ value: 'tok-real' });
|
||||
expect(await userSetting(1, 'ntfy_token')).toBe('tok-real');
|
||||
});
|
||||
|
||||
// #1772: a free-form LLM endpoint is admin-only. The resolver ignores such a
|
||||
// row for a non-admin either way; these routes refuse it so the user is told.
|
||||
describe('LLM endpoint settings are admin-only (#1772)', () => {
|
||||
const countRows = () => (db.prepare('SELECT COUNT(*) AS n FROM settings').get() as { n: number }).n;
|
||||
const settingsCount = () => countRows(orm, Settings);
|
||||
|
||||
it('PUT 403 for a non-admin naming a base URL', async () => {
|
||||
const res = await request(server).put('/api/settings').set('Cookie', sessionCookie(1))
|
||||
.send({ key: 'llm_base_url', value: 'http://192.168.1.5:11434' });
|
||||
expect(res.status).toBe(403);
|
||||
expect(res.body).toEqual({ error: 'Admin access required' });
|
||||
expect(countRows()).toBe(0);
|
||||
expect(await settingsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('PUT 403 for a non-admin picking the local provider', async () => {
|
||||
const res = await request(server).put('/api/settings').set('Cookie', sessionCookie(1))
|
||||
.send({ key: 'llm_provider', value: 'local' });
|
||||
expect(res.status).toBe(403);
|
||||
expect(countRows()).toBe(0);
|
||||
expect(await settingsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('PUT lets a non-admin clear the base URL and pick a hosted provider', async () => {
|
||||
@@ -147,8 +156,7 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
.send({ key: 'llm_base_url', value: ' ' })).status).toBe(200);
|
||||
expect((await request(server).put('/api/settings').set('Cookie', sessionCookie(1))
|
||||
.send({ key: 'llm_provider', value: 'anthropic' })).status).toBe(200);
|
||||
expect(db.prepare("SELECT value FROM settings WHERE user_id = 1 AND key = 'llm_provider'").get())
|
||||
.toEqual({ value: 'anthropic' });
|
||||
expect(await userSetting(1, 'llm_provider')).toBe('anthropic');
|
||||
});
|
||||
|
||||
it('PUT 403 for a non-admin naming a routing engine (#1797)', async () => {
|
||||
@@ -161,7 +169,7 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
.send({ key: 'routing_base_url', value: 'https://osrm.example.org' });
|
||||
expect(res.status).toBe(403);
|
||||
expect(res.body).toEqual({ error: 'Admin access required' });
|
||||
expect(countRows()).toBe(0);
|
||||
expect(await settingsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('PUT lets a non-admin clear a routing engine somebody set before the rule', async () => {
|
||||
@@ -173,7 +181,7 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
const res = await request(server).post('/api/settings/bulk').set('Cookie', sessionCookie(1))
|
||||
.send({ settings: { routing_base_url: 'https://osrm.example.org' } });
|
||||
expect(res.status).toBe(403);
|
||||
expect(countRows()).toBe(0);
|
||||
expect(await settingsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('PUT 403 for a non-admin naming the second routing engine', async () => {
|
||||
@@ -185,7 +193,7 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
.send({ key: 'valhalla_base_url', value: 'https://valhalla.example.org' });
|
||||
expect(res.status).toBe(403);
|
||||
expect(res.body).toEqual({ error: 'Admin access required' });
|
||||
expect(countRows()).toBe(0);
|
||||
expect(await settingsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('PUT lets a non-admin clear the second routing engine', async () => {
|
||||
@@ -204,7 +212,7 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
.send({ settings: { llm_provider: 'local', llm_base_url: 'http://192.168.1.5:11434', llm_model: 'nuextract' } });
|
||||
expect(res.status).toBe(403);
|
||||
expect(res.body).toEqual({ error: 'Admin access required' });
|
||||
expect(countRows()).toBe(0);
|
||||
expect(await settingsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('POST /bulk 200 for a non-admin bringing their own hosted key', async () => {
|
||||
@@ -222,15 +230,14 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
.send({ settings: { llm_provider: 'local', llm_base_url: 'http://192.168.1.5:11434' } });
|
||||
expect(res.status).toBe(403);
|
||||
expect(res.body).toEqual({ error: 'Admin access required' });
|
||||
expect(countRows()).toBe(0);
|
||||
expect(await settingsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('POST /bulk 200 for an admin bringing their own hosted key', async () => {
|
||||
const res = await request(server).post('/api/settings/bulk').set('Cookie', sessionCookie(2))
|
||||
.send({ settings: { llm_provider: 'openai', llm_base_url: '', llm_model: 'gpt-4o-mini' } });
|
||||
expect(res.status).toBe(200);
|
||||
expect(db.prepare("SELECT value FROM settings WHERE user_id = 2 AND key = 'llm_provider'").get())
|
||||
.toEqual({ value: 'openai' });
|
||||
expect(await userSetting(2, 'llm_provider')).toBe('openai');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -248,7 +255,7 @@ describe('Settings e2e (real auth guard + temp SQLite)', () => {
|
||||
const res = await request(server).put('/api/admin/default-user-settings').set('Cookie', sessionCookie(2))
|
||||
.send({ week_start: 'friday' });
|
||||
expect(res.status).toBe(400);
|
||||
expect(db.prepare("SELECT value FROM app_settings WHERE key = 'default_user_setting_week_start'").get()).toBeUndefined();
|
||||
expect(await findRow(orm, AppSettings, { key: 'default_user_setting_week_start' })).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user