From a0b419d149e561238be5046eb274d69b30179e0c Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 4 May 2023 12:30:13 -0500 Subject: [PATCH] More robust checks on transform's state --- x-pack/plugins/transform/readme.md | 4 +- .../apps/transform/actions/reauthorizing.ts | 102 ++++++++---------- 2 files changed, 48 insertions(+), 58 deletions(-) diff --git a/x-pack/plugins/transform/readme.md b/x-pack/plugins/transform/readme.md index acd433d235dac35..8c25f2ddd8ac46f 100644 --- a/x-pack/plugins/transform/readme.md +++ b/x-pack/plugins/transform/readme.md @@ -122,7 +122,7 @@ With PATH_TO_CONFIG and other options as follows. edit, clone | `test/functional/apps/transform/edit_clone/config.ts` feature controls | `test/functional/apps/transform/feature_controls/config.ts` permissions | `test/functional/apps/transform/permissions/config.ts` - start, reset, delete | `test/functional/apps/transform/actions/config.ts` + actions | `test/functional/apps/transform/actions/config.ts` 1. Functional UI tests with `Basic` license: @@ -133,7 +133,7 @@ With PATH_TO_CONFIG and other options as follows. edit, clone | `test/functional_basic/apps/transform/edit_clone/config.ts` feature controls | `test/functional_basic/apps/transform/feature_controls/config.ts` permissions | `test/functional_basic/apps/transform/permissions/config.ts` - start, reset, delete | `test/functional_basic/apps/transform/actions/config.ts` + actions | `test/functional_basic/apps/transform/actions/config.ts` 1. API integration tests with `Trial` license: diff --git a/x-pack/test/functional/apps/transform/actions/reauthorizing.ts b/x-pack/test/functional/apps/transform/actions/reauthorizing.ts index 23f99221318f782..489d0a3a7ff5dd2 100644 --- a/x-pack/test/functional/apps/transform/actions/reauthorizing.ts +++ b/x-pack/test/functional/apps/transform/actions/reauthorizing.ts @@ -5,17 +5,13 @@ * 2.0. */ -import { - TRANSFORM_HEALTH, - TRANSFORM_HEALTH_LABEL, - TRANSFORM_HEALTH_DESCRIPTION, -} from '@kbn/transform-plugin/common/constants'; -import { +import { TRANSFORM_HEALTH_LABEL, TRANSFORM_STATE } from '@kbn/transform-plugin/common/constants'; +import type { TransformLatestConfig, TransformPivotConfig, } from '@kbn/transform-plugin/common/types/transform'; -import { SecurityCreateApiKeyResponse } from '@elastic/elasticsearch/lib/api/types'; -import { FtrProviderContext } from '../../../ftr_provider_context'; +import type { SecurityCreateApiKeyResponse } from '@elastic/elasticsearch/lib/api/types'; +import type { FtrProviderContext } from '../../../ftr_provider_context'; import { getLatestTransformConfig, getPivotTransformConfig } from '../helpers'; import { USER } from '../../../services/transform/security_common'; import { COMMON_REQUEST_HEADERS } from '../../../services/ml/common_api'; @@ -26,11 +22,9 @@ interface TestDataPivot { mode: 'batch' | 'continuous'; type: 'pivot'; expected: { - healthDescription: string; - healthLabel: string; - healthStatus: string; + originalState: object; reauthorizeEnabled: boolean; - originalStatus: string; + reauthorizedState: object; }; created_by_user: USER; current_user: USER; @@ -42,11 +36,9 @@ interface TestDataLatest { mode: 'batch' | 'continuous'; type: 'latest'; expected: { - healthDescription: string; - healthLabel: string; - healthStatus: string; + originalState: object; reauthorizeEnabled: boolean; - originalStatus: string; + reauthorizedState: object; }; created_by_user: USER; current_user: USER; @@ -70,20 +62,35 @@ export default function ({ getService }: FtrProviderContext) { describe('reauthorizing', function () { const PREFIX = 'reauthorizing'; const testDataList: TestData[] = [ + // { + // suiteTitle: 'continuous pivot transform (created by viewer, viewed by viewer)', + // originalConfig: getPivotTransformConfig(`${PREFIX}-${USER.TRANSFORM_VIEWER}-1`, true), + // mode: 'continuous', + // type: 'pivot', + // expected: { + // originalState: { status: TRANSFORM_STATE.STOPPED, health: TRANSFORM_HEALTH_LABEL.red }, + // reauthorizeEnabled: false, + // reauthorizedState: { status: 'started', health: TRANSFORM_HEALTH_LABEL.green }, + // }, + // created_by_user: USER.TRANSFORM_VIEWER, + // current_user: USER.TRANSFORM_VIEWER, + // }, { - suiteTitle: 'continuous pivot transform (created by viewer, viewed by viewer)', - originalConfig: getPivotTransformConfig(`${PREFIX}-${USER.TRANSFORM_VIEWER}-1`, true), - mode: 'continuous', + suiteTitle: 'batch pivot transform (created by viewer, viewed by poweruser)', + originalConfig: getPivotTransformConfig(PREFIX, false), + mode: 'batch', type: 'pivot', expected: { - healthDescription: TRANSFORM_HEALTH_DESCRIPTION.green, - healthLabel: TRANSFORM_HEALTH_LABEL.green, - healthStatus: TRANSFORM_HEALTH.green, - originalStatus: 'stopped', - reauthorizeEnabled: false, + originalState: { status: TRANSFORM_STATE.STOPPED, health: TRANSFORM_HEALTH_LABEL.red }, + reauthorizeEnabled: true, + reauthorizedState: { + status: TRANSFORM_STATE.STOPPED, + progress: '100', + health: TRANSFORM_HEALTH_LABEL.green, + }, }, created_by_user: USER.TRANSFORM_VIEWER, - current_user: USER.TRANSFORM_VIEWER, + current_user: USER.TRANSFORM_POWERUSER, }, { suiteTitle: 'continuous pivot transform (created by viewer, authorized by poweruser)', @@ -91,11 +98,12 @@ export default function ({ getService }: FtrProviderContext) { mode: 'continuous', type: 'pivot', expected: { - healthDescription: TRANSFORM_HEALTH_DESCRIPTION.green, - healthLabel: TRANSFORM_HEALTH_LABEL.green, - healthStatus: TRANSFORM_HEALTH.green, - originalStatus: 'stopped', + originalState: { status: TRANSFORM_STATE.STOPPED, health: TRANSFORM_HEALTH_LABEL.red }, reauthorizeEnabled: true, + reauthorizedState: { + status: 'started', + health: TRANSFORM_HEALTH_LABEL.green, + }, }, created_by_user: USER.TRANSFORM_VIEWER, current_user: USER.TRANSFORM_POWERUSER, @@ -106,12 +114,9 @@ export default function ({ getService }: FtrProviderContext) { mode: 'continuous', type: 'latest', expected: { - healthDescription: TRANSFORM_HEALTH_DESCRIPTION.green, - healthLabel: TRANSFORM_HEALTH_LABEL.green, - healthStatus: TRANSFORM_HEALTH.green, - originalStatus: 'started', - + originalState: { status: 'started', health: TRANSFORM_HEALTH_LABEL.green }, reauthorizeEnabled: false, + reauthorizedState: { status: 'started', health: TRANSFORM_HEALTH_LABEL.green }, }, created_by_user: USER.TRANSFORM_POWERUSER, current_user: USER.TRANSFORM_VIEWER, @@ -130,18 +135,6 @@ export default function ({ getService }: FtrProviderContext) { await transform.testResources.createIndexPatternIfNeeded('ft_ecommerce', 'order_date'); for (const testData of testDataList) { - if ( - testData.expected.healthStatus === TRANSFORM_HEALTH.yellow && - testData.type === 'pivot' - ) { - testData.originalConfig.pivot.aggregations['products.base_price.fail'] = { - avg: { - script: { - source: "def a = doc['non_existing'].value", - }, - }, - }; - } await transform.api.createTransform(testData.originalConfig.id, testData.originalConfig, { deferValidation: true, headers: generateHeaders(apiKeysForTransformUsers.get(testData.created_by_user)!), @@ -184,9 +177,10 @@ export default function ({ getService }: FtrProviderContext) { 'should display the original transform in the transform list' ); await transform.table.filterWithSearchString(transformId, 1); - await transform.table.assertTransformRowFields(transformId, { - status: testData.expected.originalStatus, - }); + await transform.table.assertTransformRowFields( + transformId, + testData.expected.originalState + ); if (testData.expected.reauthorizeEnabled) { await transform.testExecution.logTestStep('should reauthorize the transform'); @@ -198,15 +192,11 @@ export default function ({ getService }: FtrProviderContext) { await transform.table.clickTransformRowAction(transformId, 'Reauthorize'); await transform.table.confirmReauthorizeTransform(); - await transform.table.assertTransformExpandedRowHealth( - testData.expected.healthDescription, - testData.expected.healthStatus !== TRANSFORM_HEALTH.green + await transform.table.assertTransformRowFields( + transformId, + testData.expected.reauthorizedState ); - await transform.table.assertTransformRowFields(transformId, { - status: 'started', - }); } - await transform.table.clearSearchString(testDataList.length); }); });