-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add smoke serverless tests for favorites (starred) feature (#200985)
## 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
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
x-pack/test_serverless/api_integration/test_suites/common/favorites/dashboard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([]); | ||
}); | ||
}); | ||
} |
62 changes: 62 additions & 0 deletions
62
x-pack/test_serverless/api_integration/test_suites/common/favorites/esql.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}); | ||
}); | ||
}); | ||
} |
15 changes: 15 additions & 0 deletions
15
x-pack/test_serverless/api_integration/test_suites/common/favorites/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters