import { SPACES , ALL_SPACES_ID } from '../../common/lib/spaces' ; import { testCaseFailures , getTestScenarios } from '../../common/lib/saved_object_test_utils' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; import { createTestSuiteFactory , TEST_CASES as CASES } from '../../common/suites/create' ; const { DEFAULT : { spaceId : DEFAULT_SPACE_ID } , SPACE_1 : { spaceId : SPACE_1_ID } , SPACE_2 : { spaceId : SPACE_2_ID } , } = SPACES ; const { fail400 , fail409 } = testCaseFailures ; const createTestCases = ( overwrite , spaceId ) => { const expectedNamespaces = [ spaceId ] ; return [ { ... CASES . SINGLE_NAMESPACE_DEFAULT_SPACE , ... fail409 ( ! overwrite && spaceId === DEFAULT_SPACE_ID ) , expectedNamespaces , } , { ... CASES . SINGLE_NAMESPACE_SPACE_1 , ... fail409 ( ! overwrite && spaceId === SPACE_1_ID ) , expectedNamespaces , } , { ... CASES . SINGLE_NAMESPACE_SPACE_2 , ... fail409 ( ! overwrite && spaceId === SPACE_2_ID ) , expectedNamespaces , } , { ... CASES . MULTI_NAMESPACE_ALL_SPACES , ... fail409 ( ! overwrite ) } , { ... CASES . MULTI_NAMESPACE_DEFAULT_AND_SPACE_1 , ... fail409 ( ! overwrite || ( spaceId !== DEFAULT_SPACE_ID && spaceId !== SPACE_1_ID ) ) , } , { ... CASES . MULTI_NAMESPACE_ONLY_SPACE_1 , ... fail409 ( ! overwrite || spaceId !== SPACE_1_ID ) } , { ... CASES . MULTI_NAMESPACE_ONLY_SPACE_2 , ... fail409 ( ! overwrite || spaceId !== SPACE_2_ID ) } , { ... CASES . MULTI_NAMESPACE_ISOLATED_ONLY_DEFAULT_SPACE , ... fail409 ( ! overwrite || spaceId !== DEFAULT_SPACE_ID ) , } , { ... CASES . MULTI_NAMESPACE_ISOLATED_ONLY_SPACE_1 , ... fail409 ( ! overwrite || spaceId !== SPACE_1_ID ) , } , { ... CASES . NAMESPACE_AGNOSTIC , ... fail409 ( ! overwrite ) } , { ... CASES . HIDDEN , ... fail400 ( ) } , { ... CASES . NEW_SINGLE_NAMESPACE_OBJ , expectedNamespaces } , { ... CASES . NEW_MULTI_NAMESPACE_OBJ , expectedNamespaces } , CASES . NEW_NAMESPACE_AGNOSTIC_OBJ , { ... CASES . INITIAL_NS_SINGLE_NAMESPACE_OBJ_OTHER_SPACE , initialNamespaces : [ 'x' , 'y' ] , ... fail400 ( ) , } , CASES . INITIAL_NS_SINGLE_NAMESPACE_OBJ_OTHER_SPACE , { ... CASES . INITIAL_NS_MULTI_NAMESPACE_ISOLATED_OBJ_OTHER_SPACE , initialNamespaces : [ ALL_SPACES_ID ] , ... fail400 ( ) , } , CASES . INITIAL_NS_MULTI_NAMESPACE_ISOLATED_OBJ_OTHER_SPACE , CASES . INITIAL_NS_MULTI_NAMESPACE_OBJ_EACH_SPACE , CASES . INITIAL_NS_MULTI_NAMESPACE_OBJ_ALL_SPACES , { ... CASES . ALIAS_CONFLICT_OBJ , initialNamespaces : [ '*' ] , ... fail409 ( ) } , { ... CASES . ALIAS_CONFLICT_OBJ , ... fail409 ( spaceId === SPACE_1_ID ) , expectedNamespaces } , ] ; } ; export default function ( { getService } ) { const supertest = getService ( 'supertestWithoutAuth' ) ; const esArchiver = getService ( 'esArchiver' ) ; const { addTests , createTestDefinitions } = createTestSuiteFactory ( esArchiver , supertest ) ; const createTests = ( overwrite , spaceId ) => { const testCases = createTestCases ( overwrite , spaceId ) ; return createTestDefinitions ( testCases , false , overwrite , { spaceId } ) ; } ; describe ( '_create' , ( ) => { getTestScenarios ( [ false , true ] ) . spaces . forEach ( ( { spaceId , modifier : overwrite } ) => { const suffix = overwrite ? ' with overwrite enabled' : '' ; const tests = createTests ( overwrite ! , spaceId ) ; addTests ( `within the ${ spaceId } space${ suffix }` , { spaceId , tests } ) ; } ) ; } ) ; }