import test from 'node:test' import assert from 'node:assert/strict' import { unwrapResponse } from './request.js' test('unwrapResponse returns data when code is 200', () => { const data = unwrapResponse({ code: 200, message: 'success', data: { token: 't' } }) assert.deepEqual(data, { token: 't' }) }) test('unwrapResponse throws with backend message when code is not 200', () => { assert.throws( () => unwrapResponse({ code: 401, message: '用户名或密码错误', data: null }), (e) => e instanceof Error && e.message === '用户名或密码错误' && e.code === 401 ) }) test('unwrapResponse throws network message on null body', () => { assert.throws( () => unwrapResponse(null), (e) => e instanceof Error && e.message === '网络异常,请稍后重试' ) })