23 lines
1.0 KiB
JavaScript
23 lines
1.0 KiB
JavaScript
|
|
import assert from 'node:assert/strict';
|
||
|
|
import { isCompetitionState, unwrapCompetitionResponse } from '../src/views/website/competition/response.mjs';
|
||
|
|
|
||
|
|
const state = {
|
||
|
|
published: false,
|
||
|
|
competition: {},
|
||
|
|
notice: {},
|
||
|
|
schedule: { items: [] },
|
||
|
|
results: { overall: [], challenge: [], battle: [] },
|
||
|
|
players: [],
|
||
|
|
records: [],
|
||
|
|
};
|
||
|
|
|
||
|
|
assert.deepEqual(unwrapCompetitionResponse(state), state);
|
||
|
|
assert.deepEqual(unwrapCompetitionResponse({ statusCode: 200, data: state }), state);
|
||
|
|
assert.deepEqual(unwrapCompetitionResponse({ statusCode: 200, data: JSON.stringify(state) }), state);
|
||
|
|
assert.equal(isCompetitionState(unwrapCompetitionResponse({ statusCode: 200, data: JSON.stringify(state) })), true);
|
||
|
|
assert.equal(isCompetitionState({ statusCode: 200, data: state }), false);
|
||
|
|
assert.throws(() => unwrapCompetitionResponse({ statusCode: 401, errors: '401 Unauthorized' }), /401 Unauthorized/);
|
||
|
|
assert.throws(() => unwrapCompetitionResponse({ statusCode: 200, data: 'invalid JSON' }), /JSON 格式不正确/);
|
||
|
|
|
||
|
|
console.log('官网赛事接口响应解包与数据校验通过');
|