From f3f37ed4e68dc4d8769da71016e417bd05857d1e Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Thu, 27 Apr 2023 12:01:27 +0200 Subject: [PATCH] fix/adapt zdt algo utils --- .../check_version_compatibility.test.mocks.ts | 12 +++---- .../utils/check_version_compatibility.test.ts | 36 +++++++++---------- .../generate_additive_mapping_diff.test.ts | 33 +++++++++-------- 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/check_version_compatibility.test.mocks.ts b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/check_version_compatibility.test.mocks.ts index a0e03552ed946..8d7cbe657758c 100644 --- a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/check_version_compatibility.test.mocks.ts +++ b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/check_version_compatibility.test.mocks.ts @@ -6,16 +6,16 @@ * Side Public License, v 1. */ -export const getModelVersionsFromMappingsMock = jest.fn(); -export const compareModelVersionsMock = jest.fn(); -export const getModelVersionMapForTypesMock = jest.fn(); +export const getVirtualVersionsFromMappingsMock = jest.fn(); +export const compareVirtualVersionsMock = jest.fn(); +export const getVirtualVersionMapMock = jest.fn(); jest.doMock('@kbn/core-saved-objects-base-server-internal', () => { const actual = jest.requireActual('@kbn/core-saved-objects-base-server-internal'); return { ...actual, - getModelVersionsFromMappings: getModelVersionsFromMappingsMock, - compareModelVersions: compareModelVersionsMock, - getModelVersionMapForTypes: getModelVersionMapForTypesMock, + getVirtualVersionsFromMappings: getVirtualVersionsFromMappingsMock, + compareVirtualVersions: compareVirtualVersionsMock, + getVirtualVersionMap: getVirtualVersionMapMock, }; }); diff --git a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/check_version_compatibility.test.ts b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/check_version_compatibility.test.ts index 8430f1f898426..528855417e90f 100644 --- a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/check_version_compatibility.test.ts +++ b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/check_version_compatibility.test.ts @@ -7,14 +7,14 @@ */ import { - compareModelVersionsMock, - getModelVersionsFromMappingsMock, - getModelVersionMapForTypesMock, + compareVirtualVersionsMock, + getVirtualVersionMapMock, + getVirtualVersionsFromMappingsMock, } from './check_version_compatibility.test.mocks'; import type { SavedObjectsType } from '@kbn/core-saved-objects-server'; import type { IndexMapping, - ModelVersionMap, + VirtualVersionMap, CompareModelVersionResult, } from '@kbn/core-saved-objects-base-server-internal'; import { checkVersionCompatibility } from './check_version_compatibility'; @@ -27,9 +27,9 @@ describe('checkVersionCompatibility', () => { let mappings: IndexMapping; beforeEach(() => { - compareModelVersionsMock.mockReset().mockReturnValue({}); - getModelVersionsFromMappingsMock.mockReset().mockReturnValue({}); - getModelVersionMapForTypesMock.mockReset().mockReturnValue({ status: 'equal' }); + compareVirtualVersionsMock.mockReset().mockReturnValue({}); + getVirtualVersionMapMock.mockReset().mockReturnValue({}); + getVirtualVersionsFromMappingsMock.mockReset().mockReturnValue({ status: 'equal' }); types = [createType({ name: 'foo' }), createType({ name: 'bar' })]; @@ -46,8 +46,8 @@ describe('checkVersionCompatibility', () => { deletedTypes, }); - expect(getModelVersionMapForTypesMock).toHaveBeenCalledTimes(1); - expect(getModelVersionMapForTypesMock).toHaveBeenCalledWith(types); + expect(getVirtualVersionMapMock).toHaveBeenCalledTimes(1); + expect(getVirtualVersionMapMock).toHaveBeenCalledWith(types); }); it('calls getModelVersionsFromMappings with the correct parameters', () => { @@ -58,8 +58,8 @@ describe('checkVersionCompatibility', () => { deletedTypes, }); - expect(getModelVersionsFromMappingsMock).toHaveBeenCalledTimes(1); - expect(getModelVersionsFromMappingsMock).toHaveBeenCalledWith({ + expect(getVirtualVersionsFromMappingsMock).toHaveBeenCalledTimes(1); + expect(getVirtualVersionsFromMappingsMock).toHaveBeenCalledWith({ mappings, source: 'mappingVersions', knownTypes: ['foo', 'bar'], @@ -67,11 +67,11 @@ describe('checkVersionCompatibility', () => { }); it('calls compareModelVersions with the correct parameters', () => { - const appVersions: ModelVersionMap = { foo: 2, bar: 2 }; - const indexVersions: ModelVersionMap = { foo: 1, bar: 1 }; + const appVersions: VirtualVersionMap = { foo: '10.2.0', bar: '10.2.0' }; + const indexVersions: VirtualVersionMap = { foo: '10.1.0', bar: '10.1.0' }; - getModelVersionMapForTypesMock.mockReturnValue(appVersions); - getModelVersionsFromMappingsMock.mockReturnValue(indexVersions); + getVirtualVersionMapMock.mockReturnValue(appVersions); + getVirtualVersionsFromMappingsMock.mockReturnValue(indexVersions); checkVersionCompatibility({ types, @@ -80,8 +80,8 @@ describe('checkVersionCompatibility', () => { deletedTypes, }); - expect(compareModelVersionsMock).toHaveBeenCalledTimes(1); - expect(compareModelVersionsMock).toHaveBeenCalledWith({ + expect(compareVirtualVersionsMock).toHaveBeenCalledTimes(1); + expect(compareVirtualVersionsMock).toHaveBeenCalledWith({ appVersions, indexVersions, deletedTypes, @@ -97,7 +97,7 @@ describe('checkVersionCompatibility', () => { equal: [], }, }; - compareModelVersionsMock.mockReturnValue(expected); + compareVirtualVersionsMock.mockReturnValue(expected); const result = checkVersionCompatibility({ types, diff --git a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/generate_additive_mapping_diff.test.ts b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/generate_additive_mapping_diff.test.ts index ce0cba20f427c..9e711dd6daaf1 100644 --- a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/generate_additive_mapping_diff.test.ts +++ b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/utils/generate_additive_mapping_diff.test.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import type { SavedObjectsModelVersion } from '@kbn/core-saved-objects-server'; import type { IndexMappingMeta } from '@kbn/core-saved-objects-base-server-internal'; import { generateAdditiveMappingDiff } from './generate_additive_mapping_diff'; import { createType } from '../test_helpers'; @@ -13,20 +14,24 @@ import { createType } from '../test_helpers'; describe('generateAdditiveMappingDiff', () => { const deletedTypes = ['deletedType']; + const stubMigration = jest.fn(); + const stubModelVersion: SavedObjectsModelVersion = { modelChange: { type: 'expansion' } }; + const getTypes = () => { const foo = createType({ name: 'foo', + switchToModelVersionAt: '8.0.0', modelVersions: { - 1: { modelChange: { type: 'expansion' } }, - 2: { modelChange: { type: 'expansion' } }, + 1: stubModelVersion, + 2: stubModelVersion, }, mappings: { properties: { fooProp: { type: 'text' } } }, }); const bar = createType({ name: 'bar', - modelVersions: { - 1: { modelChange: { type: 'expansion' } }, - 2: { modelChange: { type: 'expansion' } }, + migrations: { + '8.0.0': stubMigration, + '8.5.0': stubMigration, }, mappings: { properties: { barProp: { type: 'text' } } }, }); @@ -39,8 +44,8 @@ describe('generateAdditiveMappingDiff', () => { const types = [foo, bar]; const meta: IndexMappingMeta = { mappingVersions: { - foo: 1, - bar: 1, + foo: '10.1.0', + bar: '7.9.0', }, }; @@ -61,8 +66,8 @@ describe('generateAdditiveMappingDiff', () => { const types = [foo, bar]; const meta: IndexMappingMeta = { mappingVersions: { - foo: 1, - bar: 2, + foo: '10.1.0', + bar: '8.5.0', }, }; @@ -82,9 +87,9 @@ describe('generateAdditiveMappingDiff', () => { const types = [foo, bar]; const meta: IndexMappingMeta = { mappingVersions: { - foo: 1, - bar: 1, - deletedType: 42, + foo: '10.1.0', + bar: '8.2.0', + deletedType: '10.2.0', }, }; @@ -105,8 +110,8 @@ describe('generateAdditiveMappingDiff', () => { const types = [foo, bar]; const meta: IndexMappingMeta = { mappingVersions: { - foo: 1, - bar: 3, + foo: '10.1.0', + bar: '10.1.0', }, };