Skip to content

Commit

Permalink
PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jportner committed Nov 3, 2021
1 parent 7373db6 commit 04db6f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,22 @@ 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

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);
Expand All @@ -458,7 +459,7 @@ describe('#updateObjectsSpaces', () => {
expect.objectContaining({
type: obj2.type,
id: obj2.id,
namespaces: [space1],
namespaces: [space1, space2],
deleteBehavior: 'inclusive',
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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: {
Expand Down

0 comments on commit 04db6f2

Please sign in to comment.