import { test } from 'node:test'; import assert from 'node:assert/strict'; import { randomUUID } from 'node:crypto'; import { createStatsStore } from '../src/server/stats-store.js'; test('visitor identity persists without creating the removed match collection', { skip: !process.env.TEST_MONGODB_URI }, async () => { const options = { mongoUri: process.env.TEST_MONGODB_URI!, databaseName: `dragon_ball_test_stats_${randomUUID().replaceAll('-', '')}` }; let store = await createStatsStore(options); try { const guest = await store.createGuest('a'.repeat(43)); assert.deepEqual(await store.createGuest('a'.repeat(43)), guest); const player = await store.db.collection('players').findOne({ _id: guest.playerId as any }); assert.ok(player?.guestTokenHash); assert.ok(!JSON.stringify(player).includes(guest.guestToken)); assert.equal(await store.findGuest('bad-token'), null); await store.close(); store = await createStatsStore(options); assert.deepEqual(await store.findGuest(guest.guestToken), guest); assert.equal((await store.db.listCollections({ name: 'matches' }).toArray()).length, 0); } finally { await store.db.dropDatabase(); await store.close(); } });