/** * Copyright 2022 Gravwell, Inc. All rights reserved. * * Contact: [legal@gravwell.io](mailto:legal@gravwell.io) * * This software may be modified and distributed under the terms of the MIT * license. See the LICENSE file for details. */ import { omit } from 'lodash'; import { Actionable, ActionableAction } from '~/models/actionable/actionable'; import { CreatableActionable } from '~/models/actionable/creatable-actionable'; import { isActionable } from '~/models/actionable/is-actionable'; import { UpdatableActionable } from '~/models/actionable/updatable-actionable'; import { TEST_BASE_API_CONTEXT } from '~/tests/config'; import { integrationTest, integrationTestSpecDef } from '~/tests/test-types'; import { omitUndefinedShallow } from '../utils/omit-undefined-shallow'; import { makeCreateOneActionable } from './create-one-actionable'; import { makeDeleteOneActionable } from './delete-one-actionable'; import { makeGetOneActionable } from './get-one-actionable'; import { makeUpdateOneActionable } from './update-one-actionable'; xdescribe( 'updateOneActionable()', integrationTestSpecDef(() => { let createOneActionable: ReturnType; beforeAll(async () => { createOneActionable = makeCreateOneActionable(await TEST_BASE_API_CONTEXT()); }); let getOneActionable: ReturnType; beforeAll(async () => { getOneActionable = makeGetOneActionable(await TEST_BASE_API_CONTEXT()); }); let updateOneActionable: ReturnType; beforeAll(async () => { updateOneActionable = makeUpdateOneActionable(await TEST_BASE_API_CONTEXT()); }); let deleteOneActionable: ReturnType; beforeAll(async () => { deleteOneActionable = makeDeleteOneActionable(await TEST_BASE_API_CONTEXT()); }); let createdActionable: Actionable; beforeEach(async () => { // Create one actionable const data: CreatableActionable = { name: 'Current name', description: 'Current description', menuLabel: 'Current label', actions: [{ name: 'Current action', command: { type: 'query', userQuery: 'tag=netflow' } }], triggers: [{ pattern: /abc/g, activatesOn: 'clicks and selection', disabled: false }], isDisabled: false, }; createdActionable = await createOneActionable(data); }); afterEach(async () => { await deleteOneActionable(createdActionable.id).catch(() => undefined); }); const updateTests: Array> = [ { name: 'New name' }, { description: 'New description' }, { description: null }, { menuLabel: 'New label' }, { menuLabel: null }, { userID: '2' }, { groupIDs: ['1'] }, { groupIDs: ['1', '2'] }, { groupIDs: [] }, { isGlobal: true }, { isGlobal: false }, { actions: [] }, { actions: [ { name: 'New action', description: 'New action description', command: { type: 'url', urlTemplate: 'http://google__VALUE__', modal: false, modalWidthPercentage: null, noValueUrlEncode: false, }, }, ], }, { triggers: [] }, { triggers: [{ pattern: /123/g, activatesOn: 'selection', disabled: false }] }, ]; updateTests.forEach((_data, testIndex) => { const updatedFields = Object.keys(omit(_data, ['id'])); const formatedUpdatedFields = updatedFields.join(', '); const formatedTestIndex = (testIndex + 1).toString().padStart(2, '0'); // gravwell/gravwell#2425 xit( `Test ${formatedTestIndex}: Should update an actionable ${formatedUpdatedFields} and return itself updated`, integrationTest(async () => { const current = createdActionable; expect(isActionable(current)).toBeTrue(); const data: UpdatableActionable = { ..._data, id: current.id }; if (updatedFields.includes('userID')) { // *NOTE: gravwell/gravwell#2318 nÂș 7 await expectAsync(updateOneActionable(data)).toBeRejected(); await expectAsync(getOneActionable(data.id)).toBeRejected(); return; } const updated = await updateOneActionable(data); expect(isActionable(updated)).toBeTrue(); const parsedData = omitUndefinedShallow({ ...data, actions: data.actions?.map(action => ({ ...action, description: action.description ?? null, placeholder: action.placeholder ?? null, start: action.start ?? { type: 'stringFormat', placeholder: null, format: null }, end: action.end ?? { type: 'stringFormat', placeholder: null, format: null }, })), }); expect(updated).toEqual({ ...current, ...parsedData, lastUpdateDate: updated.lastUpdateDate }); }), ); }); }), );