import { describe, expect, it } from 'vitest' import { runGetMapping } from '../../../src/tools/mappingTool.js' const managed = (status: number, body: unknown) => ({ config: { readonly: false }, backend: { request: async () => ({ status, body }), dispose: async () => {} } }) as never describe('runGetMapping', () => { it('flattens by default', async () => { const out = await runGetMapping( managed(200, { idx: { mappings: { properties: { y: { type: 'long' } } } } }), 'idx', false ) expect(out.fields).toContainEqual({ field: 'y', type: 'long' }) }) it('returns raw body when raw=true', async () => { const raw = { idx: { mappings: { properties: { y: { type: 'long' } } } } } const out = await runGetMapping(managed(200, raw), 'idx', true) expect(out.body).toEqual(raw) expect(out.fields).toBeUndefined() }) it('passes the raw body through on a ≥400 status', async () => { const out = await runGetMapping(managed(404, { error: 'not_found' }), 'idx', false) expect(out.status).toBe(404) expect(out.body).toEqual({ error: 'not_found' }) expect(out.fields).toBeUndefined() }) })