kibana/test/api_integration/apis/guided_onboarding/put_state.ts
Sander Philipse 2ba56a55a4
[9.0] [Search] Remove website search guided onboarding (#224538) (#224665)
# Backport

This will backport the following commits from `main` to `9.0`:
- [[Search] Remove website search guided onboarding
(#224538)](https://github.com/elastic/kibana/pull/224538)

<!--- Backport version: 10.0.1 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Sander
Philipse","email":"94373878+sphilipse@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-06-19T17:34:32Z","message":"[Search]
Remove website search guided onboarding (#224538)\n\n## Summary\n\nThis
removes the deprecated website search guided onboarding from\nKibana.
Deprecated because we no longer offer a managed web
crawler.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9171743e8368a47503cf5892a8b7e47d35b42319","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Search","backport:prev-minor","v9.1.0","v9.0.1"],"title":"[Search]
Remove website search guided
onboarding","number":224538,"url":"https://github.com/elastic/kibana/pull/224538","mergeCommit":{"message":"[Search]
Remove website search guided onboarding (#224538)\n\n## Summary\n\nThis
removes the deprecated website search guided onboarding from\nKibana.
Deprecated because we no longer offer a managed web
crawler.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9171743e8368a47503cf5892a8b7e47d35b42319"}},"sourceBranch":"main","suggestedTargetBranches":["9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/224538","number":224538,"mergeCommit":{"message":"[Search]
Remove website search guided onboarding (#224538)\n\n## Summary\n\nThis
removes the deprecated website search guided onboarding from\nKibana.
Deprecated because we no longer offer a managed web
crawler.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9171743e8368a47503cf5892a8b7e47d35b42319"}},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-06-20 08:07:25 -05:00

191 lines
6.1 KiB
TypeScript

/*
* 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 expect from '@kbn/expect';
import {
testGuideStep1ActiveState,
testGuideNotActiveState,
testGuideStep1InProgressState,
testGuideStep2ActiveState,
testGuideParams,
} from '@kbn/guided-onboarding-plugin/public/services/api.mocks';
import {
pluginStateSavedObjectsType,
pluginStateSavedObjectsId,
guideStateSavedObjectsType,
} from '@kbn/guided-onboarding-plugin/server/saved_objects/guided_setup';
import { testGuideId } from '@kbn/guided-onboarding';
import { API_BASE_PATH } from '@kbn/guided-onboarding-plugin/common';
import { X_ELASTIC_INTERNAL_ORIGIN_REQUEST } from '@kbn/core-http-common';
import type { FtrProviderContext } from '../../ftr_provider_context';
import { createGuides, createPluginState } from './helpers';
const putStatePath = `${API_BASE_PATH}/state`;
export default function testPutState({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
describe(`PUT ${putStatePath}`, () => {
afterEach(async () => {
// Clean up saved objects
await kibanaServer.savedObjects.clean({
types: [pluginStateSavedObjectsType, guideStateSavedObjectsType],
});
});
it('creates a plugin saved object when updating the status and there is no state yet', async () => {
const response = await supertest
.put(putStatePath)
.set('kbn-xsrf', 'true')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send({
status: 'in_progress',
})
.expect(200);
expect(response.body).to.eql({
pluginState: {
status: 'in_progress',
isActivePeriod: true,
},
});
const createdSO = await kibanaServer.savedObjects.get({
type: pluginStateSavedObjectsType,
id: pluginStateSavedObjectsId,
});
expect(createdSO.attributes.status).to.eql('in_progress');
});
it('updates the plugin saved object when updating the status and there is already state', async () => {
await createPluginState(kibanaServer, {
status: 'not_started',
creationDate: new Date().toISOString(),
});
const response = await supertest
.put(putStatePath)
.set('kbn-xsrf', 'true')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send({
status: 'in_progress',
})
.expect(200);
expect(response.body).to.eql({
pluginState: {
status: 'in_progress',
isActivePeriod: true,
},
});
const createdSO = await kibanaServer.savedObjects.get({
type: pluginStateSavedObjectsType,
id: pluginStateSavedObjectsId,
});
expect(createdSO.attributes.status).to.eql('in_progress');
});
it('creates a guide saved object when updating the guide and there is no guide SO yet', async () => {
await supertest
.put(putStatePath)
.set('kbn-xsrf', 'true')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send({
guide: testGuideStep1ActiveState,
})
.expect(200);
const createdSO = await kibanaServer.savedObjects.get({
type: guideStateSavedObjectsType,
id: testGuideId,
});
expect(createdSO.attributes).to.eql(testGuideStep1ActiveState);
});
it('updates the guide saved object when updating the guide and there is already guide SO', async () => {
await createGuides(kibanaServer, [testGuideStep1ActiveState]);
await supertest
.put(putStatePath)
.set('kbn-xsrf', 'true')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send({
guide: testGuideNotActiveState,
})
.expect(200);
const createdSO = await kibanaServer.savedObjects.get({
type: guideStateSavedObjectsType,
id: testGuideId,
});
expect(createdSO.attributes).to.eql(testGuideNotActiveState);
});
it('updates any existing active guides to inactive', async () => {
// create an active guide
await createGuides(kibanaServer, [testGuideStep1ActiveState]);
// Create a new guide with isActive: true
await supertest
.put(putStatePath)
.set('kbn-xsrf', 'true')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send({
guide: {
...testGuideStep1ActiveState,
guideId: 'kubernetes',
},
})
.expect(200);
// Check that all guides except observability are inactive
const testGuideSO = await kibanaServer.savedObjects.get({
type: guideStateSavedObjectsType,
id: testGuideId,
});
expect(testGuideSO.attributes.isActive).to.eql(false);
const kubernetesGuide = await kibanaServer.savedObjects.get({
type: guideStateSavedObjectsType,
id: 'kubernetes',
});
expect(kubernetesGuide.attributes.isActive).to.eql(true);
});
it('saves dynamic params if provided', async () => {
// create a guide
await createGuides(kibanaServer, [testGuideStep1InProgressState]);
// complete step1 with dynamic params
await supertest
.put(putStatePath)
.set('kbn-xsrf', 'true')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.send({
guide: {
...testGuideStep2ActiveState,
params: testGuideParams,
},
})
.expect(200);
// check that params object was saved
const testGuideSO = await kibanaServer.savedObjects.get({
type: guideStateSavedObjectsType,
id: testGuideId,
});
expect(testGuideSO.attributes.params).to.eql(testGuideParams);
});
});
}