54 lines
2.1 KiB
TypeScript
54 lines
2.1 KiB
TypeScript
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()
|
|
})
|
|
it('truncates an over-budget flattened-fields response', async () => {
|
|
const properties: Record<string, { type: string }> = {}
|
|
for (let i = 0; i < 50; i++) {
|
|
properties['field_with_a_long_name_' + i] = { type: 'keyword' }
|
|
}
|
|
const out = await runGetMapping(
|
|
managed(200, { idx: { mappings: { properties } } }),
|
|
'idx',
|
|
false,
|
|
100
|
|
)
|
|
expect(out.truncated).toBe(true)
|
|
})
|
|
it('truncates an over-budget raw response', async () => {
|
|
const big: Record<string, string> = {}
|
|
for (let i = 0; i < 50; i++) {
|
|
big['key_with_a_fairly_long_name_' + i] = 'some value here ' + i
|
|
}
|
|
const out = await runGetMapping(managed(200, big), 'idx', true, 100)
|
|
expect(out.truncated).toBe(true)
|
|
expect(out.fields).toBeUndefined()
|
|
})
|
|
})
|