From 276cf86858fc81d70ca5cb8e36182ae12c89771a Mon Sep 17 00:00:00 2001 From: Drew Tate Date: Thu, 17 Aug 2023 08:17:25 -0600 Subject: [PATCH] [Event annotations] add types to integration tests (#164103) --- .github/CODEOWNERS | 2 +- src/plugins/event_annotation/common/index.ts | 8 +- .../event_annotations/event_annotations.ts | 83 +++++++++++-------- test/tsconfig.json | 3 +- 4 files changed, 57 insertions(+), 39 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c4ef8cba67037..da739b422d33f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -829,7 +829,7 @@ packages/kbn-yarn-lock-validator @elastic/kibana-operations /x-pack/test/api_integration/apis/lens/ @elastic/kibana-visualizations /test/functional/apps/visualize/ @elastic/kibana-visualizations /x-pack/test/functional/apps/graph @elastic/kibana-visualizations -/test/api_integraion/apis/event_annotations @elastic/kibana-visualizations +/test/api_integration/apis/event_annotations @elastic/kibana-visualizations # Global Experience diff --git a/src/plugins/event_annotation/common/index.ts b/src/plugins/event_annotation/common/index.ts index e4648d82fb765..cb30e43060cfb 100644 --- a/src/plugins/event_annotation/common/index.ts +++ b/src/plugins/event_annotation/common/index.ts @@ -26,5 +26,11 @@ export type { EventAnnotationGroupArgs } from './event_annotation_group'; export type { FetchEventAnnotationsArgs } from './fetch_event_annotations/types'; export type { EventAnnotationArgs, EventAnnotationOutput } from './types'; -export type { EventAnnotationGroupSavedObjectAttributes } from './content_management'; +export type { + EventAnnotationGroupSavedObjectAttributes, + EventAnnotationGroupCreateIn, + EventAnnotationGroupUpdateIn, + EventAnnotationGroupSearchIn, +} from './content_management'; +export { CONTENT_ID } from './content_management'; export { ANNOTATIONS_LISTING_VIEW_ID } from './constants'; diff --git a/test/api_integration/apis/event_annotations/event_annotations.ts b/test/api_integration/apis/event_annotations/event_annotations.ts index 01119446d8aa1..fda97881f3d9b 100644 --- a/test/api_integration/apis/event_annotations/event_annotations.ts +++ b/test/api_integration/apis/event_annotations/event_annotations.ts @@ -7,18 +7,23 @@ */ import expect from '@kbn/expect'; +import type { + EventAnnotationGroupSavedObjectAttributes, + EventAnnotationGroupCreateIn, + EventAnnotationGroupUpdateIn, + EventAnnotationGroupSearchIn, +} from '@kbn/event-annotation-plugin/common'; +import { CONTENT_ID } from '@kbn/event-annotation-plugin/common'; import { FtrProviderContext } from '../../ftr_provider_context'; const CONTENT_ENDPOINT = '/api/content_management/rpc'; -const CONTENT_TYPE_ID = 'event-annotation-group'; - const API_VERSION = 1; const EXISTING_ID_1 = 'fcebef20-3ba4-11ee-85d3-3dd00bdd66ef'; // from loaded archive const EXISTING_ID_2 = '0d1aa670-3baf-11ee-a4a7-c11cb33a9549'; // from loaded archive -const DEFAULT_EVENT_ANNOTATION_GROUP = { +const DEFAULT_EVENT_ANNOTATION_GROUP: EventAnnotationGroupSavedObjectAttributes = { title: 'a group', description: '', ignoreGlobalFilters: true, @@ -66,20 +71,22 @@ export default function ({ getService }: FtrProviderContext) { // TODO test tag searching, ordering, pagination, etc it(`should retrieve existing groups`, async () => { + const payload: EventAnnotationGroupSearchIn = { + contentTypeId: CONTENT_ID, + query: { + limit: 1000, + tags: { + included: [], + excluded: [], + }, + }, + version: API_VERSION, + }; + const resp = await supertest .post(`${CONTENT_ENDPOINT}/search`) .set('kbn-xsrf', 'kibana') - .send({ - contentTypeId: CONTENT_TYPE_ID, - query: { - limit: 1000, - tags: { - included: [], - excluded: [], - }, - }, - version: API_VERSION, - }) + .send(payload) .expect(200); const results = resp.body.result.result.hits; @@ -90,18 +97,20 @@ export default function ({ getService }: FtrProviderContext) { describe('create', () => { it(`should require dataViewSpec to be specified`, async () => { - const createWithDataViewSpec = (dataViewSpec: any) => - supertest + const createWithDataViewSpec = (dataViewSpec: any) => { + const payload: EventAnnotationGroupCreateIn = { + contentTypeId: CONTENT_ID, + data: { ...DEFAULT_EVENT_ANNOTATION_GROUP, dataViewSpec }, + options: { + references: DEFAULT_REFERENCES, + }, + version: API_VERSION, + }; + return supertest .post(`${CONTENT_ENDPOINT}/create`) .set('kbn-xsrf', 'kibana') - .send({ - contentTypeId: CONTENT_TYPE_ID, - data: { ...DEFAULT_EVENT_ANNOTATION_GROUP, dataViewSpec }, - options: { - references: DEFAULT_REFERENCES, - }, - version: API_VERSION, - }); + .send(payload); + }; const errorResp = await createWithDataViewSpec(undefined).expect(400); @@ -119,20 +128,22 @@ export default function ({ getService }: FtrProviderContext) { describe('update', () => { it(`should require dataViewSpec to be specified`, async () => { - const updateWithDataViewSpec = (dataViewSpec: any) => - supertest + const updateWithDataViewSpec = (dataViewSpec: any) => { + const payload: EventAnnotationGroupUpdateIn = { + contentTypeId: CONTENT_ID, + data: { ...DEFAULT_EVENT_ANNOTATION_GROUP, dataViewSpec }, + id: EXISTING_ID_1, + options: { + references: DEFAULT_REFERENCES, + }, + version: API_VERSION, + }; + + return supertest .post(`${CONTENT_ENDPOINT}/update`) .set('kbn-xsrf', 'kibana') - .send({ - contentTypeId: CONTENT_TYPE_ID, - data: { ...DEFAULT_EVENT_ANNOTATION_GROUP, dataViewSpec }, - id: EXISTING_ID_1, - options: { - references: DEFAULT_REFERENCES, - }, - version: API_VERSION, - }); - + .send(payload); + }; const errorResp = await updateWithDataViewSpec(undefined).expect(400); expect(errorResp.body.message).to.be( diff --git a/test/tsconfig.json b/test/tsconfig.json index 74788c0c85aec..56d4f185930e7 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -67,6 +67,7 @@ "@kbn/enterprise-search-plugin", "@kbn/core-saved-objects-server", "@kbn/discover-plugin", - "@kbn/core-http-common" + "@kbn/core-http-common", + "@kbn/event-annotation-plugin" ] }