fix(demo): skip the example trips when the demo account owns its own

The seed put the example trips in whenever the admin owned none, so a demo
whose content belongs to the demo account got them back on every reopen,
the hourly reset included, and the next baseline saved them along.
This commit is contained in:
Maurice
2026-10-25 00:10:21 +02:00
parent 270a13ff60
commit 2ac333f842
2 changed files with 35 additions and 1 deletions
+10
View File
@@ -69,6 +69,16 @@ async function seedDemoData(): Promise<{ adminId: number; demoId: number }> {
return { adminId, demoId };
}
// A demo whose content belongs to the demo account itself (built over the
// API, then saved as the baseline) is left alone. Without this the old
// example trips would come back on every reopen, the hourly reset included,
// and the mark below would save them into the next baseline.
const demoTripCount = await demo.countTripsByUser(demoId);
if (demoTripCount > 0) {
console.log('[Demo] The demo account owns its own trips, skipping the example trips');
return { adminId, demoId };
}
console.log('[Demo] Seeding example trips...');
await seedExampleTrips(demo, adminId, demoId);
+25 -1
View File
@@ -27,7 +27,7 @@ import { takeExampleTripsSeeded } from '../../../src/demo/demo-reset';
import { seedDemoData } from '../../../src/demo/demo-seed';
import { withRequestContext } from '../../../src/nest/database/request-context';
import { createSnapshotTestDb } from '../../helpers/db-mock';
import { countRows, findRows } from '../../helpers/factories/rows';
import { countRows, deleteRows, findRows, updateRows } from '../../helpers/factories/rows';
import { readAppSetting } from '../../helpers/factories/settings';
import { readUser } from '../../helpers/factories/users';
import { createTestOrm } from '../../helpers/test-orm';
@@ -167,4 +167,28 @@ describe('demo seeding', () => {
await seed();
expect(takeExampleTripsSeeded()).toBe(false);
});
it('DEMOSEED-006: leaves a demo alone whose trips belong to the demo account, not the admin', async () => {
takeExampleTripsSeeded();
const { adminId, demoId } = await seed();
expect(takeExampleTripsSeeded()).toBe(true);
// The demo content is rebuilt as the demo user's own: the admin's example
// trips go, one trip owned by the demo account stays.
const orm = await createTestOrm(db);
const exampleTrips = await findRows(orm, Trips, { user_id: adminId }, { id: 'asc' });
const keep = exampleTrips[0];
await deleteRows(orm, Trips, { id: { $in: exampleTrips.slice(1).map((t) => t.id) } });
await updateRows(orm, Trips, { id: keep.id }, { user: demoId });
await orm.close();
await seed();
const after = await createTestOrm(db);
const trips = await findRows(after, Trips, {}, { id: 'asc' });
await after.close();
expect(trips.map((t) => ({ id: t.id, user_id: t.user_id }))).toEqual([{ id: keep.id, user_id: demoId }]);
// Nothing was seeded, so no baseline is due either.
expect(takeExampleTripsSeeded()).toBe(false);
});
});