Skip to content

Commit

Permalink
[ML] Use TRANSFORM_STATE instead of raw strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Sep 10, 2020
1 parent 894b1f8 commit e434c4f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 31 deletions.
24 changes: 14 additions & 10 deletions x-pack/test/api_integration/apis/transform/delete_transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';

import { DeleteTransformsRequestSchema } from '../../../../plugins/transform/common/api_schemas/delete_transforms';
import { FtrProviderContext } from '../../ftr_provider_context';
import { TRANSFORM_STATE } from '../../../../plugins/transform/common/constants';

import { COMMON_REQUEST_HEADERS } from '../../../functional/services/ml/common_api';
import { USER } from '../../../functional/services/transform/security_common';

import { FtrProviderContext } from '../../ftr_provider_context';

import { asyncForEach, generateDestIndex, generateTransformConfig } from './common';

export default ({ getService }: FtrProviderContext) => {
Expand Down Expand Up @@ -46,7 +50,7 @@ export default ({ getService }: FtrProviderContext) => {

it('should delete transform by transformId', async () => {
const reqBody: DeleteTransformsRequestSchema = {
transformsInfo: [{ id: transformId, state: 'stopped' }],
transformsInfo: [{ id: transformId, state: TRANSFORM_STATE.STOPPED }],
};
const { body } = await supertest
.post(`/api/transform/delete_transforms`)
Expand All @@ -67,7 +71,7 @@ export default ({ getService }: FtrProviderContext) => {

it('should return 403 for unauthorized user', async () => {
const reqBody: DeleteTransformsRequestSchema = {
transformsInfo: [{ id: transformId, state: 'stopped' }],
transformsInfo: [{ id: transformId, state: TRANSFORM_STATE.STOPPED }],
};
await supertest
.post(`/api/transform/delete_transforms`)
Expand All @@ -86,7 +90,7 @@ export default ({ getService }: FtrProviderContext) => {
describe('single transform deletion with invalid transformId', function () {
it('should return 200 with error in response if invalid transformId', async () => {
const reqBody: DeleteTransformsRequestSchema = {
transformsInfo: [{ id: 'invalid_transform_id', state: 'stopped' }],
transformsInfo: [{ id: 'invalid_transform_id', state: TRANSFORM_STATE.STOPPED }],
};
const { body } = await supertest
.post(`/api/transform/delete_transforms`)
Expand All @@ -105,8 +109,8 @@ export default ({ getService }: FtrProviderContext) => {
describe('bulk deletion', function () {
const reqBody: DeleteTransformsRequestSchema = {
transformsInfo: [
{ id: 'bulk_delete_test_1', state: 'stopped' },
{ id: 'bulk_delete_test_2', state: 'stopped' },
{ id: 'bulk_delete_test_1', state: TRANSFORM_STATE.STOPPED },
{ id: 'bulk_delete_test_2', state: TRANSFORM_STATE.STOPPED },
],
};
const destinationIndices = reqBody.transformsInfo.map((d) => generateDestIndex(d.id));
Expand Down Expand Up @@ -160,7 +164,7 @@ export default ({ getService }: FtrProviderContext) => {
...reqBody,
transformsInfo: [
...reqBody.transformsInfo,
{ id: invalidTransformId, state: 'stopped' },
{ id: invalidTransformId, state: TRANSFORM_STATE.STOPPED },
],
})
.expect(200);
Expand Down Expand Up @@ -196,7 +200,7 @@ export default ({ getService }: FtrProviderContext) => {

it('should delete transform and destination index', async () => {
const reqBody: DeleteTransformsRequestSchema = {
transformsInfo: [{ id: transformId, state: 'stopped' }],
transformsInfo: [{ id: transformId, state: TRANSFORM_STATE.STOPPED }],
deleteDestIndex: true,
};
const { body } = await supertest
Expand Down Expand Up @@ -234,7 +238,7 @@ export default ({ getService }: FtrProviderContext) => {

it('should delete transform and destination index pattern', async () => {
const reqBody: DeleteTransformsRequestSchema = {
transformsInfo: [{ id: transformId, state: 'stopped' }],
transformsInfo: [{ id: transformId, state: TRANSFORM_STATE.STOPPED }],
deleteDestIndex: false,
deleteDestIndexPattern: true,
};
Expand Down Expand Up @@ -274,7 +278,7 @@ export default ({ getService }: FtrProviderContext) => {

it('should delete transform, destination index, & destination index pattern', async () => {
const reqBody: DeleteTransformsRequestSchema = {
transformsInfo: [{ id: transformId, state: 'stopped' }],
transformsInfo: [{ id: transformId, state: TRANSFORM_STATE.STOPPED }],
deleteDestIndex: true,
deleteDestIndexPattern: true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import expect from '@kbn/expect';

import { StartTransformsRequestSchema } from '../../../../plugins/transform/common/api_schemas/start_transforms';
import { TRANSFORM_STATE } from '../../../../plugins/transform/common/constants';

import { COMMON_REQUEST_HEADERS } from '../../../functional/services/ml/common_api';
import { USER } from '../../../functional/services/transform/security_common';
Expand Down Expand Up @@ -76,7 +77,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(body[transformId].success).to.eql(false);
expect(typeof body[transformId].error).to.eql('string');

await transform.api.waitForTransformState(transformId, 'stopped');
await transform.api.waitForTransformState(transformId, TRANSFORM_STATE.STOPPED);
await transform.api.waitForIndicesNotToExist(destinationIndex);
});
});
Expand Down
23 changes: 14 additions & 9 deletions x-pack/test/api_integration/apis/transform/stop_transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/
import expect from '@kbn/expect';

import type { StopTransformsRequestSchema } from '../../../../plugins/transform/common/api_schemas/stop_transforms';
import type { PutTransformsRequestSchema } from '../../../../plugins/transform/common/api_schemas/transforms';
import type { StopTransformsRequestSchema } from '../../../../plugins/transform/common/api_schemas/stop_transforms';
import { TRANSFORM_STATE } from '../../../../plugins/transform/common/constants';

import { COMMON_REQUEST_HEADERS } from '../../../functional/services/ml/common_api';
import { USER } from '../../../functional/services/transform/security_common';
Expand Down Expand Up @@ -58,7 +59,9 @@ export default ({ getService }: FtrProviderContext) => {
});

it('should stop the transform by transformId', async () => {
const reqBody: StopTransformsRequestSchema = [{ id: transformId, state: 'started' }];
const reqBody: StopTransformsRequestSchema = [
{ id: transformId, state: TRANSFORM_STATE.STARTED },
];
const { body } = await supertest
.post(`/api/transform/stop_transforms`)
.auth(
Expand All @@ -75,9 +78,11 @@ export default ({ getService }: FtrProviderContext) => {
});

it('should return 200 with success:false for unauthorized user', async () => {
await transform.api.waitForTransformStateNotToBe(transformId, 'stopped');
await transform.api.waitForTransformStateNotToBe(transformId, TRANSFORM_STATE.STOPPED);

const reqBody: StopTransformsRequestSchema = [{ id: transformId, state: 'started' }];
const reqBody: StopTransformsRequestSchema = [
{ id: transformId, state: TRANSFORM_STATE.STARTED },
];
const { body } = await supertest
.post(`/api/transform/stop_transforms`)
.auth(
Expand All @@ -91,15 +96,15 @@ export default ({ getService }: FtrProviderContext) => {
expect(body[transformId].success).to.eql(false);
expect(typeof body[transformId].error).to.eql('string');

await transform.api.waitForTransformStateNotToBe(transformId, 'stopped');
await transform.api.waitForTransformStateNotToBe(transformId, TRANSFORM_STATE.STOPPED);
await transform.api.waitForIndicesToExist(destinationIndex);
});
});

describe('single transform stop with invalid transformId', function () {
it('should return 200 with error in response if invalid transformId', async () => {
const reqBody: StopTransformsRequestSchema = [
{ id: 'invalid_transform_id', state: 'started' },
{ id: 'invalid_transform_id', state: TRANSFORM_STATE.STARTED },
];
const { body } = await supertest
.post(`/api/transform/stop_transforms`)
Expand All @@ -118,8 +123,8 @@ export default ({ getService }: FtrProviderContext) => {

describe('bulk stop', function () {
const reqBody: StopTransformsRequestSchema = [
{ id: 'bulk_stop_test_1', state: 'started' },
{ id: 'bulk_stop_test_2', state: 'started' },
{ id: 'bulk_stop_test_1', state: TRANSFORM_STATE.STARTED },
{ id: 'bulk_stop_test_2', state: TRANSFORM_STATE.STARTED },
];
const destinationIndices = reqBody.map((d) => generateDestIndex(d.id));

Expand Down Expand Up @@ -164,7 +169,7 @@ export default ({ getService }: FtrProviderContext) => {
.set(COMMON_REQUEST_HEADERS)
.send([
{ id: reqBody[0].id, state: reqBody[0].state },
{ id: invalidTransformId, state: 'stopped' },
{ id: invalidTransformId, state: TRANSFORM_STATE.STOPPED },
{ id: reqBody[1].id, state: reqBody[1].state },
])
.expect(200);
Expand Down
10 changes: 7 additions & 3 deletions x-pack/test/api_integration/apis/transform/transforms_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

import { TRANSFORM_STATE } from '../../../../plugins/transform/common/constants';

import { COMMON_REQUEST_HEADERS } from '../../../functional/services/ml/common_api';
import { USER } from '../../../functional/services/transform/security_common';

import { FtrProviderContext } from '../../ftr_provider_context';

import { generateTransformConfig } from './common';

export default ({ getService }: FtrProviderContext) => {
Expand All @@ -18,8 +22,8 @@ export default ({ getService }: FtrProviderContext) => {
const expected = {
apiTransformTransforms: {
count: 2,
transform1: { id: 'the-transform-1', state: 'stopped' },
transform2: { id: 'the-transform-2', state: 'stopped' },
transform1: { id: 'the-transform-1', state: TRANSFORM_STATE.STOPPED },
transform2: { id: 'the-transform-2', state: TRANSFORM_STATE.STOPPED },
typeOfStats: 'object',
typeOfCheckpointing: 'object',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { TRANSFORM_STATE } from '../../../../plugins/transform/common/constants';

import { FtrProviderContext } from '../../ftr_provider_context';

interface GroupByEntry {
Expand Down Expand Up @@ -141,7 +143,7 @@ export default function ({ getService }: FtrProviderContext) {
values: [`Men's Accessories`],
},
row: {
status: 'stopped',
status: TRANSFORM_STATE.STOPPED,
mode: 'batch',
progress: '100',
},
Expand Down Expand Up @@ -239,7 +241,7 @@ export default function ({ getService }: FtrProviderContext) {
values: ['AE', 'CO', 'EG', 'FR', 'GB'],
},
row: {
status: 'stopped',
status: TRANSFORM_STATE.STOPPED,
mode: 'batch',
progress: '100',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { TRANSFORM_STATE } from '../../../../plugins/transform/common/constants';

import { FtrProviderContext } from '../../ftr_provider_context';

interface GroupByEntry {
Expand Down Expand Up @@ -58,7 +60,7 @@ export default function ({ getService }: FtrProviderContext) {
values: ['ASA'],
},
row: {
status: 'stopped',
status: TRANSFORM_STATE.STOPPED,
mode: 'batch',
progress: '100',
},
Expand Down
6 changes: 4 additions & 2 deletions x-pack/test/functional/apps/transform/editing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { FtrProviderContext } from '../../ftr_provider_context';
import { TransformPivotConfig } from '../../../../plugins/transform/common/types/transform';
import { TRANSFORM_STATE } from '../../../../plugins/transform/common/constants';

import { FtrProviderContext } from '../../ftr_provider_context';

function getTransformConfig(): TransformPivotConfig {
const date = Date.now();
Expand Down Expand Up @@ -52,7 +54,7 @@ export default function ({ getService }: FtrProviderContext) {
expected: {
messageText: 'updated transform.',
row: {
status: 'stopped',
status: TRANSFORM_STATE.STOPPED,
mode: 'batch',
progress: '100',
},
Expand Down
6 changes: 3 additions & 3 deletions x-pack/test/functional/services/transform/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/
import expect from '@kbn/expect';

import { FtrProviderContext } from '../../ftr_provider_context';

import type { PutTransformsRequestSchema } from '../../../../plugins/transform/common/api_schemas/transforms';
import { TransformState, TRANSFORM_STATE } from '../../../../plugins/transform/common/constants';
import type { TransformStats } from '../../../../plugins/transform/common/types/transform_stats';

import { FtrProviderContext } from '../../ftr_provider_context';

export async function asyncForEach(array: any[], callback: Function) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
Expand Down Expand Up @@ -94,7 +94,7 @@ export function TransformAPIProvider({ getService }: FtrProviderContext) {
await esSupertest
.post(`/_transform/${transformId}/_stop?force=true&wait_for_completion`)
.expect(200);
await this.waitForTransformState(transformId, 'stopped');
await this.waitForTransformState(transformId, TRANSFORM_STATE.STOPPED);

await esSupertest.delete(`/_transform/${transformId}`).expect(200);
await this.waitForTransformNotToExist(transformId);
Expand Down

0 comments on commit e434c4f

Please sign in to comment.