From 3e81ea1afb2835fd6d3f45a07a568f3794f4d5e8 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Wed, 26 Apr 2023 11:13:33 +0300 Subject: [PATCH] PR feedback & fix types --- .../connectors/swimlane/translations.ts | 2 +- x-pack/plugins/cases/public/containers/api.ts | 31 ++-- .../plugins/cases/public/containers/utils.ts | 8 +- .../plugins/cases/server/client/utils.test.ts | 16 +-- .../plugins/cases/server/common/constants.ts | 38 ++--- .../plugins/cases/server/common/types/case.ts | 20 +-- .../migrations/cases.test.ts | 20 +-- .../saved_object_types/migrations/cases.ts | 14 +- .../cases/server/services/cases/index.test.ts | 132 +++++++++--------- .../cases/server/services/cases/index.ts | 8 +- .../server/services/cases/transform.test.ts | 44 +++--- .../cases/server/services/cases/transform.ts | 4 +- .../cases/server/services/configure/types.ts | 4 +- .../cases/server/services/test_utils.ts | 14 +- .../cases/server/services/transform.ts | 12 +- .../server/telemetry/queries/cases.test.ts | 4 +- .../cases/server/telemetry/queries/cases.ts | 8 +- .../tests/common/cases/import_export.ts | 8 +- .../tests/common/cases/migrations.ts | 24 ++-- 19 files changed, 206 insertions(+), 205 deletions(-) diff --git a/x-pack/plugins/cases/public/components/connectors/swimlane/translations.ts b/x-pack/plugins/cases/public/components/connectors/swimlane/translations.ts index 00c21bc0e657a0..eb6cd168fab991 100644 --- a/x-pack/plugins/cases/public/components/connectors/swimlane/translations.ts +++ b/x-pack/plugins/cases/public/components/connectors/swimlane/translations.ts @@ -37,6 +37,6 @@ export const EMPTY_MAPPING_WARNING_DESC = i18n.translate( 'xpack.cases.connectors.swimlane.emptyMappingWarningDesc', { defaultMessage: - 'This connector cannot be selected because it is missing the required case field mappings. You can edit this connector to add required field mappings or select a connector of type Cases', + 'This connector cannot be selected because it is missing the required case field mappings. You can edit this connector to add required field mappings or select a connector of type Cases.', } ); diff --git a/x-pack/plugins/cases/public/containers/api.ts b/x-pack/plugins/cases/public/containers/api.ts index d1ad89b7d2a3bb..2d9e17658d156d 100644 --- a/x-pack/plugins/cases/public/containers/api.ts +++ b/x-pack/plugins/cases/public/containers/api.ts @@ -31,6 +31,8 @@ import type { CasesFindResponse, GetCaseConnectorsResponse, CaseUserActionStatsResponse, + Case, + Cases, } from '../../common/api'; import { CommentType, @@ -90,7 +92,7 @@ export const getCase = async ( includeComments: boolean = true, signal: AbortSignal ): Promise => { - const response = await KibanaServices.get().http.fetch(getCaseDetailsUrl(caseId), { + const response = await KibanaServices.get().http.fetch(getCaseDetailsUrl(caseId), { method: 'GET', query: { includeComments, @@ -244,7 +246,7 @@ export const getCases = async ({ }; export const postCase = async (newCase: CasePostRequest, signal: AbortSignal): Promise => { - const response = await KibanaServices.get().http.fetch(CASES_URL, { + const response = await KibanaServices.get().http.fetch(CASES_URL, { method: 'POST', body: JSON.stringify(newCase), signal, @@ -261,7 +263,7 @@ export const patchCase = async ( version: string, signal: AbortSignal ): Promise => { - const response = await KibanaServices.get().http.fetch(CASES_URL, { + const response = await KibanaServices.get().http.fetch(CASES_URL, { method: 'PATCH', body: JSON.stringify({ cases: [{ ...updatedCase, id: caseId, version }] }), signal, @@ -277,7 +279,7 @@ export const updateCases = async ( return []; } - const response = await KibanaServices.get().http.fetch(CASES_URL, { + const response = await KibanaServices.get().http.fetch(CASES_URL, { method: 'PATCH', body: JSON.stringify({ cases }), signal, @@ -291,14 +293,11 @@ export const postComment = async ( caseId: string, signal: AbortSignal ): Promise => { - const response = await KibanaServices.get().http.fetch( - `${CASES_URL}/${caseId}/comments`, - { - method: 'POST', - body: JSON.stringify(newComment), - signal, - } - ); + const response = await KibanaServices.get().http.fetch(`${CASES_URL}/${caseId}/comments`, { + method: 'POST', + body: JSON.stringify(newComment), + signal, + }); return convertCaseToCamelCase(decodeCaseResponse(response)); }; @@ -317,7 +316,7 @@ export const patchComment = async ({ signal: AbortSignal; owner: string; }): Promise => { - const response = await KibanaServices.get().http.fetch(getCaseCommentsUrl(caseId), { + const response = await KibanaServices.get().http.fetch(getCaseCommentsUrl(caseId), { method: 'PATCH', body: JSON.stringify({ comment: commentUpdate, @@ -340,7 +339,7 @@ export const deleteComment = async ({ commentId: string; signal: AbortSignal; }): Promise => { - await KibanaServices.get().http.fetch(getCaseCommentDeleteUrl(caseId, commentId), { + await KibanaServices.get().http.fetch(getCaseCommentDeleteUrl(caseId, commentId), { method: 'DELETE', signal, }); @@ -360,7 +359,7 @@ export const pushCase = async ( connectorId: string, signal: AbortSignal ): Promise => { - const response = await KibanaServices.get().http.fetch( + const response = await KibanaServices.get().http.fetch( getCasePushUrl(caseId, connectorId), { method: 'POST', @@ -389,7 +388,7 @@ export const createAttachments = async ( caseId: string, signal: AbortSignal ): Promise => { - const response = await KibanaServices.get().http.fetch( + const response = await KibanaServices.get().http.fetch( INTERNAL_BULK_CREATE_ATTACHMENTS_URL.replace('{case_id}', caseId), { method: 'POST', diff --git a/x-pack/plugins/cases/public/containers/utils.ts b/x-pack/plugins/cases/public/containers/utils.ts index 8227472a7c686e..66b540040415f3 100644 --- a/x-pack/plugins/cases/public/containers/utils.ts +++ b/x-pack/plugins/cases/public/containers/utils.ts @@ -21,6 +21,8 @@ import type { SingleCaseMetricsResponse, User, CaseUserActionStatsResponse, + Case, + Cases, } from '../../common/api'; import { CaseRt, @@ -34,7 +36,7 @@ import { SingleCaseMetricsResponseRt, CaseUserActionStatsResponseRt, } from '../../common/api'; -import type { CaseUI, CasesUI, FilterOptions, UpdateByKey } from './types'; +import type { CaseUI, FilterOptions, UpdateByKey } from './types'; import * as i18n from './translations'; export const getTypedPayload = (a: unknown): T => a as T; @@ -47,7 +49,7 @@ export const covertToSnakeCase = (obj: Record) => export const createToasterPlainError = (message: string) => new ToasterError([message]); -export const decodeCaseResponse = (respCase?: CaseUI) => +export const decodeCaseResponse = (respCase?: Case) => pipe(CaseRt.decode(respCase), fold(throwErrors(createToasterPlainError), identity)); export const decodeCaseResolveResponse = (respCase?: CaseResolveResponse) => @@ -62,7 +64,7 @@ export const decodeSingleCaseMetricsResponse = (respCase?: SingleCaseMetricsResp fold(throwErrors(createToasterPlainError), identity) ); -export const decodeCasesResponse = (respCase?: CasesUI) => +export const decodeCasesResponse = (respCase?: Cases) => pipe(CasesRt.decode(respCase), fold(throwErrors(createToasterPlainError), identity)); export const decodeCaseConfigurationsResponse = (respCase?: CasesConfigurationsResponse) => { diff --git a/x-pack/plugins/cases/server/client/utils.test.ts b/x-pack/plugins/cases/server/client/utils.test.ts index 86854e36c5aa36..2b63f9c7321053 100644 --- a/x-pack/plugins/cases/server/client/utils.test.ts +++ b/x-pack/plugins/cases/server/client/utils.test.ts @@ -21,7 +21,7 @@ import { constructSearch, convertSortField, } from './utils'; -import { CaseSeveritySavedObject, CaseStatusSavedObject } from '../common/types/case'; +import { CasePersistedSeverity, CasePersistedStatus } from '../common/types/case'; describe('utils', () => { describe('convertSortField', () => { @@ -401,9 +401,9 @@ describe('utils', () => { }); it.each([ - [CaseStatuses.open, CaseStatusSavedObject.OPEN], - [CaseStatuses['in-progress'], CaseStatusSavedObject.IN_PROGRESS], - [CaseStatuses.closed, CaseStatusSavedObject.CLOSED], + [CaseStatuses.open, CasePersistedStatus.OPEN], + [CaseStatuses['in-progress'], CasePersistedStatus.IN_PROGRESS], + [CaseStatuses.closed, CasePersistedStatus.CLOSED], ])('creates a filter for status "%s"', (status, expectedStatus) => { expect(constructQueryOptions({ status }).filter).toMatchInlineSnapshot(` Object { @@ -426,10 +426,10 @@ describe('utils', () => { }); it.each([ - [CaseSeverity.LOW, CaseSeveritySavedObject.LOW], - [CaseSeverity.MEDIUM, CaseSeveritySavedObject.MEDIUM], - [CaseSeverity.HIGH, CaseSeveritySavedObject.HIGH], - [CaseSeverity.CRITICAL, CaseSeveritySavedObject.CRITICAL], + [CaseSeverity.LOW, CasePersistedSeverity.LOW], + [CaseSeverity.MEDIUM, CasePersistedSeverity.MEDIUM], + [CaseSeverity.HIGH, CasePersistedSeverity.HIGH], + [CaseSeverity.CRITICAL, CasePersistedSeverity.CRITICAL], ])('creates a filter for severity "%s"', (severity, expectedSeverity) => { expect(constructQueryOptions({ severity }).filter).toMatchInlineSnapshot(` Object { diff --git a/x-pack/plugins/cases/server/common/constants.ts b/x-pack/plugins/cases/server/common/constants.ts index 0de680a29dc304..69c1f3e619c970 100644 --- a/x-pack/plugins/cases/server/common/constants.ts +++ b/x-pack/plugins/cases/server/common/constants.ts @@ -7,7 +7,7 @@ import { CaseSeverity, CaseStatuses } from '../../common/api'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT } from '../../common/constants'; -import { CaseSeveritySavedObject, CaseStatusSavedObject } from './types/case'; +import { CasePersistedSeverity, CasePersistedStatus } from './types/case'; /** * The name of the saved object reference indicating the action connector ID. This is stored in the Saved Object reference @@ -40,28 +40,28 @@ export const EXTERNAL_REFERENCE_REF_NAME = 'externalReferenceId'; */ export const LICENSING_CASE_ASSIGNMENT_FEATURE = 'Cases user assignment'; -export const SEVERITY_EXTERNAL_TO_ESMODEL: Record = { - [CaseSeverity.LOW]: CaseSeveritySavedObject.LOW, - [CaseSeverity.MEDIUM]: CaseSeveritySavedObject.MEDIUM, - [CaseSeverity.HIGH]: CaseSeveritySavedObject.HIGH, - [CaseSeverity.CRITICAL]: CaseSeveritySavedObject.CRITICAL, +export const SEVERITY_EXTERNAL_TO_ESMODEL: Record = { + [CaseSeverity.LOW]: CasePersistedSeverity.LOW, + [CaseSeverity.MEDIUM]: CasePersistedSeverity.MEDIUM, + [CaseSeverity.HIGH]: CasePersistedSeverity.HIGH, + [CaseSeverity.CRITICAL]: CasePersistedSeverity.CRITICAL, }; -export const SEVERITY_ESMODEL_TO_EXTERNAL: Record = { - [CaseSeveritySavedObject.LOW]: CaseSeverity.LOW, - [CaseSeveritySavedObject.MEDIUM]: CaseSeverity.MEDIUM, - [CaseSeveritySavedObject.HIGH]: CaseSeverity.HIGH, - [CaseSeveritySavedObject.CRITICAL]: CaseSeverity.CRITICAL, +export const SEVERITY_ESMODEL_TO_EXTERNAL: Record = { + [CasePersistedSeverity.LOW]: CaseSeverity.LOW, + [CasePersistedSeverity.MEDIUM]: CaseSeverity.MEDIUM, + [CasePersistedSeverity.HIGH]: CaseSeverity.HIGH, + [CasePersistedSeverity.CRITICAL]: CaseSeverity.CRITICAL, }; -export const STATUS_EXTERNAL_TO_ESMODEL: Record = { - [CaseStatuses.open]: CaseStatusSavedObject.OPEN, - [CaseStatuses['in-progress']]: CaseStatusSavedObject.IN_PROGRESS, - [CaseStatuses.closed]: CaseStatusSavedObject.CLOSED, +export const STATUS_EXTERNAL_TO_ESMODEL: Record = { + [CaseStatuses.open]: CasePersistedStatus.OPEN, + [CaseStatuses['in-progress']]: CasePersistedStatus.IN_PROGRESS, + [CaseStatuses.closed]: CasePersistedStatus.CLOSED, }; -export const STATUS_ESMODEL_TO_EXTERNAL: Record = { - [CaseStatusSavedObject.OPEN]: CaseStatuses.open, - [CaseStatusSavedObject.IN_PROGRESS]: CaseStatuses['in-progress'], - [CaseStatusSavedObject.CLOSED]: CaseStatuses.closed, +export const STATUS_ESMODEL_TO_EXTERNAL: Record = { + [CasePersistedStatus.OPEN]: CaseStatuses.open, + [CasePersistedStatus.IN_PROGRESS]: CaseStatuses['in-progress'], + [CasePersistedStatus.CLOSED]: CaseStatuses.closed, }; diff --git a/x-pack/plugins/cases/server/common/types/case.ts b/x-pack/plugins/cases/server/common/types/case.ts index 4f8e4c5a9ebc7e..a654087b777661 100644 --- a/x-pack/plugins/cases/server/common/types/case.ts +++ b/x-pack/plugins/cases/server/common/types/case.ts @@ -9,20 +9,20 @@ import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { CaseAttributes } from '../../../common/api'; import type { User, UserProfile } from './user'; -export enum CaseSeveritySavedObject { +export enum CasePersistedSeverity { LOW = 0, MEDIUM = 10, HIGH = 20, CRITICAL = 30, } -export enum CaseStatusSavedObject { +export enum CasePersistedStatus { OPEN = 0, IN_PROGRESS = 10, CLOSED = 20, } -export interface CaseExternalServiceSavedObject { +export interface CasePersistedExternalService { connector_name: string; external_id: string; external_title: string; @@ -31,15 +31,15 @@ export interface CaseExternalServiceSavedObject { pushed_by: User; } -export type ConnectorFieldsSavedObject = Array<{ +export type CasePersistedConnectorFields = Array<{ key: string; value: unknown; }>; -export interface ConnectorSavedObject { +export interface CasePersistedConnector { name: string; type: string; - fields: ConnectorFieldsSavedObject | null; + fields: CasePersistedConnectorFields | null; } export interface CasePersistedAttributes { @@ -48,14 +48,14 @@ export interface CasePersistedAttributes { closed_by: User | null; created_at: string; created_by: User; - connector: ConnectorSavedObject; + connector: CasePersistedConnector; description: string; duration: number | null; - external_service: CaseExternalServiceSavedObject | null; + external_service: CasePersistedExternalService | null; owner: string; settings: { syncAlerts: boolean }; - severity: CaseSeveritySavedObject; - status: CaseStatusSavedObject; + severity: CasePersistedSeverity; + status: CasePersistedStatus; tags: string[]; title: string; total_alerts: number; diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/cases.test.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/cases.test.ts index 7638b447ee2faa..bb6c5f1130bda0 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/cases.test.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/cases.test.ts @@ -9,7 +9,7 @@ import type { SavedObjectSanitizedDoc, SavedObjectUnsanitizedDoc } from '@kbn/co import type { CaseAttributes, CaseFullExternalService } from '../../../common/api'; import { CaseSeverity, CaseStatuses, ConnectorTypes, NONE_CONNECTOR_ID } from '../../../common/api'; import { CASE_SAVED_OBJECT } from '../../../common/constants'; -import { CaseSeveritySavedObject, CaseStatusSavedObject } from '../../common/types/case'; +import { CasePersistedSeverity, CasePersistedStatus } from '../../common/types/case'; import { getNoneCaseConnector } from '../../common/utils'; import type { ESCaseConnectorWithId } from '../../services/test_utils'; import { createExternalService } from '../../services/test_utils'; @@ -585,10 +585,10 @@ describe('case migrations', () => { describe('update severity', () => { it.each([ - [CaseSeverity.LOW, CaseSeveritySavedObject.LOW], - [CaseSeverity.MEDIUM, CaseSeveritySavedObject.MEDIUM], - [CaseSeverity.HIGH, CaseSeveritySavedObject.HIGH], - [CaseSeverity.CRITICAL, CaseSeveritySavedObject.CRITICAL], + [CaseSeverity.LOW, CasePersistedSeverity.LOW], + [CaseSeverity.MEDIUM, CasePersistedSeverity.MEDIUM], + [CaseSeverity.HIGH, CasePersistedSeverity.HIGH], + [CaseSeverity.CRITICAL, CasePersistedSeverity.CRITICAL], ])( 'migrates "%s" severity keyword value to matching short', (oldSeverityValue, expectedSeverityValue) => { @@ -624,7 +624,7 @@ describe('case migrations', () => { ...doc, attributes: { ...doc.attributes, - severity: CaseSeveritySavedObject.LOW, + severity: CasePersistedSeverity.LOW, }, references: [], }); @@ -633,9 +633,9 @@ describe('case migrations', () => { describe('update status', () => { it.each([ - [CaseStatuses.open, CaseStatusSavedObject.OPEN], - [CaseStatuses['in-progress'], CaseStatusSavedObject.IN_PROGRESS], - [CaseStatuses.closed, CaseStatusSavedObject.CLOSED], + [CaseStatuses.open, CasePersistedStatus.OPEN], + [CaseStatuses['in-progress'], CasePersistedStatus.IN_PROGRESS], + [CaseStatuses.closed, CasePersistedStatus.CLOSED], ])( 'migrates "%s" status keyword value to matching short', (oldStatusValue, expectedStatusValue) => { @@ -671,7 +671,7 @@ describe('case migrations', () => { ...doc, attributes: { ...doc.attributes, - status: CaseStatusSavedObject.OPEN, + status: CasePersistedStatus.OPEN, }, references: [], }); diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/cases.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/cases.ts index 37f204371ba834..4154a20c2f0046 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/cases.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/cases.ts @@ -26,8 +26,8 @@ import { } from './user_actions/connector_id'; import { CASE_TYPE_INDIVIDUAL } from './constants'; import { pipeMigrations } from './utils'; -import type { ConnectorFieldsSavedObject } from '../../common/types/case'; -import { CaseSeveritySavedObject, CaseStatusSavedObject } from '../../common/types/case'; +import type { CasePersistedConnectorFields } from '../../common/types/case'; +import { CasePersistedSeverity, CasePersistedStatus } from '../../common/types/case'; interface UnsanitizedCaseConnector { connector_id: string; @@ -38,7 +38,7 @@ interface SanitizedCaseConnector { id: string; name: string | null; type: string | null; - fields: null | ConnectorFieldsSavedObject; + fields: null | CasePersistedConnectorFields; }; } @@ -138,10 +138,10 @@ export const addAssignees = ( export const convertSeverity = ( doc: SavedObjectUnsanitizedDoc ): SavedObjectSanitizedDoc< - Omit & { severity: CaseSeveritySavedObject } + Omit & { severity: CasePersistedSeverity } > => { const severity = - SEVERITY_EXTERNAL_TO_ESMODEL[doc.attributes.severity] ?? CaseSeveritySavedObject.LOW; + SEVERITY_EXTERNAL_TO_ESMODEL[doc.attributes.severity] ?? CasePersistedSeverity.LOW; return { ...doc, attributes: { ...doc.attributes, severity }, @@ -151,8 +151,8 @@ export const convertSeverity = ( export const convertStatus = ( doc: SavedObjectUnsanitizedDoc -): SavedObjectSanitizedDoc & { status: CaseStatusSavedObject }> => { - const status = STATUS_EXTERNAL_TO_ESMODEL[doc.attributes?.status] ?? CaseStatusSavedObject.OPEN; +): SavedObjectSanitizedDoc & { status: CasePersistedStatus }> => { + const status = STATUS_EXTERNAL_TO_ESMODEL[doc.attributes?.status] ?? CasePersistedStatus.OPEN; return { ...doc, attributes: { ...doc.attributes, status }, diff --git a/x-pack/plugins/cases/server/services/cases/index.test.ts b/x-pack/plugins/cases/server/services/cases/index.test.ts index a4576213e434b6..c0039529ffc916 100644 --- a/x-pack/plugins/cases/server/services/cases/index.test.ts +++ b/x-pack/plugins/cases/server/services/cases/index.test.ts @@ -44,7 +44,7 @@ import { import { AttachmentService } from '../attachments'; import { PersistableStateAttachmentTypeRegistry } from '../../attachment_framework/persistable_state_registry'; import type { CaseSavedObjectTransformed, CasePersistedAttributes } from '../../common/types/case'; -import { CaseSeveritySavedObject, CaseStatusSavedObject } from '../../common/types/case'; +import { CasePersistedSeverity, CasePersistedStatus } from '../../common/types/case'; const createUpdateSOResponse = ({ connector, @@ -54,8 +54,8 @@ const createUpdateSOResponse = ({ }: { connector?: ESCaseConnectorWithId; externalService?: CaseFullExternalService; - severity?: CaseSeveritySavedObject; - status?: CaseStatusSavedObject; + severity?: CasePersistedSeverity; + status?: CasePersistedStatus; } = {}): SavedObjectsUpdateResponse => { const references: SavedObjectReference[] = createSavedObjectReferences({ connector, @@ -502,10 +502,10 @@ describe('CasesService', () => { }); it.each([ - [CaseSeverity.LOW, CaseSeveritySavedObject.LOW], - [CaseSeverity.MEDIUM, CaseSeveritySavedObject.MEDIUM], - [CaseSeverity.HIGH, CaseSeveritySavedObject.HIGH], - [CaseSeverity.CRITICAL, CaseSeveritySavedObject.CRITICAL], + [CaseSeverity.LOW, CasePersistedSeverity.LOW], + [CaseSeverity.MEDIUM, CasePersistedSeverity.MEDIUM], + [CaseSeverity.HIGH, CasePersistedSeverity.HIGH], + [CaseSeverity.CRITICAL, CasePersistedSeverity.CRITICAL], ])( 'properly converts "%s" severity to corresponding ES value on updating SO', async (patchParamsSeverity, expectedSeverity) => { @@ -527,9 +527,9 @@ describe('CasesService', () => { ); it.each([ - [CaseStatuses.open, CaseStatusSavedObject.OPEN], - [CaseStatuses['in-progress'], CaseStatusSavedObject.IN_PROGRESS], - [CaseStatuses.closed, CaseStatusSavedObject.CLOSED], + [CaseStatuses.open, CasePersistedStatus.OPEN], + [CaseStatuses['in-progress'], CasePersistedStatus.IN_PROGRESS], + [CaseStatuses.closed, CasePersistedStatus.CLOSED], ])( 'properly converts "%s" status to corresponding ES value on updating SO', async (patchParamsStatus, expectedStatus) => { @@ -602,10 +602,10 @@ describe('CasesService', () => { const patchResults = unsecuredSavedObjectsClient.bulkUpdate.mock .calls[0][0] as unknown as Array>; - expect(patchResults[0].attributes.severity).toEqual(CaseSeveritySavedObject.LOW); - expect(patchResults[1].attributes.severity).toEqual(CaseSeveritySavedObject.MEDIUM); - expect(patchResults[2].attributes.severity).toEqual(CaseSeveritySavedObject.HIGH); - expect(patchResults[3].attributes.severity).toEqual(CaseSeveritySavedObject.CRITICAL); + expect(patchResults[0].attributes.severity).toEqual(CasePersistedSeverity.LOW); + expect(patchResults[1].attributes.severity).toEqual(CasePersistedSeverity.MEDIUM); + expect(patchResults[2].attributes.severity).toEqual(CasePersistedSeverity.HIGH); + expect(patchResults[3].attributes.severity).toEqual(CasePersistedSeverity.CRITICAL); }); it('properly converts status to corresponding ES value on bulk updating SO', async () => { @@ -649,9 +649,9 @@ describe('CasesService', () => { const patchResults = unsecuredSavedObjectsClient.bulkUpdate.mock .calls[0][0] as unknown as Array>; - expect(patchResults[0].attributes.status).toEqual(CaseStatusSavedObject.OPEN); - expect(patchResults[1].attributes.status).toEqual(CaseStatusSavedObject.IN_PROGRESS); - expect(patchResults[2].attributes.status).toEqual(CaseStatusSavedObject.CLOSED); + expect(patchResults[0].attributes.status).toEqual(CasePersistedStatus.OPEN); + expect(patchResults[1].attributes.status).toEqual(CasePersistedStatus.IN_PROGRESS); + expect(patchResults[2].attributes.status).toEqual(CasePersistedStatus.CLOSED); }); }); @@ -870,10 +870,10 @@ describe('CasesService', () => { }); it.each([ - [CaseSeverity.LOW, CaseSeveritySavedObject.LOW], - [CaseSeverity.MEDIUM, CaseSeveritySavedObject.MEDIUM], - [CaseSeverity.HIGH, CaseSeveritySavedObject.HIGH], - [CaseSeverity.CRITICAL, CaseSeveritySavedObject.CRITICAL], + [CaseSeverity.LOW, CasePersistedSeverity.LOW], + [CaseSeverity.MEDIUM, CasePersistedSeverity.MEDIUM], + [CaseSeverity.HIGH, CasePersistedSeverity.HIGH], + [CaseSeverity.CRITICAL, CasePersistedSeverity.CRITICAL], ])( 'properly converts "%s" severity to corresponding ES value on creating SO', async (postParamsSeverity, expectedSeverity) => { @@ -896,9 +896,9 @@ describe('CasesService', () => { ); it.each([ - [CaseStatuses.open, CaseStatusSavedObject.OPEN], - [CaseStatuses['in-progress'], CaseStatusSavedObject.IN_PROGRESS], - [CaseStatuses.closed, CaseStatusSavedObject.CLOSED], + [CaseStatuses.open, CasePersistedStatus.OPEN], + [CaseStatuses['in-progress'], CasePersistedStatus.IN_PROGRESS], + [CaseStatuses.closed, CasePersistedStatus.CLOSED], ])( 'properly converts "%s" status to corresponding ES value on creating SO', async (postParamsStatus, expectedStatus) => { @@ -987,15 +987,15 @@ describe('CasesService', () => { it('properly converts the severity field to the corresponding external value in the bulkPatch response', async () => { unsecuredSavedObjectsClient.bulkUpdate.mockResolvedValue({ saved_objects: [ - createCaseSavedObjectResponse({ overrides: { severity: CaseSeveritySavedObject.LOW } }), + createCaseSavedObjectResponse({ overrides: { severity: CasePersistedSeverity.LOW } }), createCaseSavedObjectResponse({ - overrides: { severity: CaseSeveritySavedObject.MEDIUM }, + overrides: { severity: CasePersistedSeverity.MEDIUM }, }), createCaseSavedObjectResponse({ - overrides: { severity: CaseSeveritySavedObject.HIGH }, + overrides: { severity: CasePersistedSeverity.HIGH }, }), createCaseSavedObjectResponse({ - overrides: { severity: CaseSeveritySavedObject.CRITICAL }, + overrides: { severity: CasePersistedSeverity.CRITICAL }, }), ], }); @@ -1018,11 +1018,11 @@ describe('CasesService', () => { it('properly converts the status field to the corresponding external value in the bulkPatch response', async () => { unsecuredSavedObjectsClient.bulkUpdate.mockResolvedValue({ saved_objects: [ - createCaseSavedObjectResponse({ overrides: { status: CaseStatusSavedObject.OPEN } }), + createCaseSavedObjectResponse({ overrides: { status: CasePersistedStatus.OPEN } }), createCaseSavedObjectResponse({ - overrides: { status: CaseStatusSavedObject.IN_PROGRESS }, + overrides: { status: CasePersistedStatus.IN_PROGRESS }, }), - createCaseSavedObjectResponse({ overrides: { status: CaseStatusSavedObject.CLOSED } }), + createCaseSavedObjectResponse({ overrides: { status: CasePersistedStatus.CLOSED } }), ], }); @@ -1301,10 +1301,10 @@ describe('CasesService', () => { }); it.each([ - [CaseSeveritySavedObject.LOW, CaseSeverity.LOW], - [CaseSeveritySavedObject.MEDIUM, CaseSeverity.MEDIUM], - [CaseSeveritySavedObject.HIGH, CaseSeverity.HIGH], - [CaseSeveritySavedObject.CRITICAL, CaseSeverity.CRITICAL], + [CasePersistedSeverity.LOW, CaseSeverity.LOW], + [CasePersistedSeverity.MEDIUM, CaseSeverity.MEDIUM], + [CasePersistedSeverity.HIGH, CaseSeverity.HIGH], + [CasePersistedSeverity.CRITICAL, CaseSeverity.CRITICAL], ])( 'properly converts "%s" severity to corresponding external value in the patch response', async (internalSeverityValue, expectedSeverity) => { @@ -1323,9 +1323,9 @@ describe('CasesService', () => { ); it.each([ - [CaseStatusSavedObject.OPEN, CaseStatuses.open], - [CaseStatusSavedObject.IN_PROGRESS, CaseStatuses['in-progress']], - [CaseStatusSavedObject.CLOSED, CaseStatuses.closed], + [CasePersistedStatus.OPEN, CaseStatuses.open], + [CasePersistedStatus.IN_PROGRESS, CaseStatuses['in-progress']], + [CasePersistedStatus.CLOSED, CaseStatuses.closed], ])( 'properly converts "%s" status to corresponding external value in the patch response', async (internalStatusValue, expectedStatus) => { @@ -1376,10 +1376,10 @@ describe('CasesService', () => { }); it.each([ - [CaseSeveritySavedObject.LOW, CaseSeverity.LOW], - [CaseSeveritySavedObject.MEDIUM, CaseSeverity.MEDIUM], - [CaseSeveritySavedObject.HIGH, CaseSeverity.HIGH], - [CaseSeveritySavedObject.CRITICAL, CaseSeverity.CRITICAL], + [CasePersistedSeverity.LOW, CaseSeverity.LOW], + [CasePersistedSeverity.MEDIUM, CaseSeverity.MEDIUM], + [CasePersistedSeverity.HIGH, CaseSeverity.HIGH], + [CasePersistedSeverity.CRITICAL, CaseSeverity.CRITICAL], ])( 'properly converts "%s" severity to corresponding external value in the post response', async (internalSeverityValue, expectedSeverity) => { @@ -1397,9 +1397,9 @@ describe('CasesService', () => { ); it.each([ - [CaseStatusSavedObject.OPEN, CaseStatuses.open], - [CaseStatusSavedObject.IN_PROGRESS, CaseStatuses['in-progress']], - [CaseStatusSavedObject.CLOSED, CaseStatuses.closed], + [CasePersistedStatus.OPEN, CaseStatuses.open], + [CasePersistedStatus.IN_PROGRESS, CaseStatuses['in-progress']], + [CasePersistedStatus.CLOSED, CaseStatuses.closed], ])( 'properly converts "%s" status to corresponding external value in the post response', async (internalStatusValue, expectedStatus) => { @@ -1469,10 +1469,10 @@ describe('CasesService', () => { }); it.each([ - [CaseSeveritySavedObject.LOW, CaseSeverity.LOW], - [CaseSeveritySavedObject.MEDIUM, CaseSeverity.MEDIUM], - [CaseSeveritySavedObject.HIGH, CaseSeverity.HIGH], - [CaseSeveritySavedObject.CRITICAL, CaseSeverity.CRITICAL], + [CasePersistedSeverity.LOW, CaseSeverity.LOW], + [CasePersistedSeverity.MEDIUM, CaseSeverity.MEDIUM], + [CasePersistedSeverity.HIGH, CaseSeverity.HIGH], + [CasePersistedSeverity.CRITICAL, CaseSeverity.CRITICAL], ])( 'includes the properly converted "%s" severity field in the result', async (severity, expectedSeverity) => { @@ -1488,9 +1488,9 @@ describe('CasesService', () => { ); it.each([ - [CaseStatusSavedObject.OPEN, CaseStatuses.open], - [CaseStatusSavedObject.IN_PROGRESS, CaseStatuses['in-progress']], - [CaseStatusSavedObject.CLOSED, CaseStatuses.closed], + [CasePersistedStatus.OPEN, CaseStatuses.open], + [CasePersistedStatus.IN_PROGRESS, CaseStatuses['in-progress']], + [CasePersistedStatus.CLOSED, CaseStatuses.closed], ])( 'includes the properly converted "%s" status field in the result', async (status, expectedStatus) => { @@ -1548,16 +1548,16 @@ describe('CasesService', () => { unsecuredSavedObjectsClient.bulkGet.mockResolvedValue({ saved_objects: [ createCaseSavedObjectResponse({ - overrides: { severity: CaseSeveritySavedObject.LOW }, + overrides: { severity: CasePersistedSeverity.LOW }, }), createCaseSavedObjectResponse({ - overrides: { severity: CaseSeveritySavedObject.MEDIUM }, + overrides: { severity: CasePersistedSeverity.MEDIUM }, }), createCaseSavedObjectResponse({ - overrides: { severity: CaseSeveritySavedObject.HIGH }, + overrides: { severity: CasePersistedSeverity.HIGH }, }), createCaseSavedObjectResponse({ - overrides: { severity: CaseSeveritySavedObject.CRITICAL }, + overrides: { severity: CasePersistedSeverity.CRITICAL }, }), ], }); @@ -1573,13 +1573,13 @@ describe('CasesService', () => { unsecuredSavedObjectsClient.bulkGet.mockResolvedValue({ saved_objects: [ createCaseSavedObjectResponse({ - overrides: { status: CaseStatusSavedObject.OPEN }, + overrides: { status: CasePersistedStatus.OPEN }, }), createCaseSavedObjectResponse({ - overrides: { status: CaseStatusSavedObject.IN_PROGRESS }, + overrides: { status: CasePersistedStatus.IN_PROGRESS }, }), createCaseSavedObjectResponse({ - overrides: { status: CaseStatusSavedObject.CLOSED }, + overrides: { status: CasePersistedStatus.CLOSED }, }), ], }); @@ -1711,10 +1711,10 @@ describe('CasesService', () => { }); it.each([ - [CaseSeveritySavedObject.LOW, CaseSeverity.LOW], - [CaseSeveritySavedObject.MEDIUM, CaseSeverity.MEDIUM], - [CaseSeveritySavedObject.HIGH, CaseSeverity.HIGH], - [CaseSeveritySavedObject.CRITICAL, CaseSeverity.CRITICAL], + [CasePersistedSeverity.LOW, CaseSeverity.LOW], + [CasePersistedSeverity.MEDIUM, CaseSeverity.MEDIUM], + [CasePersistedSeverity.HIGH, CaseSeverity.HIGH], + [CasePersistedSeverity.CRITICAL, CaseSeverity.CRITICAL], ])( 'includes the properly converted "%s" severity field in the result', async (internalSeverityValue, expectedSeverity) => { @@ -1729,9 +1729,9 @@ describe('CasesService', () => { ); it.each([ - [CaseStatusSavedObject.OPEN, CaseStatuses.open], - [CaseStatusSavedObject.IN_PROGRESS, CaseStatuses['in-progress']], - [CaseStatusSavedObject.CLOSED, CaseStatuses.closed], + [CasePersistedStatus.OPEN, CaseStatuses.open], + [CasePersistedStatus.IN_PROGRESS, CaseStatuses['in-progress']], + [CasePersistedStatus.CLOSED, CaseStatuses.closed], ])( 'includes the properly converted "%s" status field in the result', async (internalStatusValue, expectedStatus) => { diff --git a/x-pack/plugins/cases/server/services/cases/index.ts b/x-pack/plugins/cases/server/services/cases/index.ts index b4abc7dc234864..8ff9828343cb52 100644 --- a/x-pack/plugins/cases/server/services/cases/index.ts +++ b/x-pack/plugins/cases/server/services/cases/index.ts @@ -50,7 +50,7 @@ import type { CaseSavedObjectTransformed, CaseTransformedAttributes, } from '../../common/types/case'; -import { CaseStatusSavedObject } from '../../common/types/case'; +import { CasePersistedStatus } from '../../common/types/case'; import type { GetCaseIdsByAlertIdArgs, GetCaseIdsByAlertIdAggs, @@ -220,9 +220,9 @@ export class CasesService { const statusBuckets = CasesService.getStatusBuckets(cases.aggregations?.statuses.buckets); return { - open: statusBuckets?.get(CaseStatusSavedObject.OPEN) ?? 0, - 'in-progress': statusBuckets?.get(CaseStatusSavedObject.IN_PROGRESS) ?? 0, - closed: statusBuckets?.get(CaseStatusSavedObject.CLOSED) ?? 0, + open: statusBuckets?.get(CasePersistedStatus.OPEN) ?? 0, + 'in-progress': statusBuckets?.get(CasePersistedStatus.IN_PROGRESS) ?? 0, + closed: statusBuckets?.get(CasePersistedStatus.CLOSED) ?? 0, }; } diff --git a/x-pack/plugins/cases/server/services/cases/transform.test.ts b/x-pack/plugins/cases/server/services/cases/transform.test.ts index 1dee24a3a4b832..1ba613e8c6d1ef 100644 --- a/x-pack/plugins/cases/server/services/cases/transform.test.ts +++ b/x-pack/plugins/cases/server/services/cases/transform.test.ts @@ -23,7 +23,7 @@ import { PUSH_CONNECTOR_ID_REFERENCE_NAME, } from '../../common/constants'; import { getNoneCaseConnector } from '../../common/utils'; -import { CaseSeveritySavedObject, CaseStatusSavedObject } from '../../common/types/case'; +import { CasePersistedSeverity, CasePersistedStatus } from '../../common/types/case'; describe('case transforms', () => { describe('transformUpdateResponseToExternalModel', () => { @@ -200,10 +200,10 @@ describe('case transforms', () => { }); it.each([ - [CaseSeveritySavedObject.LOW, CaseSeverity.LOW], - [CaseSeveritySavedObject.MEDIUM, CaseSeverity.MEDIUM], - [CaseSeveritySavedObject.HIGH, CaseSeverity.HIGH], - [CaseSeveritySavedObject.CRITICAL, CaseSeverity.CRITICAL], + [CasePersistedSeverity.LOW, CaseSeverity.LOW], + [CasePersistedSeverity.MEDIUM, CaseSeverity.MEDIUM], + [CasePersistedSeverity.HIGH, CaseSeverity.HIGH], + [CasePersistedSeverity.CRITICAL, CaseSeverity.CRITICAL], ])( 'properly converts "%s" severity to corresponding external value "%s"', (internalSeverityValue, expectedSeverityValue) => { @@ -222,9 +222,9 @@ describe('case transforms', () => { ); it.each([ - [CaseStatusSavedObject.OPEN, CaseStatuses.open], - [CaseStatusSavedObject.IN_PROGRESS, CaseStatuses['in-progress']], - [CaseStatusSavedObject.CLOSED, CaseStatuses.closed], + [CasePersistedStatus.OPEN, CaseStatuses.open], + [CasePersistedStatus.IN_PROGRESS, CaseStatuses['in-progress']], + [CasePersistedStatus.CLOSED, CaseStatuses.closed], ])( 'properly converts "%s" status to corresponding ES Value "%s"', (internalStatusValue, expectedStatusValue) => { @@ -387,10 +387,10 @@ describe('case transforms', () => { }); it.each([ - [CaseSeverity.LOW, CaseSeveritySavedObject.LOW], - [CaseSeverity.MEDIUM, CaseSeveritySavedObject.MEDIUM], - [CaseSeverity.HIGH, CaseSeveritySavedObject.HIGH], - [CaseSeverity.CRITICAL, CaseSeveritySavedObject.CRITICAL], + [CaseSeverity.LOW, CasePersistedSeverity.LOW], + [CaseSeverity.MEDIUM, CasePersistedSeverity.MEDIUM], + [CaseSeverity.HIGH, CasePersistedSeverity.HIGH], + [CaseSeverity.CRITICAL, CasePersistedSeverity.CRITICAL], ])( 'properly converts "%s" severity to corresponding ES Value "%s"', (externalSeverityValue, expectedSeverityValue) => { @@ -410,9 +410,9 @@ describe('case transforms', () => { }); it.each([ - [CaseStatuses.open, CaseStatusSavedObject.OPEN], - [CaseStatuses['in-progress'], CaseStatusSavedObject.IN_PROGRESS], - [CaseStatuses.closed, CaseStatusSavedObject.CLOSED], + [CaseStatuses.open, CasePersistedStatus.OPEN], + [CaseStatuses['in-progress'], CasePersistedStatus.IN_PROGRESS], + [CaseStatuses.closed, CasePersistedStatus.CLOSED], ])( 'properly converts "%s" status to corresponding ES Value "%s"', (externalStatusValue, expectedStatusValue) => { @@ -501,10 +501,10 @@ describe('case transforms', () => { }); it.each([ - [CaseSeveritySavedObject.LOW, CaseSeverity.LOW], - [CaseSeveritySavedObject.MEDIUM, CaseSeverity.MEDIUM], - [CaseSeveritySavedObject.HIGH, CaseSeverity.HIGH], - [CaseSeveritySavedObject.CRITICAL, CaseSeverity.CRITICAL], + [CasePersistedSeverity.LOW, CaseSeverity.LOW], + [CasePersistedSeverity.MEDIUM, CaseSeverity.MEDIUM], + [CasePersistedSeverity.HIGH, CaseSeverity.HIGH], + [CasePersistedSeverity.CRITICAL, CaseSeverity.CRITICAL], ])( 'properly converts "%s" severity to corresponding external value "%s"', (internalSeverityValue, expectedSeverityValue) => { @@ -529,9 +529,9 @@ describe('case transforms', () => { }); it.each([ - [CaseStatusSavedObject.OPEN, CaseStatuses.open], - [CaseStatusSavedObject.IN_PROGRESS, CaseStatuses['in-progress']], - [CaseStatusSavedObject.CLOSED, CaseStatuses.closed], + [CasePersistedStatus.OPEN, CaseStatuses.open], + [CasePersistedStatus.IN_PROGRESS, CaseStatuses['in-progress']], + [CasePersistedStatus.CLOSED, CaseStatuses.closed], ])( 'properly converts "%s" status to corresponding external value "%s"', (internalStatusValue, expectedStatusValue) => { diff --git a/x-pack/plugins/cases/server/services/cases/transform.ts b/x-pack/plugins/cases/server/services/cases/transform.ts index 89ab6520d21f7b..aaefaf74d52f54 100644 --- a/x-pack/plugins/cases/server/services/cases/transform.ts +++ b/x-pack/plugins/cases/server/services/cases/transform.ts @@ -34,7 +34,7 @@ import { } from '../transform'; import { ConnectorReferenceHandler } from '../connector_reference_handler'; import type { - CaseExternalServiceSavedObject, + CasePersistedExternalService, CasePersistedAttributes, CaseTransformedAttributes, } from '../../common/types/case'; @@ -229,7 +229,7 @@ export function transformSavedObjectToExternalModel( function transformESExternalService( // this type needs to match that of CaseFullExternalService except that it does not include the connector_id, see: x-pack/plugins/cases/common/api/cases/case.ts // that's why it can be null here - externalService: CaseExternalServiceSavedObject | null | undefined, + externalService: CasePersistedExternalService | null | undefined, references: SavedObjectReference[] | undefined ): CaseFullExternalService | null { const connectorIdRef = findConnectorIdReference(PUSH_CONNECTOR_ID_REFERENCE_NAME, references); diff --git a/x-pack/plugins/cases/server/services/configure/types.ts b/x-pack/plugins/cases/server/services/configure/types.ts index 853497d58aaf36..68af51062fadf0 100644 --- a/x-pack/plugins/cases/server/services/configure/types.ts +++ b/x-pack/plugins/cases/server/services/configure/types.ts @@ -6,12 +6,12 @@ */ import type { CasesConfigureAttributes } from '../../../common/api'; -import type { ConnectorSavedObject } from '../../common/types/case'; +import type { CasePersistedConnector } from '../../common/types/case'; /** * This type should only be used within the configure service. It represents how the configure saved object will be layed * out in ES. */ export type ESCasesConfigureAttributes = Omit & { - connector: ConnectorSavedObject; + connector: CasePersistedConnector; }; diff --git a/x-pack/plugins/cases/server/services/test_utils.ts b/x-pack/plugins/cases/server/services/test_utils.ts index 2ea9d7bfdfb76c..83b37f3f6c2975 100644 --- a/x-pack/plugins/cases/server/services/test_utils.ts +++ b/x-pack/plugins/cases/server/services/test_utils.ts @@ -18,11 +18,11 @@ import { CaseSeverity, CaseStatuses, ConnectorTypes, NONE_CONNECTOR_ID } from '. import { CASE_SAVED_OBJECT, SECURITY_SOLUTION_OWNER } from '../../common/constants'; import { getNoneCaseConnector } from '../common/utils'; import type { - CaseExternalServiceSavedObject, + CasePersistedExternalService, CasePersistedAttributes, - ConnectorFieldsSavedObject, + CasePersistedConnectorFields, } from '../common/types/case'; -import { CaseSeveritySavedObject, CaseStatusSavedObject } from '../common/types/case'; +import { CasePersistedSeverity, CasePersistedStatus } from '../common/types/case'; /** * This is only a utility interface to help with constructing test cases. After the migration, the ES format will no longer @@ -32,7 +32,7 @@ export interface ESCaseConnectorWithId { id: string; name: string; type: ConnectorTypes; - fields: ConnectorFieldsSavedObject | null; + fields: CasePersistedConnectorFields | null; } /** @@ -109,11 +109,11 @@ export const basicESCaseFields: CasePersistedAttributes = { email: 'testemail@elastic.co', username: 'elastic', }, - severity: CaseSeveritySavedObject.LOW, + severity: CasePersistedSeverity.LOW, duration: null, description: 'This is a brand new case of a bad meanie defacing data', title: 'Super Bad Security Issue', - status: CaseStatusSavedObject.OPEN, + status: CasePersistedStatus.OPEN, tags: ['defacement'], updated_at: '2019-11-25T21:54:48.952Z', updated_by: { @@ -184,7 +184,7 @@ export const createCaseSavedObjectResponse = ({ fields: connector?.fields ?? null, }; - let restExternalService: CaseExternalServiceSavedObject | null = null; + let restExternalService: CasePersistedExternalService | null = null; if (externalService !== null) { const { connector_id: ignored, ...rest } = externalService ?? { connector_name: '.jira', diff --git a/x-pack/plugins/cases/server/services/transform.ts b/x-pack/plugins/cases/server/services/transform.ts index 78efd705cc29a6..46e390f75689b5 100644 --- a/x-pack/plugins/cases/server/services/transform.ts +++ b/x-pack/plugins/cases/server/services/transform.ts @@ -9,7 +9,7 @@ import type { SavedObjectReference } from '@kbn/core/server'; import { ACTION_SAVED_OBJECT_TYPE } from '@kbn/actions-plugin/server'; import type { CaseConnector, ConnectorTypeFields } from '../../common/api'; import { getNoneCaseConnector } from '../common/utils'; -import type { ConnectorSavedObject, ConnectorFieldsSavedObject } from '../common/types/case'; +import type { CasePersistedConnector, CasePersistedConnectorFields } from '../common/types/case'; export function findConnectorIdReference( name: string, @@ -23,7 +23,7 @@ export function transformESConnectorToExternalModel({ references, referenceName, }: { - connector?: ConnectorSavedObject; + connector?: CasePersistedConnector; references?: SavedObjectReference[]; referenceName: string; }): CaseConnector | undefined { @@ -32,7 +32,7 @@ export function transformESConnectorToExternalModel({ } function transformConnectorFieldsToExternalModel( - connector?: ConnectorSavedObject, + connector?: CasePersistedConnector, connectorId?: string ): CaseConnector | undefined { if (!connector) { @@ -72,7 +72,7 @@ export function transformESConnectorOrUseDefault({ references, referenceName, }: { - connector?: ConnectorSavedObject; + connector?: CasePersistedConnector; references?: SavedObjectReference[]; referenceName: string; }): CaseConnector { @@ -82,12 +82,12 @@ export function transformESConnectorOrUseDefault({ ); } -export function transformFieldsToESModel(connector: CaseConnector): ConnectorFieldsSavedObject { +export function transformFieldsToESModel(connector: CaseConnector): CasePersistedConnectorFields { if (!connector.fields) { return []; } - return Object.entries(connector.fields).reduce( + return Object.entries(connector.fields).reduce( (acc, [key, value]) => [ ...acc, { diff --git a/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts b/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts index 88ee4e7afe30f7..560997e8802be2 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/cases.test.ts @@ -7,7 +7,7 @@ import type { SavedObjectsFindResponse } from '@kbn/core/server'; import { savedObjectsRepositoryMock, loggingSystemMock } from '@kbn/core/server/mocks'; -import { CaseStatusSavedObject } from '../../common/types/case'; +import { CasePersistedStatus } from '../../common/types/case'; import type { AttachmentAggregationResult, AttachmentFrameworkAggsResult, @@ -99,7 +99,7 @@ describe('getCasesTelemetryData', () => { status: { buckets: [ { - key: CaseStatusSavedObject.OPEN, + key: CasePersistedStatus.OPEN, doc_count: 2, }, ], diff --git a/x-pack/plugins/cases/server/telemetry/queries/cases.ts b/x-pack/plugins/cases/server/telemetry/queries/cases.ts index 2b7699b9764176..abd1979d752e8b 100644 --- a/x-pack/plugins/cases/server/telemetry/queries/cases.ts +++ b/x-pack/plugins/cases/server/telemetry/queries/cases.ts @@ -36,7 +36,7 @@ import { getSolutionValues, } from './utils'; import type { CasePersistedAttributes } from '../../common/types/case'; -import { CaseStatusSavedObject } from '../../common/types/case'; +import { CasePersistedStatus } from '../../common/types/case'; export const getLatestCasesDates = async ({ savedObjectsClient, @@ -94,12 +94,12 @@ export const getCasesTelemetryData = async ({ total: casesRes.total, ...getCountsFromBuckets(aggregationsBuckets.counts), status: { - open: findValueInBuckets(aggregationsBuckets.status, CaseStatusSavedObject.OPEN), + open: findValueInBuckets(aggregationsBuckets.status, CasePersistedStatus.OPEN), inProgress: findValueInBuckets( aggregationsBuckets.status, - CaseStatusSavedObject.IN_PROGRESS + CasePersistedStatus.IN_PROGRESS ), - closed: findValueInBuckets(aggregationsBuckets.status, CaseStatusSavedObject.CLOSED), + closed: findValueInBuckets(aggregationsBuckets.status, CasePersistedStatus.CLOSED), }, syncAlertsOn: findValueInBuckets(aggregationsBuckets.syncAlerts, 1), syncAlertsOff: findValueInBuckets(aggregationsBuckets.syncAlerts, 0), diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/import_export.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/import_export.ts index e6d3a816e3275b..b030b0ea5db4d9 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/import_export.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/import_export.ts @@ -29,8 +29,8 @@ import { CaseUserActionAttributesWithoutConnectorId, } from '@kbn/cases-plugin/common/api'; import { - CaseSeveritySavedObject, - CaseStatusSavedObject, + CasePersistedSeverity, + CasePersistedStatus, } from '@kbn/cases-plugin/server/common/types/case'; import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib'; import { @@ -214,8 +214,8 @@ const expectExportToHaveCaseSavedObject = ( expect(createdCaseSO.attributes.connector.name).to.eql(caseRequest.connector.name); expect(createdCaseSO.attributes.connector.fields).to.eql([]); expect(createdCaseSO.attributes.settings).to.eql(caseRequest.settings); - expect(createdCaseSO.attributes.status).to.eql(CaseStatusSavedObject.OPEN); - expect(createdCaseSO.attributes.severity).to.eql(CaseSeveritySavedObject.LOW); + expect(createdCaseSO.attributes.status).to.eql(CasePersistedStatus.OPEN); + expect(createdCaseSO.attributes.severity).to.eql(CasePersistedSeverity.LOW); expect(createdCaseSO.attributes.duration).to.eql(null); expect(createdCaseSO.attributes.tags).to.eql(caseRequest.tags); }; diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/migrations.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/migrations.ts index ed42462d8f2529..f908e90c58afb2 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/migrations.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/migrations.ts @@ -9,8 +9,8 @@ import expect from '@kbn/expect'; import { CASES_URL, SECURITY_SOLUTION_OWNER } from '@kbn/cases-plugin/common/constants'; import { AttributesTypeUser } from '@kbn/cases-plugin/common/api'; import { - CaseSeveritySavedObject, - CaseStatusSavedObject, + CasePersistedSeverity, + CasePersistedStatus, } from '@kbn/cases-plugin/server/common/types/case'; import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; import { @@ -502,11 +502,11 @@ export default function createGetTests({ getService }: FtrProviderContext) { describe('severity', () => { it('severity keyword values are converted to matching short', async () => { - const expectedSeverityValues: Record = { - 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf6': CaseSeveritySavedObject.LOW, - 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf7': CaseSeveritySavedObject.MEDIUM, - 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf8': CaseSeveritySavedObject.HIGH, - 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf9': CaseSeveritySavedObject.CRITICAL, + const expectedSeverityValues: Record = { + 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf6': CasePersistedSeverity.LOW, + 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf7': CasePersistedSeverity.MEDIUM, + 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf8': CasePersistedSeverity.HIGH, + 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf9': CasePersistedSeverity.CRITICAL, }; const casesFromES = await getCaseSavedObjectsFromES({ es }); @@ -521,11 +521,11 @@ export default function createGetTests({ getService }: FtrProviderContext) { describe('status', () => { it('status keyword values are converted to matching short', async () => { - const expectedStatusValues: Record = { - 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf6': CaseStatusSavedObject.OPEN, - 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf7': CaseStatusSavedObject.OPEN, - 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf8': CaseStatusSavedObject.IN_PROGRESS, - 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf9': CaseStatusSavedObject.CLOSED, + const expectedStatusValues: Record = { + 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf6': CasePersistedStatus.OPEN, + 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf7': CasePersistedStatus.OPEN, + 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf8': CasePersistedStatus.IN_PROGRESS, + 'cases:063d5820-1284-11ed-81af-63a2bdfb2bf9': CasePersistedStatus.CLOSED, }; const casesFromES = await getCaseSavedObjectsFromES({ es });