Add download stats, key deletion, batch creation, and newest-first listing.
Track landing downloads per platform/month, support admin delete and bulk key issue, and sort licenses by createdAtSec. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import {
|
||||
getDownloadStatsForMonth,
|
||||
listDownloadMonths,
|
||||
monthKeyFromDate,
|
||||
recordDownload,
|
||||
} from '../lib/downloadStats.mjs';
|
||||
|
||||
void test('recordDownload increments platform counts by month', () => {
|
||||
const data = {};
|
||||
const r1 = recordDownload(data, 'windows', new Date('2026-07-15T12:00:00Z'));
|
||||
assert.equal(r1.ok, true);
|
||||
assert.equal(r1.month, '2026-07');
|
||||
assert.equal(r1.count, 1);
|
||||
|
||||
recordDownload(data, 'macos', new Date('2026-07-20T12:00:00Z'));
|
||||
recordDownload(data, 'windows', new Date('2026-07-21T12:00:00Z'));
|
||||
|
||||
const stats = getDownloadStatsForMonth(data, '2026-07');
|
||||
assert.equal(stats.windows, 2);
|
||||
assert.equal(stats.macos, 1);
|
||||
assert.equal(stats.linux, 0);
|
||||
assert.equal(stats.total, 3);
|
||||
});
|
||||
|
||||
void test('recordDownload rejects invalid platform', () => {
|
||||
const data = {};
|
||||
const r = recordDownload(data, 'android');
|
||||
assert.equal(r.ok, false);
|
||||
});
|
||||
|
||||
void test('listDownloadMonths returns sorted keys', () => {
|
||||
const data = {
|
||||
downloadStats: {
|
||||
byMonth: {
|
||||
'2026-05': { windows: 1, macos: 0, linux: 0 },
|
||||
'2026-07': { windows: 2, macos: 0, linux: 0 },
|
||||
},
|
||||
},
|
||||
};
|
||||
assert.deepEqual(listDownloadMonths(data), ['2026-07', '2026-05']);
|
||||
assert.equal(monthKeyFromDate(new Date('2026-03-01T00:00:00Z')), '2026-03');
|
||||
});
|
||||
Reference in New Issue
Block a user