admin/services/apiResponse.test.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

21 lines
714 B
TypeScript

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',
})
})
})