[econ] room storefront purchaseables

This commit is contained in:
Devin Zuczek
2026-10-03 13:57:32 -04:00
parent 41d0b0543a
commit 739176a3ed
4 changed files with 272 additions and 11 deletions
+97 -4
View File
@@ -104,9 +104,18 @@ import {
} from '../../inventory-custom-db'
import { INVENTORY_SCHEMA_DDL } from '../../inventory-db'
import { REWARD_STATUS_SCHEMA_DDL } from '../../reward-db'
import { ROOM_CONSUMABLE_SCHEMA_DDL, ROOM_INVENTORY_SCHEMA_DDL } from '../../room-consumable-db'
import { ROOM_BALANCE_SCHEMA_DDL, ROOM_CURRENCY_SCHEMA_DDL } from '../../room-currency-db'
import { ROOM_KEY_SCHEMA_DDL } from '../../room-key-db'
import {
ROOM_CONSUMABLE_SCHEMA_DDL,
ROOM_INVENTORY_SCHEMA_DDL,
upsertRoomConsumable,
} from '../../room-consumable-db'
import {
createPurchaseOffer,
createRoomCurrency,
ROOM_BALANCE_SCHEMA_DDL,
ROOM_CURRENCY_SCHEMA_DDL,
} from '../../room-currency-db'
import { createRoomKey, ROOM_KEY_SCHEMA_DDL } from '../../room-key-db'
import type { CatalogLoadRow, CatalogRow, CatalogValue, StoreListing } from '../../catalog-db'
import type { Env } from '../../context'
@@ -2896,7 +2905,6 @@ describe('econ endpoints', () => {
'/econ/roomOffer/room/92',
'/econ/roomOffer/room/92/purchaseCounts',
'/econ/roomGiftDropShops/room/92',
'/api/ugcPurchasables/v1/items/room/92',
]) {
const res = await exports.default.fetch(`${ORIGIN}${path}`)
expect(res.status, path).toBe(200)
@@ -2904,6 +2912,91 @@ describe('econ endpoints', () => {
}
})
test('GET /api/ugcPurchasables/v1/items/room/:roomId lists keys, consumables and currency packs as one shop', async () => {
const shop = async (roomId: number) =>
(await (
await exports.default.fetch(`${ORIGIN}/api/ugcPurchasables/v1/items/room/${roomId}`)
).json()) as Array<Record<string, unknown>>
// A room that sells nothing is `[]`, never `{}` — the client's decoder throws on that.
expect(await shop(93)).toEqual([])
const key = await createRoomKey(env.DB, {
RoomId: 93,
Type: 'Key',
Name: 'VIP Key',
Description: '',
Price: 250,
})
const consumable = await upsertRoomConsumable(env.DB, null, {
RoomId: 93,
Name: 'Potion',
Description: 'Drink me',
ImageName: 'potion.png',
Price: 5,
PurchaseCurrencyId: 'c0ffee00-0000-4000-8000-000000000093',
MaximumCountPerPurchase: 10,
})
const currency = await createRoomCurrency(env.DB, {
RoomId: 93,
Name: 'Gems',
Description: '',
Limit: 100,
Shape: 0,
Color: 0,
})
const offer = await createPurchaseOffer(env.DB, currency.CurrencyId, {
Name: '100 gems',
CurrencyAmount: 100,
Price: 400,
Order: 0,
})
// The client's 10-key `UgcPurchasableItem`, `ItemType` saying which table a line is
// from and `ItemId` a bare GUID: a key is named by its ReplicationId, not its number.
expect(await shop(93)).toEqual([
{
ItemType: 0,
ItemId: key.ReplicationId,
Name: 'VIP Key',
Description: '',
ImageName: null,
RoomId: 93,
Price: 250,
PurchaseCurrencyId: null,
CreatedAt: key.CreatedAt,
ModifiedAt: key.CreatedAt,
},
{
ItemType: 1,
ItemId: consumable.RoomConsumableId,
Name: 'Potion',
Description: 'Drink me',
ImageName: 'potion.png',
RoomId: 93,
Price: 5,
PurchaseCurrencyId: 'c0ffee00-0000-4000-8000-000000000093',
CreatedAt: consumable.ModifiedAt,
ModifiedAt: consumable.ModifiedAt,
},
{
ItemType: 3,
ItemId: offer.CurrencyPurchaseOfferId,
Name: '100 gems',
Description: '',
ImageName: null,
RoomId: 93,
Price: 400,
// A currency pack is bought with tokens.
PurchaseCurrencyId: null,
CreatedAt: offer.ModifiedAt,
ModifiedAt: offer.ModifiedAt,
},
])
// Another room's shop is untouched.
expect(await shop(92)).toEqual([])
})
test('POST /api/ugcPurchasables/v1/items/bulk resolves custom avatar items, echoing RoomId', async () => {
const item = await createCustomAvatarItem(env.DB, {
customAvatarItemId: crypto.randomUUID(),