mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
import { buildApp } from '../../src/bootstrap';
|
|
import { AppSettings } from '../../src/db/entities/AppSettings.entity';
|
|
import { SchemaVersion } from '../../src/db/entities/SchemaVersion.entity';
|
|
import { Users } from '../../src/db/entities/Users.entity';
|
|
import { MapDefaultsSeeder } from '../../src/db/seeders/MapDefaultsSeeder';
|
|
import { deleteRows, insertRow } from '../helpers/factories/rows';
|
|
import { readAppSetting, setAppSetting } from '../helpers/factories/settings';
|
|
import { makeUser } from '../helpers/factories/users';
|
|
import { MikroORM } from '@mikro-orm/core';
|
|
import type { INestApplication } from '@nestjs/common';
|
|
import { OPENFREEMAP_DEFAULT_STYLE } from '@trek/shared';
|
|
|
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
const PROVIDER = 'default_user_setting_map_provider';
|
|
const STYLE = 'default_user_setting_maplibre_style';
|
|
|
|
let app: INestApplication;
|
|
let orm: MikroORM;
|
|
|
|
beforeAll(async () => {
|
|
app = await buildApp();
|
|
orm = app.get(MikroORM);
|
|
}, 60_000);
|
|
|
|
beforeEach(async () => {
|
|
await deleteRows(orm, AppSettings, { key: { $in: [PROVIDER, STYLE] } });
|
|
await deleteRows(orm, SchemaVersion, {});
|
|
await deleteRows(orm, Users, {});
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app?.close();
|
|
});
|
|
|
|
const seed = () => new MapDefaultsSeeder().run(orm.em.fork());
|
|
|
|
describe('fresh-install map defaults', () => {
|
|
it('sets MapLibre Liberty once and keeps a style explicitly chosen later', async () => {
|
|
await seed();
|
|
expect(await readAppSetting(orm, PROVIDER)).toBe(JSON.stringify('maplibre-gl'));
|
|
expect(await readAppSetting(orm, STYLE)).toBe(JSON.stringify(OPENFREEMAP_DEFAULT_STYLE));
|
|
await setAppSetting(orm, STYLE, JSON.stringify('trek:ofm-auto'));
|
|
await seed();
|
|
expect(await readAppSetting(orm, STYLE)).toBe(JSON.stringify('trek:ofm-auto'));
|
|
});
|
|
|
|
it('keeps the provider and style of an install with an explicit default', async () => {
|
|
await setAppSetting(orm, PROVIDER, JSON.stringify('leaflet'));
|
|
await seed();
|
|
expect(await readAppSetting(orm, PROVIDER)).toBe(JSON.stringify('leaflet'));
|
|
expect(await readAppSetting(orm, STYLE)).toBeNull();
|
|
});
|
|
|
|
it('leaves an existing installation waiting for its first SSO user alone', async () => {
|
|
await insertRow(orm, SchemaVersion, { version: 258 });
|
|
await seed();
|
|
expect(await readAppSetting(orm, PROVIDER)).toBeNull();
|
|
expect(await readAppSetting(orm, STYLE)).toBeNull();
|
|
});
|
|
|
|
it('leaves an install with users alone even if the legacy marker is missing', async () => {
|
|
await makeUser(orm);
|
|
await seed();
|
|
expect(await readAppSetting(orm, PROVIDER)).toBeNull();
|
|
});
|
|
});
|