diff --git a/x-pack/plugins/case/server/saved_object_types/migrations.ts b/x-pack/plugins/case/server/saved_object_types/migrations.ts index 117e2eaeea4d8..bf9694d7e6bb0 100644 --- a/x-pack/plugins/case/server/saved_object_types/migrations.ts +++ b/x-pack/plugins/case/server/saved_object_types/migrations.ts @@ -8,7 +8,13 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { SavedObjectUnsanitizedDoc, SavedObjectSanitizedDoc } from '../../../../../src/core/server'; -import { ConnectorTypes, CommentType, CaseType, AssociationType } from '../../common/api'; +import { + ConnectorTypes, + CommentType, + CaseType, + AssociationType, + ESConnectorFields, +} from '../../common/api'; interface UnsanitizedCaseConnector { connector_id: string; @@ -24,7 +30,7 @@ interface SanitizedCaseConnector { id: string; name: string | null; type: string | null; - fields: null; + fields: null | ESConnectorFields; }; } @@ -88,13 +94,21 @@ export const caseMigrations = { }; }, '7.12.0': ( - doc: SavedObjectUnsanitizedDoc> - ): SavedObjectSanitizedDoc => { + doc: SavedObjectUnsanitizedDoc + ): SavedObjectSanitizedDoc => { + const { fields, type } = doc.attributes.connector; return { ...doc, attributes: { ...doc.attributes, type: CaseType.individual, + connector: { + ...doc.attributes.connector, + fields: + Array.isArray(fields) && fields.length > 0 && type === ConnectorTypes.serviceNowITSM + ? [...fields, { key: 'category', value: null }, { key: 'subcategory', value: null }] + : fields, + }, }, references: doc.references || [], }; diff --git a/x-pack/test/case_api_integration/basic/tests/cases/migrations.ts b/x-pack/test/case_api_integration/basic/tests/cases/migrations.ts index e75ea0f8a89c9..e66b623138e60 100644 --- a/x-pack/test/case_api_integration/basic/tests/cases/migrations.ts +++ b/x-pack/test/case_api_integration/basic/tests/cases/migrations.ts @@ -58,7 +58,6 @@ export default function createGetTests({ getService }: FtrProviderContext) { // tests upgrading a 7.11.1 saved object to the latest version describe('7.11.1 -> latest stack version', () => { - const caseID = '2ea28c10-7855-11eb-9ca6-83ec5acb735f'; before(async () => { await esArchiver.load('cases/migrations/7.11.1'); }); @@ -68,6 +67,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { }); it('adds rule info to only alert comments for 7.12', async () => { + const caseID = '2ea28c10-7855-11eb-9ca6-83ec5acb735f'; // user comment let { body } = await supertest .get(`${CASES_URL}/${caseID}/comments/34a20a00-7855-11eb-9ca6-83ec5acb735f`) @@ -84,6 +84,28 @@ export default function createGetTests({ getService }: FtrProviderContext) { expect(body).key('rule'); expect(body.rule).to.eql({ id: null, name: null }); }); + + it('adds category and subcategory to the ITSM connector', async () => { + const { body } = await supertest + .get(`${CASES_URL}/6f973440-7abd-11eb-9ca6-83ec5acb735f`) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + expect(body).key('connector'); + expect(body.connector).to.eql({ + id: '444ebab0-7abd-11eb-9ca6-83ec5acb735f', + name: 'SN', + type: '.servicenow', + fields: { + impact: '2', + severity: '2', + urgency: '2', + category: null, + subcategory: null, + }, + }); + }); }); }); } diff --git a/x-pack/test/functional/es_archives/cases/migrations/7.11.1/data.json.gz b/x-pack/test/functional/es_archives/cases/migrations/7.11.1/data.json.gz index 219f58b7e9d21..efb62cba5675d 100644 Binary files a/x-pack/test/functional/es_archives/cases/migrations/7.11.1/data.json.gz and b/x-pack/test/functional/es_archives/cases/migrations/7.11.1/data.json.gz differ