import { test } from 'node:test' import assert from 'node:assert/strict' import { parseEvent, parseScoreChannel } from '../guards' // 大屏快照里的 avgMode / countToTeam 是后加的字段:旧服务端不下发时必须有默认值, // 而 basis='aggregate'(新口径「按队内平均」)不能被当成未知取值回落到 result。 test('parseEvent 缺 avgMode 时按 valid 处理', () => { assert.equal(parseEvent({ id: 1, code: 'TPULL', eventType: 'individual_team' }).avgMode, 'valid') assert.equal(parseEvent({ id: 1, avgMode: 'all' }).avgMode, 'all') assert.equal(parseEvent({ id: 1, avgMode: 'AVG' }).avgMode, 'valid') }) test('parseScoreChannel 保留 aggregate 并按 true 补 countToTeam', () => { const channel = parseScoreChannel({ id: 3, eventId: 1, scope: 'team', basis: 'aggregate', profileId: 2, sortOrder: 1 }) assert.equal(channel.basis, 'aggregate') assert.equal(channel.countToTeam, true) const personal = parseScoreChannel({ id: 4, eventId: 1, scope: 'athlete', basis: 'result', profileId: 1, countToTeam: false }) assert.equal(personal.countToTeam, false) // 未知 basis 仍回落到 result,避免渲染出不存在的口径。 assert.equal(parseScoreChannel({ basis: 'sum' }).basis, 'result') }) test('parseEvent 同时解析详情接口带出的通道', () => { const event = parseEvent({ id: 1, channels: [{ id: 1, scope: 'athlete', basis: 'result', profileId: 1, countToTeam: false }], }) assert.equal(event.channels?.length, 1) assert.equal(event.channels?.[0]?.countToTeam, false) // 列表接口不下发 channels 时保持 undefined,不能凭空造出空数组。 assert.equal(parseEvent({ id: 1 }).channels, undefined) })