diff --git a/x-pack/test_serverless/api_integration/test_suites/common/favorites/dashboard.ts b/x-pack/test_serverless/api_integration/test_suites/common/favorites/dashboard.ts new file mode 100644 index 0000000000000..05ad57aadbf18 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/favorites/dashboard.ts @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from '@kbn/expect'; +import type { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const roleScopedSupertest = getService('roleScopedSupertest'); + const kibanaServer = getService('kibanaServer'); + + describe('Favorites dashboard api', function () { + before(async () => { + await kibanaServer.savedObjects.clean({ + types: ['favorites'], + }); + }); + + it('can favorite a dashboard', async () => { + const supertest = await roleScopedSupertest.getSupertestWithRoleScope('viewer', { + useCookieHeader: true, // favorite only works with Cookie header + withInternalHeaders: true, + }); + + let response = await supertest + .get('/internal/content_management/favorites/dashboard') + .expect(200); + expect(response.body.favoriteIds).to.eql([]); + + const favoriteId = '1'; + + response = await supertest + .post(`/internal/content_management/favorites/dashboard/${favoriteId}/favorite`) + .expect(200); + + expect(response.body.favoriteIds).to.eql([favoriteId]); + + response = await supertest + .post(`/internal/content_management/favorites/dashboard/${favoriteId}/unfavorite`) + .expect(200); + expect(response.body.favoriteIds).to.eql([]); + }); + }); +} diff --git a/x-pack/test_serverless/api_integration/test_suites/common/favorites/esql.ts b/x-pack/test_serverless/api_integration/test_suites/common/favorites/esql.ts new file mode 100644 index 0000000000000..4dfb92273a410 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/favorites/esql.ts @@ -0,0 +1,62 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from '@kbn/expect'; +import type { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const roleScopedSupertest = getService('roleScopedSupertest'); + const kibanaServer = getService('kibanaServer'); + + describe('Favorites esql query api', function () { + before(async () => { + await kibanaServer.savedObjects.clean({ + types: ['favorites'], + }); + }); + + it('can favorite an esql_query', async () => { + const supertest = await roleScopedSupertest.getSupertestWithRoleScope('viewer', { + useCookieHeader: true, // favorite only works with Cookie header + withInternalHeaders: true, + }); + + const list = () => + supertest.get('/internal/content_management/favorites/esql_query').expect(200); + + let response = await list(); + expect(response.body.favoriteIds).to.eql([]); + + const favoriteId = '1'; + const metadata = { + queryString: 'SELECT * FROM test1', + createdAt: '2021-09-01T00:00:00Z', + status: 'success', + }; + + response = await supertest + .post(`/internal/content_management/favorites/esql_query/${favoriteId}/favorite`) + .send({ metadata }) + .expect(200); + + expect(response.body.favoriteIds).to.eql([favoriteId]); + + response = await list(); + expect(response.body.favoriteIds).to.eql([favoriteId]); + expect(response.body.favoriteMetadata).to.eql({ [favoriteId]: metadata }); + + response = await supertest + .post(`/internal/content_management/favorites/esql_query/${favoriteId}/unfavorite`) + .expect(200); + expect(response.body.favoriteIds).to.eql([]); + + response = await list(); + expect(response.body.favoriteIds).to.eql([]); + expect(response.body.favoriteMetadata).to.eql({}); + }); + }); +} diff --git a/x-pack/test_serverless/api_integration/test_suites/common/favorites/index.ts b/x-pack/test_serverless/api_integration/test_suites/common/favorites/index.ts new file mode 100644 index 0000000000000..684f88f6ac973 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/favorites/index.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('Favorites API', function () { + loadTestFile(require.resolve('./dashboard')); + loadTestFile(require.resolve('./esql')); + }); +} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts index 68202b5adf3ad..c3feabb61e1d3 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts @@ -33,6 +33,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/saved_objects_management'), require.resolve('../../common/telemetry'), require.resolve('../../common/data_usage'), + require.resolve('../../common/favorites'), ], junit: { reportName: 'Serverless Observability API Integration Tests - Common Group 1', diff --git a/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts index 36249651d5167..dd0222a24582d 100644 --- a/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts @@ -31,6 +31,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/saved_objects_management'), require.resolve('../../common/telemetry'), require.resolve('../../common/data_usage'), + require.resolve('../../common/favorites'), ], junit: { reportName: 'Serverless Search API Integration Tests - Common Group 1', diff --git a/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts index 577b4f8ba4ee0..29888d8031980 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts @@ -33,6 +33,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/saved_objects_management'), require.resolve('../../common/telemetry'), require.resolve('../../common/data_usage'), + require.resolve('../../common/favorites'), ], junit: { reportName: 'Serverless Security API Integration Tests - Common Group 1',