41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { flattenMapping } from '../../../src/es/mapping.js'
|
|
|
|
const raw = {
|
|
myindex: {
|
|
mappings: {
|
|
properties: {
|
|
id: { type: 'keyword' },
|
|
title: { type: 'text', fields: { raw: { type: 'keyword' } } },
|
|
author: { properties: { name: { type: 'text' }, age: { type: 'integer' } } }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
describe('flattenMapping', () => {
|
|
it('flattens nested properties to dotted field:type rows', () => {
|
|
const rows = flattenMapping(raw)
|
|
expect(rows).toContainEqual({ field: 'id', type: 'keyword' })
|
|
expect(rows).toContainEqual({ field: 'title', type: 'text' })
|
|
expect(rows).toContainEqual({ field: 'title.raw', type: 'keyword' })
|
|
expect(rows).toContainEqual({ field: 'author.name', type: 'text' })
|
|
expect(rows).toContainEqual({ field: 'author.age', type: 'integer' })
|
|
})
|
|
it('handles multiple indices by prefixing the index name', () => {
|
|
const rows = flattenMapping({
|
|
a: { mappings: { properties: { x: { type: 'long' } } } },
|
|
b: { mappings: { properties: { y: { type: 'date' } } } }
|
|
})
|
|
expect(rows).toContainEqual({ index: 'a', field: 'x', type: 'long' })
|
|
expect(rows).toContainEqual({ index: 'b', field: 'y', type: 'date' })
|
|
})
|
|
it('returns empty array for an empty mapping', () => {
|
|
expect(flattenMapping({ idx: { mappings: {} } })).toEqual([])
|
|
})
|
|
it('returns empty array for a non-object input', () => {
|
|
expect(flattenMapping(null)).toEqual([])
|
|
expect(flattenMapping('nope')).toEqual([])
|
|
})
|
|
})
|