import { describe, it, expect } from "vitest"
describe("SteamDB HTML Parser", () => {
it("parses version and build from typical SteamDB HTML", async () => {
const { _parseSteamDBHtml } = await import("../scrape")
// Version regex: /Last known name[^<]*<[^>]*>([^<]+)\s*
]*>(\d+)/i
const html = `
| Last known name v1.2.3 |
| Build ID | 12345678 |
`
const result = _parseSteamDBHtml(html)
expect(result.versionString).toBe("v1.2.3")
expect(result.buildId).toBe("12345678")
})
it("returns nulls for unrecognized HTML", async () => {
const { _parseSteamDBHtml } = await import("../scrape")
const result = _parseSteamDBHtml("Nothing here")
expect(result.versionString).toBeNull()
expect(result.buildId).toBeNull()
})
it("extracts build ID via buildid attribute even without version string", async () => {
const { _parseSteamDBHtml } = await import("../scrape")
// Build ID regex fallback: /buildid[^>]*>(\d+)/i
// buildid[^>]*>(\d+) — expects digits right after the closing tag
const html = `99999`
const result = _parseSteamDBHtml(html)
expect(result.buildId).toBe("99999")
expect(result.versionString).toBeNull()
})
it("extracts build ID via Build ID table row pattern", async () => {
const { _parseSteamDBHtml } = await import("../scrape")
const html = ` | | Build ID | 55555 |
`
const result = _parseSteamDBHtml(html)
expect(result.buildId).toBe("55555")
expect(result.versionString).toBeNull()
})
it("extracts version from JSON-LD when available", async () => {
const { _parseSteamDBHtml } = await import("../scrape")
const html = `
`
const result = _parseSteamDBHtml(html)
expect(result.versionString).toBe("2.0.0")
expect(result.buildId).toBeNull()
})
})