[econ] some invention stats

This commit is contained in:
Devin Zuczek
2026-10-02 14:01:00 -04:00
parent bfe88a9837
commit fd2e266e50
4 changed files with 66 additions and 8 deletions
+15 -2
View File
@@ -5054,7 +5054,7 @@ describe('econ endpoints', () => {
}
InventionResponse: {
Status: number
Invention: { InventionId: number; Name: string }
Invention: { InventionId: number; Name: string; NumDownloads: number }
InventionVersion: { InventionId: number; VersionNumber: number }
}
}
@@ -5070,9 +5070,22 @@ describe('econ endpoints', () => {
expect(await getOwnedInventionIds(env.DB, 50)).toEqual([8])
// Owning an invention is boolean: buying it again is a conflict, not a second row.
// `NumDownloads` is the number of players who have it, re-derived on the grant:
// the response carries it and so does the stored record.
const storedDownloads = async (): Promise<number> =>
(
await env.DB.prepare(
"SELECT json_extract(data, '$.NumDownloads') AS n FROM invention WHERE id = 8"
).first<{ n: number }>()
)?.n ?? -1
expect(body.InventionResponse.Invention.NumDownloads).toBe(1)
expect(await storedDownloads()).toBe(1)
// Owning an invention is boolean: buying it again is a conflict, not a second row —
// and not a second download.
expect((await buyInvention('50', 8)).status).toBe(409)
expect(await getOwnedInventionIds(env.DB, 50)).toEqual([8])
expect(await storedDownloads()).toBe(1)
})
test('GET /api/storefronts/v2/buyInvention pays the creator the buyer’s tokens', async () => {