diablo2-web/tests/client/transaction-cost-input.test.ts

38 lines
1.6 KiB
TypeScript

/**
* Display prices for real server items (captures 05-09) through the 1.13c #10107/#10071 port.
*/
import path from 'node:path'
import { describe, expect, it } from 'vitest'
import { replayD2CapFile } from '../../tools/netproto-replay.ts'
import { priceItem113c, repairAllCost113c } from '../../src/client/ui-model/transaction-cost-input.ts'
const FIXTURES = path.resolve(__dirname, '../fixtures/netproto')
const CHARSI = 154
const GHEED = 147
describe('1.13c prices for captured server items', () => {
it('prices every Charsi shop item (capture 05) without missing data', () => {
const { world } = replayD2CapFile(path.join(FIXTURES, '05-d2gs-vendor-open.d2cap'))
const shop = [...world.containers.shop.values()]
expect(shop.length).toBe(46)
for (const it of shop) {
const p = priceItem113c(world, it, 0, CHARSI)
expect(Number.isInteger(p)).toBe(true)
expect(p).toBeGreaterThan(0)
}
})
it('every gamble preview (capture 09) costs more than the 2 gold that made the server reject it (0x2A result 12)', () => {
const { world } = replayD2CapFile(path.join(FIXTURES, '09-d2gs-gamble.d2cap'))
const shop = [...world.containers.shop.values()]
expect(shop.length).toBe(14)
for (const it of shop) expect(priceItem113c(world, it, 2, GHEED)).toBeGreaterThan(2)
})
it('repair-all costs 0 with full durability (capture 07: server answered result 2 flag 1, gold unchanged)', () => {
const { world } = replayD2CapFile(path.join(FIXTURES, '07-d2gs-vendor-repair.d2cap'))
expect(world.containers.equipment.size).toBe(2)
expect(repairAllCost113c(world, CHARSI)).toBe(0)
})
})