33 lines
1.8 KiB
JavaScript
33 lines
1.8 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { OPPONENT_PROFILES, LEVEL_STATS } from '../stats.ts';
|
|
|
|
const snapshot = JSON.parse(await readFile(new URL('../data/cloudRiseProfiles.json', import.meta.url), 'utf8'));
|
|
|
|
test('snapshot has 5,000 unique inactive players with a 4,000/1,000 avatar split', () => {
|
|
assert.equal(snapshot.profiles.length, 5000);
|
|
assert.equal(new Set(snapshot.profiles.map(row => row.onlyId)).size, 5000);
|
|
const sampled = new Date(snapshot.sampledAt), cutoff = new Date(snapshot.inactiveBefore);
|
|
assert.equal(sampled.getUTCFullYear(), 2026);
|
|
assert.equal(cutoff.toISOString(), '2026-07-24T11:05:38.000Z');
|
|
let real = 0;
|
|
for (const row of snapshot.profiles) {
|
|
assert(Number.isSafeInteger(row.onlyId) && row.onlyId > 0);
|
|
assert(row.taskTime > 0 && row.taskTime < cutoff.getTime());
|
|
assert.deepEqual(Object.keys(row).sort(), ['onlyId', 'taskTime', 'useravatar', 'useravatarIcon', 'username']);
|
|
const avatar = /^https:\/\//.test(row.useravatarIcon) ? row.useravatarIcon : row.useravatar;
|
|
if (/^https:\/\//.test(avatar)) { assert(new URL(avatar).hostname); real++; }
|
|
else assert.match(row.useravatar, /^(?:icon_)?\d+$/);
|
|
}
|
|
assert.equal(real, 4000);
|
|
assert.deepEqual(snapshot.selected, { real: 4000, game: 1000 });
|
|
});
|
|
|
|
test('stats preserves level data and contains only the selected display identities', async () => {
|
|
const levels = JSON.parse(await readFile(new URL('../data/cloudRiseLevelStats.json', import.meta.url), 'utf8'));
|
|
assert.deepEqual(LEVEL_STATS, levels.levels);
|
|
assert.deepEqual(OPPONENT_PROFILES, snapshot.profiles.map(({ taskTime, ...profile }) => profile));
|
|
assert(OPPONENT_PROFILES.every(row => Object.keys(row).sort().join(',') === 'onlyId,useravatar,useravatarIcon,username'));
|
|
});
|