|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +import { RegistryDataStream } from '../../../../types'; |
| 9 | +import { Field } from '../../fields/field'; |
| 10 | + |
| 11 | +import { elasticsearchServiceMock } from 'src/core/server/mocks'; |
| 12 | +import { installTemplate } from './install'; |
| 13 | + |
| 14 | +test('tests installPackage remove the aliases property if the property existed', async () => { |
| 15 | + const callCluster = elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser; |
| 16 | + callCluster.mockImplementation(async (_, params) => { |
| 17 | + if ( |
| 18 | + params && |
| 19 | + params.method === 'GET' && |
| 20 | + params.path === '/_index_template/metrics-package.dataset' |
| 21 | + ) { |
| 22 | + return { |
| 23 | + index_templates: [ |
| 24 | + { |
| 25 | + name: 'metrics-package.dataset', |
| 26 | + index_template: { |
| 27 | + index_patterns: ['metrics-package.dataset-*'], |
| 28 | + template: { aliases: {} }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + ], |
| 32 | + }; |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + const fields: Field[] = []; |
| 37 | + const dataStreamDatasetIsPrefixUnset = { |
| 38 | + type: 'metrics', |
| 39 | + dataset: 'package.dataset', |
| 40 | + title: 'test data stream', |
| 41 | + release: 'experimental', |
| 42 | + package: 'package', |
| 43 | + path: 'path', |
| 44 | + ingest_pipeline: 'default', |
| 45 | + } as RegistryDataStream; |
| 46 | + const pkg = { |
| 47 | + name: 'package', |
| 48 | + version: '0.0.1', |
| 49 | + }; |
| 50 | + const templateIndexPatternDatasetIsPrefixUnset = 'metrics-package.dataset-*'; |
| 51 | + const templatePriorityDatasetIsPrefixUnset = 200; |
| 52 | + await installTemplate({ |
| 53 | + callCluster, |
| 54 | + fields, |
| 55 | + dataStream: dataStreamDatasetIsPrefixUnset, |
| 56 | + packageVersion: pkg.version, |
| 57 | + packageName: pkg.name, |
| 58 | + }); |
| 59 | + |
| 60 | + // @ts-ignore |
| 61 | + const removeAliases = callCluster.mock.calls[1][1].body; |
| 62 | + expect(removeAliases.template.aliases).not.toBeDefined(); |
| 63 | + // @ts-ignore |
| 64 | + const sentTemplate = callCluster.mock.calls[2][1].body; |
| 65 | + expect(sentTemplate).toBeDefined(); |
| 66 | + expect(sentTemplate.priority).toBe(templatePriorityDatasetIsPrefixUnset); |
| 67 | + expect(sentTemplate.index_patterns).toEqual([templateIndexPatternDatasetIsPrefixUnset]); |
| 68 | +}); |
0 commit comments