@@ -10,9 +10,18 @@ describe('RestController', function() {
10
10
this . AlertService = $injector . get ( 'AlertService' ) ;
11
11
this . ModalService = $injector . get ( 'ModalService' ) ;
12
12
this . AceEditorService = $injector . get ( 'AceEditorService' ) ;
13
+ this . ClipboardService = $injector . get ( 'ClipboardService' ) ;
13
14
this . createController = function ( ) {
14
15
return $controller ( 'RestController' ,
15
- { $scope : this . scope } , this . $http , this . $window , this . RestDataService , this . AlertService , this . ModalService , this . AceEditorService ) ;
16
+ { $scope : this . scope } ,
17
+ this . $http ,
18
+ this . $window ,
19
+ this . RestDataService ,
20
+ this . AlertService ,
21
+ this . ModalService ,
22
+ this . AceEditorService ,
23
+ this . ClipboardService
24
+ ) ;
16
25
} ;
17
26
this . _controller = this . createController ( ) ;
18
27
} ) ) ;
@@ -129,7 +138,7 @@ describe('RestController', function() {
129
138
it ( 'loads all possible autocompletion options' , function ( ) {
130
139
this . scope . indices = [ ] ;
131
140
this . scope . updateOptions ( "" ) ;
132
- expect ( this . scope . options ) . toEqual ( [ '_msearch' , '_search' , '_suggest' ] ) ;
141
+ expect ( this . scope . options ) . toEqual ( [ '_msearch' , '_search' ] ) ;
133
142
} ) ;
134
143
it ( 'skip autocompletion if indices is absent' , function ( ) {
135
144
this . scope . indices = undefined ;
@@ -183,4 +192,64 @@ describe('RestController', function() {
183
192
} ) ;
184
193
} ) ;
185
194
195
+ describe ( 'copyAsCURLCommand' , function ( ) {
196
+ it ( 'copy json call to clipboard' , function ( ) {
197
+ this . scope . path = 'wot/_search' ;
198
+ this . scope . method = 'GET' ;
199
+ this . scope . host = 'http://localhost:9200' ;
200
+ this . scope . editor = { getValue : function ( ) { } } ;
201
+ spyOn ( this . scope . editor , 'getValue' ) . and . returnValue ( { 'k' : 'v' } ) ;
202
+ spyOn ( this . ClipboardService , 'copy' ) ;
203
+ this . scope . copyAsCURLCommand ( ) ;
204
+ expect ( this . scope . editor . getValue ) . toHaveBeenCalled ( ) ;
205
+ expect ( this . ClipboardService . copy ) . toHaveBeenCalledWith (
206
+ 'curl -H \'Content-type: application/json\' -XGET \'http://localhost:9200/wot/_search\'' ,
207
+ jasmine . any ( Function ) ,
208
+ jasmine . any ( Function )
209
+ ) ;
210
+ } ) ;
211
+
212
+ it ( 'copy x-ndjson call to clipboard for _bulk' , function ( ) {
213
+ this . scope . path = 'wot/_bulk' ;
214
+ this . scope . method = 'POST' ;
215
+ this . scope . host = 'http://localhost:9200' ;
216
+ this . scope . editor = { getStringValue : function ( ) { } } ;
217
+ var body = '{"header": ""}\n{"query": "query"}\n{"header": ""}\n{"query": "query"}\n' ;
218
+ spyOn ( this . scope . editor , 'getStringValue' ) . and . returnValue ( body ) ;
219
+ spyOn ( this . ClipboardService , 'copy' ) ;
220
+ this . scope . copyAsCURLCommand ( ) ;
221
+ expect ( this . scope . editor . getStringValue ) . toHaveBeenCalled ( ) ;
222
+ expect ( this . ClipboardService . copy ) . toHaveBeenCalledWith (
223
+ 'curl -H \'Content-type: application/x-ndjson\' -XPOST \'http://localhost:9200/wot/_bulk\' -d \'{"header":""}\n' +
224
+ '{"query":"query"}\n' +
225
+ '{"header":""}\n' +
226
+ '{"query":"query"}\n' +
227
+ '\n\'' ,
228
+ jasmine . any ( Function ) ,
229
+ jasmine . any ( Function )
230
+ ) ;
231
+ } ) ;
232
+
233
+ it ( 'copy x-ndjson call to clipboard for _msearch' , function ( ) {
234
+ this . scope . path = 'wot/_msearch' ;
235
+ this . scope . method = 'POST' ;
236
+ this . scope . host = 'http://localhost:9200' ;
237
+ this . scope . editor = { getStringValue : function ( ) { } } ;
238
+ var body = '{"header": ""}\n{"query": "query"}\n{"header": ""}\n{"query": "query"}\n' ;
239
+ spyOn ( this . scope . editor , 'getStringValue' ) . and . returnValue ( body ) ;
240
+ spyOn ( this . ClipboardService , 'copy' ) ;
241
+ this . scope . copyAsCURLCommand ( ) ;
242
+ expect ( this . scope . editor . getStringValue ) . toHaveBeenCalled ( ) ;
243
+ expect ( this . ClipboardService . copy ) . toHaveBeenCalledWith (
244
+ 'curl -H \'Content-type: application/x-ndjson\' -XPOST \'http://localhost:9200/wot/_msearch\' -d \'{"header":""}\n' +
245
+ '{"query":"query"}\n' +
246
+ '{"header":""}\n' +
247
+ '{"query":"query"}\n' +
248
+ '\n\'' ,
249
+ jasmine . any ( Function ) ,
250
+ jasmine . any ( Function )
251
+ ) ;
252
+ } ) ;
253
+ } ) ;
254
+
186
255
} ) ;
0 commit comments