Skip to content

Commit

Permalink
Add smoke serverless tests for favorites (starred) feature (#200985)
Browse files Browse the repository at this point in the history
## Summary

close #200701

As a follow-up to #198362 would
like to add very basic serverless test that check that the favorites
(starred) API works
  • Loading branch information
Dosant authored Nov 27, 2024
1 parent d077414 commit 38fab2d
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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([]);
});
});
}
Original file line number Diff line number Diff line change
@@ -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({});
});
});
}
Original file line number Diff line number Diff line change
@@ -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'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 38fab2d

Please sign in to comment.