19 lines
726 B
JavaScript
19 lines
726 B
JavaScript
|
|
import assert from 'node:assert/strict';
|
||
|
|
import { unwrapCompetitionState } from '../src/data/competition-response.js';
|
||
|
|
|
||
|
|
const state = {
|
||
|
|
published: true,
|
||
|
|
competition: {},
|
||
|
|
notice: {},
|
||
|
|
schedule: { items: [] },
|
||
|
|
results: { overall: [], challenge: [], battle: [] },
|
||
|
|
players: [],
|
||
|
|
records: [],
|
||
|
|
};
|
||
|
|
|
||
|
|
assert.deepEqual(unwrapCompetitionState(state), state);
|
||
|
|
assert.deepEqual(unwrapCompetitionState({ statusCode: 200, data: JSON.stringify(state) }), state);
|
||
|
|
assert.throws(() => unwrapCompetitionState({ statusCode: 502, errors: '上游连接失败' }), /上游连接失败/);
|
||
|
|
assert.throws(() => unwrapCompetitionState({ statusCode: 200, data: '{}' }), /结构不正确/);
|
||
|
|
console.log('Competition response parsing passed');
|