diff --git a/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts b/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts index 42b66792fa4df..e3e0349c2c742 100644 --- a/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts +++ b/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts @@ -435,13 +435,14 @@ describe('#updateObjectsSpaces', () => { it('deletes aliases for objects that were removed from specific spaces using "deleteBehavior: exclusive"', async () => { const space1 = 'space-to-remove'; - const space2 = 'other-space'; - const obj1 = { type: SHAREABLE_OBJ_TYPE, id: 'id-1', spaces: [space2] }; // will not be changed - const obj2 = { type: SHAREABLE_OBJ_TYPE, id: 'id-1', spaces: [space1, space2] }; // will be updated + const space2 = 'another-space-to-remove'; + const space3 = 'other-space'; + const obj1 = { type: SHAREABLE_OBJ_TYPE, id: 'id-1', spaces: [space3] }; // will not be changed + const obj2 = { type: SHAREABLE_OBJ_TYPE, id: 'id-1', spaces: [space1, space2, space3] }; // will be updated const obj3 = { type: SHAREABLE_OBJ_TYPE, id: 'id-1', spaces: [space1] }; // will be deleted const objects = [obj1, obj2, obj3]; - const spacesToRemove = [space1]; + const spacesToRemove = [space1, space2]; const params = setup({ objects, spacesToRemove }); // this test case does not call mget mockBulkResults({ error: false }, { error: false }); // result2 for obj2 and obj3 @@ -449,7 +450,7 @@ describe('#updateObjectsSpaces', () => { await updateObjectsSpaces(params); expect(client.bulk).toHaveBeenCalledTimes(1); expectBulkArgs( - { action: 'update', object: { ...obj2, namespaces: [space2] } }, + { action: 'update', object: { ...obj2, namespaces: [space3] } }, { action: 'delete', object: obj3 } ); expect(mockDeleteLegacyUrlAliases).toHaveBeenCalledTimes(2); @@ -458,7 +459,7 @@ describe('#updateObjectsSpaces', () => { expect.objectContaining({ type: obj2.type, id: obj2.id, - namespaces: [space1], + namespaces: [space1, space2], deleteBehavior: 'inclusive', }) ); diff --git a/x-pack/test/spaces_api_integration/common/suites/update_objects_spaces.ts b/x-pack/test/spaces_api_integration/common/suites/update_objects_spaces.ts index d2d35c303c512..3b795ae719db8 100644 --- a/x-pack/test/spaces_api_integration/common/suites/update_objects_spaces.ts +++ b/x-pack/test/spaces_api_integration/common/suites/update_objects_spaces.ts @@ -76,6 +76,7 @@ export function updateObjectsSpacesTestSuiteFactory( const { objects, spacesToAdd, spacesToRemove } = testCase; const apiResponse = response.body as SavedObjectsUpdateObjectsSpacesResponse; + let hasRefreshed = false; for (let i = 0; i < objects.length; i++) { const { id, existingNamespaces, expectAliasDifference, failure } = objects[i]; const object = apiResponse.objects[i]; @@ -96,7 +97,10 @@ export function updateObjectsSpacesTestSuiteFactory( if (expectAliasDifference !== undefined) { // if we deleted an object that had an alias pointing to it, the alias should have been deleted as well - await es.indices.refresh({ index: '.kibana' }); // alias deletion uses refresh: false, so we need to manually refresh the index before searching + if (!hasRefreshed) { + await es.indices.refresh({ index: '.kibana' }); // alias deletion uses refresh: false, so we need to manually refresh the index before searching + hasRefreshed = true; + } const searchResponse = await es.search({ index: '.kibana', body: {