import { describe, expect, it } from 'vitest' import { unwrapApiData } from '@/services/apiResponse' describe('unwrapApiData', () => { it('normalizes data and legacy body envelopes', () => { expect(unwrapApiData({ success: true, data: { id: 'data' } })).toEqual({ id: 'data' }) expect(unwrapApiData({ success: true, body: { id: 'body' } })).toEqual({ id: 'body' }) }) it('prefers data when both response fields exist', () => { expect(unwrapApiData({ success: true, data: 1, body: 2 })).toBe(1) }) it('unwraps envelopes that omit a required success: true discriminant', () => { expect(unwrapApiData({ data: { status: 'verified' } })).toEqual({ status: 'verified', }) }) })