Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
21 lines
714 B
TypeScript
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',
|
|
})
|
|
})
|
|
})
|