@@ -12,8 +12,8 @@ import { getKibanaVersion } from './lib/saved_objects_test_utils';
1212
1313export default function ( { getService } : FtrProviderContext ) {
1414 const supertest = getService ( 'supertest' ) ;
15- const esArchiver = getService ( 'esArchiver ' ) ;
16- const esDeleteAllIndices = getService ( 'esDeleteAllIndices' ) ;
15+ const kibanaServer = getService ( 'kibanaServer ' ) ;
16+ const SPACE_ID = 'ftr-so-bulk-create' ;
1717
1818 const BULK_REQUESTS = [
1919 {
@@ -38,99 +38,58 @@ export default function ({ getService }: FtrProviderContext) {
3838
3939 before ( async ( ) => {
4040 KIBANA_VERSION = await getKibanaVersion ( getService ) ;
41+ await kibanaServer . spaces . create ( { id : SPACE_ID , name : SPACE_ID } ) ;
42+ await kibanaServer . importExport . load ( 'saved_objects/basic' , { space : SPACE_ID } ) ;
4143 } ) ;
4244
43- describe ( 'with kibana index' , ( ) => {
44- before ( ( ) => esArchiver . load ( 'saved_objects/basic' ) ) ;
45- after ( ( ) => esArchiver . unload ( 'saved_objects/basic' ) ) ;
45+ after ( ( ) => kibanaServer . spaces . delete ( SPACE_ID ) ) ;
4646
47- it ( 'should return 200 with individual responses' , async ( ) =>
48- await supertest
49- . post ( `/api/saved_objects/_bulk_create` )
50- . send ( BULK_REQUESTS )
51- . expect ( 200 )
52- . then ( ( resp ) => {
53- expect ( resp . body ) . to . eql ( {
54- saved_objects : [
55- {
56- type : 'visualization' ,
57- id : 'dd7caf20-9efd-11e7-acb3-3dab96693fab' ,
58- error : {
59- error : 'Conflict' ,
60- message :
61- 'Saved object [visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab] conflict' ,
62- statusCode : 409 ,
63- } ,
47+ it ( 'should return 200 with individual responses' , async ( ) =>
48+ await supertest
49+ . post ( `/s/${ SPACE_ID } /api/saved_objects/_bulk_create` )
50+ . send ( BULK_REQUESTS )
51+ . expect ( 200 )
52+ . then ( ( resp ) => {
53+ expect ( resp . body ) . to . eql ( {
54+ saved_objects : [
55+ {
56+ type : 'visualization' ,
57+ id : 'dd7caf20-9efd-11e7-acb3-3dab96693fab' ,
58+ error : {
59+ error : 'Conflict' ,
60+ message :
61+ 'Saved object [visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab] conflict' ,
62+ statusCode : 409 ,
6463 } ,
65- {
66- type : 'dashboard' ,
67- id : 'a01b2f57-fcfd-4864-b735-09e28f0d815e' ,
68- updated_at : resp . body . saved_objects [ 1 ] . updated_at ,
69- version : resp . body . saved_objects [ 1 ] . version ,
70- attributes : {
71- title : 'A great new dashboard' ,
72- } ,
73- migrationVersion : {
74- dashboard : resp . body . saved_objects [ 1 ] . migrationVersion . dashboard ,
75- } ,
76- coreMigrationVersion : KIBANA_VERSION ,
77- references : [ ] ,
78- namespaces : [ 'default' ] ,
64+ } ,
65+ {
66+ type : 'dashboard' ,
67+ id : 'a01b2f57-fcfd-4864-b735-09e28f0d815e' ,
68+ updated_at : resp . body . saved_objects [ 1 ] . updated_at ,
69+ version : resp . body . saved_objects [ 1 ] . version ,
70+ attributes : {
71+ title : 'A great new dashboard' ,
7972 } ,
80- ] ,
81- } ) ;
82- } ) ) ;
83-
84- it ( 'should not return raw id when object id is unspecified' , async ( ) =>
85- await supertest
86- . post ( `/api/saved_objects/_bulk_create` )
87- . send ( BULK_REQUESTS . map ( ( { id, ...rest } ) => rest ) )
88- . expect ( 200 )
89- . then ( ( resp ) => {
90- resp . body . saved_objects . map ( ( { id } : { id : string } ) =>
91- expect ( id ) . not . match ( / v i s u a l i z a t i o n | d a s h b o a r d / )
92- ) ;
93- } ) ) ;
94- } ) ;
95-
96- describe ( 'without kibana index' , ( ) => {
97- before (
98- async ( ) =>
99- // just in case the kibana server has recreated it
100- await esDeleteAllIndices ( '.kibana*' )
101- ) ;
102-
103- it ( 'should return 200 with errors' , async ( ) => {
104- await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
105- await supertest
106- . post ( '/api/saved_objects/_bulk_create' )
107- . send ( BULK_REQUESTS )
108- . expect ( 200 )
109- . then ( ( resp ) => {
110- expect ( resp . body ) . to . eql ( {
111- saved_objects : [
112- {
113- id : BULK_REQUESTS [ 0 ] . id ,
114- type : BULK_REQUESTS [ 0 ] . type ,
115- error : {
116- error : 'Internal Server Error' ,
117- message : 'An internal server error occurred' ,
118- statusCode : 500 ,
119- } ,
73+ migrationVersion : {
74+ dashboard : resp . body . saved_objects [ 1 ] . migrationVersion . dashboard ,
12075 } ,
121- {
122- id : BULK_REQUESTS [ 1 ] . id ,
123- type : BULK_REQUESTS [ 1 ] . type ,
124- error : {
125- error : 'Internal Server Error' ,
126- message : 'An internal server error occurred' ,
127- statusCode : 500 ,
128- } ,
129- } ,
130- ] ,
131- } ) ;
76+ coreMigrationVersion : KIBANA_VERSION ,
77+ references : [ ] ,
78+ namespaces : [ SPACE_ID ] ,
79+ } ,
80+ ] ,
13281 } ) ;
133- } ) ;
134- } ) ;
82+ } ) ) ;
83+
84+ it ( 'should not return raw id when object id is unspecified' , async ( ) =>
85+ await supertest
86+ . post ( `/s/${ SPACE_ID } /api/saved_objects/_bulk_create` )
87+ . send ( BULK_REQUESTS . map ( ( { id, ...rest } ) => rest ) )
88+ . expect ( 200 )
89+ . then ( ( resp ) => {
90+ resp . body . saved_objects . map ( ( { id } : { id : string } ) =>
91+ expect ( id ) . not . match ( / v i s u a l i z a t i o n | d a s h b o a r d / )
92+ ) ;
93+ } ) ) ;
13594 } ) ;
13695}
0 commit comments