mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 14:41:28 -07:00
fake currency for now
This commit is contained in:
@@ -42,6 +42,19 @@ function unauthorized(c: Context<App>) {
|
|||||||
return c.body(null, 401)
|
return c.body(null, 401)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** RecNet currency types (the `CurrencyType` enum the client uses). */
|
||||||
|
const CurrencyType = {
|
||||||
|
Invalid: 0,
|
||||||
|
LaserTagTickets: 1,
|
||||||
|
RecCenterTokens: 2,
|
||||||
|
LostSkullsGold: 100,
|
||||||
|
DraculaSilver: 101,
|
||||||
|
RecRoyaleSeason1: 200,
|
||||||
|
RoomCurrency: 300,
|
||||||
|
RoomInventoryItem: 301,
|
||||||
|
ProgressionEvent: 400,
|
||||||
|
} as const
|
||||||
|
|
||||||
const app = new Hono<App>()
|
const app = new Hono<App>()
|
||||||
.use(
|
.use(
|
||||||
'*',
|
'*',
|
||||||
@@ -144,12 +157,14 @@ const app = new Hono<App>()
|
|||||||
return c.json([])
|
return c.json([])
|
||||||
})
|
})
|
||||||
|
|
||||||
// Token balance. [Authorize]; empty without a DB binding.
|
// Token balance. [Authorize]. The `2` in the path is the RecCenterTokens
|
||||||
|
// CurrencyType. The balance is a fake test value (a large amount) until a DB
|
||||||
|
// binding tracks real balances; Platform -2 means "all platforms".
|
||||||
.get('/api/storefronts/v4/balance/2', async (c) => {
|
.get('/api/storefronts/v4/balance/2', async (c) => {
|
||||||
const id = await authedId(c)
|
const id = await authedId(c)
|
||||||
if (id === null) return unauthorized(c)
|
if (id === null) return unauthorized(c)
|
||||||
// TODO: query TokenBalances once a DB binding exists.
|
// TODO: query TokenBalances once a DB binding exists.
|
||||||
return c.json([])
|
return c.json([{ CurrencyType: CurrencyType.RecCenterTokens, Platform: -2, Balance: 2147483648 }])
|
||||||
})
|
})
|
||||||
|
|
||||||
// Gift-drop storefront. Falls back to the bundled static catalog when no
|
// Gift-drop storefront. Falls back to the bundled static catalog when no
|
||||||
|
|||||||
@@ -186,14 +186,14 @@ describe('econ endpoints', () => {
|
|||||||
expect(await res.json()).toEqual([])
|
expect(await res.json()).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('GET /api/storefronts/v4/balance/2 401s without a token, returns []', async () => {
|
test('GET /api/storefronts/v4/balance/2 401s without a token, returns the token balance', async () => {
|
||||||
const anon = await exports.default.fetch(`${ORIGIN}/api/storefronts/v4/balance/2`)
|
const anon = await exports.default.fetch(`${ORIGIN}/api/storefronts/v4/balance/2`)
|
||||||
expect(anon.status).toBe(401)
|
expect(anon.status).toBe(401)
|
||||||
const res = await exports.default.fetch(`${ORIGIN}/api/storefronts/v4/balance/2`, {
|
const res = await exports.default.fetch(`${ORIGIN}/api/storefronts/v4/balance/2`, {
|
||||||
headers: await bearer(),
|
headers: await bearer(),
|
||||||
})
|
})
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(await res.json()).toEqual([])
|
expect(await res.json()).toEqual([{ CurrencyType: 2, Platform: -2, Balance: 2147483648 }])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('GET /api/storefronts/v3/giftdropstore/3 returns the storefront catalog', async () => {
|
test('GET /api/storefronts/v3/giftdropstore/3 returns the storefront catalog', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user