-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[@kbn/dashboard-plugin] Migrate Dashboard's CRUD API tests from FTR to Scout #251163
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
Changes from all commits
aac9d14
446d774
2866bbc
715e4ed
9e1e6fa
b980b2c
9bc29ec
a5b0886
cc3a93d
23fa3d7
cd15d5a
f092e52
bbd4092
35a4ea8
7fec875
4d560ef
2173b54
7138b58
e11cee1
c857259
21ed4ee
eb0fd4c
a8fb2ae
dd4a406
6fff2d3
5a91a38
545d67e
aff266a
24c17eb
4f37808
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { servers as defaultConfig } from '../../../default/serverless/es.serverless.config'; | ||
| import type { ScoutServerConfig } from '../../../../../types'; | ||
|
|
||
| /** | ||
| * Custom Scout server configuration for OAS (OpenAPI Specification) schema validation tests. | ||
| * Enables the OAS endpoint which is required for schema validation. | ||
| * | ||
| * This config is automatically used when running tests from: | ||
| * dashboard/test/scout_oas_schema/ | ||
| * | ||
| * Usage: | ||
| * node scripts/scout.js start-server --serverless=es --config-dir oas_schema | ||
| */ | ||
| export const servers: ScoutServerConfig = { | ||
| ...defaultConfig, | ||
| kbnTestServer: { | ||
| ...defaultConfig.kbnTestServer, | ||
| serverArgs: [ | ||
| ...defaultConfig.kbnTestServer.serverArgs, | ||
| // Enable OpenAPI specification endpoint for schema validation tests | ||
| '--server.oas.enabled=true', | ||
| ], | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { servers as defaultConfig } from '../../../default/serverless/oblt.serverless.config'; | ||
| import type { ScoutServerConfig } from '../../../../../types'; | ||
|
|
||
| /** | ||
| * Custom Scout server configuration for OAS (OpenAPI Specification) schema validation tests. | ||
| * Enables the OAS endpoint which is required for schema validation. | ||
| * | ||
| * This config is automatically used when running tests from: | ||
| * dashboard/test/scout_oas_schema/ | ||
| * | ||
| * Usage: | ||
| * node scripts/scout.js start-server --serverless=oblt --config-dir oas_schema | ||
| */ | ||
| export const servers: ScoutServerConfig = { | ||
| ...defaultConfig, | ||
| kbnTestServer: { | ||
| ...defaultConfig.kbnTestServer, | ||
| serverArgs: [ | ||
| ...defaultConfig.kbnTestServer.serverArgs, | ||
| // Enable OpenAPI specification endpoint for schema validation tests | ||
| '--server.oas.enabled=true', | ||
| ], | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { servers as defaultConfig } from '../../../default/serverless/security.serverless.config'; | ||
| import type { ScoutServerConfig } from '../../../../../types'; | ||
|
|
||
| /** | ||
| * Custom Scout server configuration for OAS (OpenAPI Specification) schema validation tests. | ||
| * Enables the OAS endpoint which is required for schema validation. | ||
| * | ||
| * This config is automatically used when running tests from: | ||
| * dashboard/test/scout_oas_schema/ | ||
| * | ||
| * Usage: | ||
| * node scripts/scout.js start-server --serverless=security --config-dir oas_schema | ||
| */ | ||
| export const servers: ScoutServerConfig = { | ||
| ...defaultConfig, | ||
| kbnTestServer: { | ||
| ...defaultConfig.kbnTestServer, | ||
| serverArgs: [ | ||
| ...defaultConfig.kbnTestServer.serverArgs, | ||
| // Enable OpenAPI specification endpoint for schema validation tests | ||
| '--server.oas.enabled=true', | ||
| ], | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import type { ScoutServerConfig } from '../../../../../types'; | ||
| import { defaultConfig } from '../../../default/stateful/base.config'; | ||
|
|
||
| /** | ||
| * Custom Scout server configuration for OAS (OpenAPI Specification) schema validation tests. | ||
| * Enables the OAS endpoint which is required for schema validation. | ||
| * | ||
| * This config is automatically used when running tests from: | ||
| * dashboard/test/scout_oas_schema/ | ||
| * | ||
| * Usage: | ||
| * node scripts/scout.js start-server --stateful --config-dir oas_schema | ||
| */ | ||
| export const servers: ScoutServerConfig = { | ||
| ...defaultConfig, | ||
| kbnTestServer: { | ||
| ...defaultConfig.kbnTestServer, | ||
| serverArgs: [ | ||
| ...defaultConfig.kbnTestServer.serverArgs, | ||
| // Enable OpenAPI specification endpoint for schema validation tests | ||
| '--server.oas.enabled=true', | ||
| ], | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| /** The base API path for dashboard endpoints (no leading slash for apiClient). */ | ||
| export const DASHBOARD_API_PATH = 'api/dashboards'; | ||
|
|
||
| /** Common headers for Dashboard API requests (internal API version 1) */ | ||
| export const COMMON_HEADERS = { | ||
| 'kbn-xsrf': 'some-xsrf-token', | ||
| 'x-elastic-internal-origin': 'kibana', | ||
| 'elastic-api-version': '1', | ||
| } as const; | ||
|
|
||
| /** Test data paths */ | ||
| export const KBN_ARCHIVES = { | ||
| BASIC: 'src/platform/test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json', | ||
| TAGS: 'src/platform/test/api_integration/fixtures/kbn_archiver/saved_objects/tags.json', | ||
| MANY_DASHBOARDS: | ||
| 'src/platform/test/api_integration/fixtures/kbn_archiver/saved_objects/many-dashboards.json', | ||
| } as const; | ||
|
|
||
| /** Test dashboard ID used in fixtures - is a saved object loaded by the kbn_archiver */ | ||
| export const TEST_DASHBOARD_ID = 'be3733a0-9efe-11e7-acb3-3dab96693fab'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { createPlaywrightConfig } from '@kbn/scout'; | ||
|
|
||
| export default createPlaywrightConfig({ | ||
| testDir: './tests', | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,161 @@ | ||||||
| /* | ||||||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||||||
| * Public License v 1"; you may not use this file except in compliance with, at | ||||||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||||||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||||||
| */ | ||||||
|
|
||||||
| import type { RoleApiCredentials } from '@kbn/scout'; | ||||||
| import { expect } from '@kbn/scout/api'; | ||||||
| import { tags } from '@kbn/scout'; | ||||||
| import { | ||||||
| apiTest, | ||||||
| COMMON_HEADERS, | ||||||
| DASHBOARD_API_PATH, | ||||||
| KBN_ARCHIVES, | ||||||
| TEST_DASHBOARD_ID, | ||||||
| } from '../fixtures'; | ||||||
|
|
||||||
| apiTest.describe('dashboards - create', { tag: tags.ESS_ONLY }, () => { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears most tests can be run on serverless projects as well, we could update the tags:
Suggested change
Actually, dashboards may not be available in all projects types (such as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About this one, the As far as I understand, once we can have an equivalent method to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds great 👍 I wonder if we should create an issue in our internal backlog to remember about getting back to updating the test suites tags. What do you think? |
||||||
| let editorCredentials: RoleApiCredentials; | ||||||
|
|
||||||
| apiTest.beforeAll(async ({ kbnClient, requestAuth }) => { | ||||||
| editorCredentials = await requestAuth.getApiKey('editor'); | ||||||
| await kbnClient.importExport.load(KBN_ARCHIVES.BASIC); | ||||||
| await kbnClient.importExport.load(KBN_ARCHIVES.TAGS); | ||||||
| }); | ||||||
|
|
||||||
| apiTest.afterAll(async ({ kbnClient }) => { | ||||||
| await kbnClient.savedObjects.cleanStandardList(); | ||||||
| }); | ||||||
|
|
||||||
| apiTest('should create a dashboard', async ({ apiClient }) => { | ||||||
| const title = 'Hello world dashboard'; | ||||||
|
|
||||||
| const response = await apiClient.post(DASHBOARD_API_PATH, { | ||||||
| headers: { | ||||||
| ...COMMON_HEADERS, | ||||||
| ...editorCredentials.apiKeyHeader, | ||||||
| }, | ||||||
| body: { | ||||||
| data: { | ||||||
| title, | ||||||
| }, | ||||||
| }, | ||||||
| responseType: 'json', | ||||||
| }); | ||||||
|
|
||||||
| expect(response).toHaveStatusCode(200); | ||||||
| expect(response.body.spaces).toStrictEqual(['default']); | ||||||
| expect(response.body.data).toStrictEqual({ | ||||||
| title, | ||||||
| }); | ||||||
| }); | ||||||
|
|
||||||
| apiTest('can create a dashboard with a specific id', async ({ apiClient }) => { | ||||||
| const title = `foo-${Date.now()}-${Math.random()}`; | ||||||
| const id = `bar-${Date.now()}-${Math.random()}`; | ||||||
|
|
||||||
| const response = await apiClient.post(DASHBOARD_API_PATH, { | ||||||
| headers: { | ||||||
| ...COMMON_HEADERS, | ||||||
| ...editorCredentials.apiKeyHeader, | ||||||
| }, | ||||||
| body: { | ||||||
| id, | ||||||
| data: { | ||||||
| title, | ||||||
| }, | ||||||
| }, | ||||||
| responseType: 'json', | ||||||
| }); | ||||||
|
|
||||||
| expect(response).toHaveStatusCode(200); | ||||||
| expect(response.body.id).toBe(id); | ||||||
| }); | ||||||
|
|
||||||
| // TODO Maybe move this test to x-pack/platform/test/api_integration/dashboards | ||||||
| apiTest('can create a dashboard in a defined space', async ({ apiClient }) => { | ||||||
| const title = `foo-${Date.now()}-${Math.random()}`; | ||||||
| const spaceId = 'space-1'; | ||||||
|
|
||||||
| const response = await apiClient.post(DASHBOARD_API_PATH, { | ||||||
| headers: { | ||||||
| ...COMMON_HEADERS, | ||||||
| ...editorCredentials.apiKeyHeader, | ||||||
| }, | ||||||
| body: { | ||||||
| data: { | ||||||
| title, | ||||||
| }, | ||||||
| spaces: [spaceId], | ||||||
| }, | ||||||
| responseType: 'json', | ||||||
| }); | ||||||
|
|
||||||
| expect(response).toHaveStatusCode(200); | ||||||
| expect(response.body.spaces).toStrictEqual([spaceId]); | ||||||
| }); | ||||||
|
|
||||||
| apiTest('return error if provided id already exists', async ({ apiClient }) => { | ||||||
| const title = `foo-${Date.now()}-${Math.random()}`; | ||||||
|
|
||||||
| const response = await apiClient.post(DASHBOARD_API_PATH, { | ||||||
| headers: { | ||||||
| ...COMMON_HEADERS, | ||||||
| ...editorCredentials.apiKeyHeader, | ||||||
| }, | ||||||
| body: { | ||||||
| id: TEST_DASHBOARD_ID, | ||||||
| data: { | ||||||
| title, | ||||||
| }, | ||||||
| }, | ||||||
| responseType: 'json', | ||||||
| }); | ||||||
|
|
||||||
| expect(response).toHaveStatusCode(409); | ||||||
| expect(response.body.message).toBe(`A dashboard with ID ${TEST_DASHBOARD_ID} already exists.`); | ||||||
| }); | ||||||
|
|
||||||
| apiTest('validation - returns error when title is not provided', async ({ apiClient }) => { | ||||||
| const response = await apiClient.post(DASHBOARD_API_PATH, { | ||||||
| headers: { | ||||||
| ...COMMON_HEADERS, | ||||||
| ...editorCredentials.apiKeyHeader, | ||||||
| }, | ||||||
| body: { | ||||||
| data: {}, | ||||||
| }, | ||||||
| responseType: 'json', | ||||||
| }); | ||||||
|
|
||||||
| expect(response).toHaveStatusCode(400); | ||||||
| expect(response.body.message).toBe( | ||||||
| '[request body.data.title]: expected value of type [string] but got [undefined]' | ||||||
| ); | ||||||
| }); | ||||||
|
|
||||||
| apiTest('validation - returns error if panels is not an array', async ({ apiClient }) => { | ||||||
| const response = await apiClient.post(DASHBOARD_API_PATH, { | ||||||
| headers: { | ||||||
| ...COMMON_HEADERS, | ||||||
| ...editorCredentials.apiKeyHeader, | ||||||
| }, | ||||||
| body: { | ||||||
| data: { | ||||||
| title: 'foo', | ||||||
| panels: {}, | ||||||
| }, | ||||||
| }, | ||||||
| responseType: 'json', | ||||||
| }); | ||||||
|
|
||||||
| expect(response).toHaveStatusCode(400); | ||||||
| expect(response.body.message).toBe( | ||||||
| '[request body.data.panels]: expected value of type [array] but got [Object]' | ||||||
| ); | ||||||
| }); | ||||||
| }); | ||||||
Uh oh!
There was an error while loading. Please reload this page.