import { SPACES } from '../../common/lib/spaces' ; import { testCaseFailures , getTestScenarios , } from '../../../saved_object_api_integration/common/lib/saved_object_test_utils' ; import { MULTI_NAMESPACE_SAVED_OBJECT_TEST_CASES as CASES } from '../../common/lib/saved_object_test_cases' ; import type { UpdateObjectsSpacesTestCase } from '../../common/suites/update_objects_spaces' ; import { updateObjectsSpacesTestSuiteFactory } from '../../common/suites/update_objects_spaces' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; const { DEFAULT : { spaceId : DEFAULT_SPACE_ID } , SPACE_1 : { spaceId : SPACE_1_ID } , SPACE_2 : { spaceId : SPACE_2_ID } , } = SPACES ; const { fail404 } = testCaseFailures ; param spaceId const createSinglePartTestCases = ( spaceId ) => { const spacesToAdd = [ 'some-space-id' ] ; const spacesToRemove = [ spaceId ] ; return { objects : [ { ... CASES . DEFAULT_ONLY , ... fail404 ( spaceId !== DEFAULT_SPACE_ID ) } , { ... CASES . SPACE_1_ONLY , ... fail404 ( spaceId !== SPACE_1_ID ) } , { ... CASES . SPACE_2_ONLY , ... fail404 ( spaceId !== SPACE_2_ID ) } , { ... CASES . DEFAULT_AND_SPACE_1 , ... fail404 ( spaceId === SPACE_2_ID ) } , { ... CASES . DEFAULT_AND_SPACE_2 , ... fail404 ( spaceId === SPACE_1_ID ) } , { ... CASES . SPACE_1_AND_SPACE_2 , ... fail404 ( spaceId === DEFAULT_SPACE_ID ) } , CASES . EACH_SPACE , CASES . ALL_SPACES , { ... CASES . DOES_NOT_EXIST , ... fail404 ( ) } , ] , spacesToAdd , spacesToRemove , } ; } ; /**
 * Multi-part test cases, which have to be run sequentially
 * These are non-exhaustive, but they check different permutations of saved objects and spaces to add
 */ const createMultiPartTestCases = ( ) => { const nonExistentSpace = 'does_not_exist' ; const eachSpace = [ DEFAULT_SPACE_ID , SPACE_1_ID , SPACE_2_ID ] ; const group1 = [ { objects : [ { id : CASES . ALIAS_DELETE_INCLUSIVE . id , existingNamespaces : eachSpace , expectAliasDifference : - 1 , } , ] , spacesToAdd : [ ] , spacesToRemove : [ SPACE_2_ID ] , } , { objects : [ { id : CASES . ALIAS_DELETE_INCLUSIVE . id , existingNamespaces : [ DEFAULT_SPACE_ID , SPACE_1_ID ] , expectAliasDifference : - 2 , } , ] , spacesToAdd : [ ] , spacesToRemove : [ SPACE_1_ID ] , } , { objects : [ { id : CASES . ALIAS_DELETE_INCLUSIVE . id , existingNamespaces : [ DEFAULT_SPACE_ID ] , expectAliasDifference : - 2 , } , ] , spacesToAdd : [ ] , spacesToRemove : [ DEFAULT_SPACE_ID ] , } , { objects : [ { id : CASES . ALIAS_DELETE_EXCLUSIVE . id , existingNamespaces : [ SPACE_1_ID ] , expectAliasDifference : - 3 , } , ] , spacesToAdd : [ SPACE_1_ID ] , spacesToRemove : [ '*' ] , } , ] ; const group2 = [ { objects : [ CASES . DEFAULT_ONLY ] , spacesToAdd : eachSpace , spacesToRemove : [ nonExistentSpace ] } , { objects : [ { id : CASES . DEFAULT_ONLY . id , existingNamespaces : eachSpace } ] , spacesToAdd : [ nonExistentSpace , '*' ] , spacesToRemove : [ DEFAULT_SPACE_ID ] , } , { objects : [ { id : CASES . DEFAULT_ONLY . id , existingNamespaces : [ SPACE_1_ID , SPACE_2_ID , nonExistentSpace , '*' ] , } , ] , spacesToAdd : [ ] , spacesToRemove : [ '*' ] , } , { objects : [ { id : CASES . DEFAULT_ONLY . id , existingNamespaces : [ SPACE_1_ID , SPACE_2_ID , nonExistentSpace ] , ... fail404 ( ) , } , ] , spacesToAdd : [ ] , spacesToRemove : [ SPACE_1_ID ] , } , ] ; const group3 = [ { objects : [ CASES . DEFAULT_AND_SPACE_1 ] , spacesToAdd : [ SPACE_2_ID ] , spacesToRemove : [ SPACE_1_ID ] , } , { objects : [ { id : CASES . DEFAULT_AND_SPACE_1 . id , existingNamespaces : [ DEFAULT_SPACE_ID , SPACE_2_ID ] } , ] , spacesToAdd : [ ] , spacesToRemove : [ DEFAULT_SPACE_ID , SPACE_1_ID ] , } , { objects : [ { id : CASES . DEFAULT_AND_SPACE_1 . id , existingNamespaces : [ ] , ... fail404 ( ) } ] , spacesToAdd : [ DEFAULT_SPACE_ID ] , spacesToRemove : [ ] , } , ] ; return [ ... group1 , ... group2 , ... group3 ] ; } ; export default function ( { getService } ) { const supertest = getService ( 'supertest' ) ; const esArchiver = getService ( 'esArchiver' ) ; const es = getService ( 'es' ) ; const { addTests , createTestDefinitions } = updateObjectsSpacesTestSuiteFactory ( es , esArchiver , supertest ) ; const createSinglePartTests = ( spaceId ) => { const testCases = createSinglePartTestCases ( spaceId ) ; return createTestDefinitions ( testCases , false ) ; } ; const createMultiPartTests = ( ) => { const testCases = createMultiPartTestCases ( ) ; return createTestDefinitions ( testCases , false ) ; } ; describe ( '_update_objects_spaces' , ( ) => { getTestScenarios ( ) . spaces . forEach ( ( { spaceId } ) => { const tests = createSinglePartTests ( spaceId ) ; addTests ( `targeting the ${ spaceId } space` , { spaceId , tests } ) ; } ) ; const multiPartTests = createMultiPartTests ( ) ; addTests ( 'multi-part tests in the default space' , { tests : multiPartTests } ) ; } ) ; }