Skip to content

Commit

Permalink
Migrate category & subcategory fields of ServiceNow ITSM connector
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Mar 1, 2021
1 parent b5cd44e commit 7d4ec7b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
22 changes: 18 additions & 4 deletions x-pack/plugins/case/server/saved_object_types/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +30,7 @@ interface SanitizedCaseConnector {
id: string;
name: string | null;
type: string | null;
fields: null;
fields: null | ESConnectorFields;
};
}

Expand Down Expand Up @@ -88,13 +94,21 @@ export const caseMigrations = {
};
},
'7.12.0': (
doc: SavedObjectUnsanitizedDoc<Record<string, unknown>>
): SavedObjectSanitizedDoc<SanitizedCaseType> => {
doc: SavedObjectUnsanitizedDoc<SanitizedCaseConnector>
): SavedObjectSanitizedDoc<SanitizedCaseType & SanitizedCaseConnector> => {
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 || [],
};
Expand Down
22 changes: 22 additions & 0 deletions x-pack/test/case_api_integration/basic/tests/cases/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

expect(body).key('connector');
expect(body.connector).to.eql({
id: 'connector-1',
name: 'SN',
type: '.servicenow',
fields: {
impact: '1',
severity: '1',
urgency: '1',
category: null,
subcategory: null,
},
});
});
});
});
}

0 comments on commit 7d4ec7b

Please sign in to comment.