Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event annotations] add types to integration tests #164103

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion src/plugins/event_annotation/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
83 changes: 47 additions & 36 deletions test/api_integration/apis/event_annotations/event_annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}