@@ -146,7 +146,7 @@ suite('Code Action Provider Test Suite', function () {
146
146
expect ( codeActions ) . to . exist ;
147
147
148
148
if ( codeActions ) {
149
- expect ( codeActions . length ) . to . be . equal ( 5 ) ;
149
+ expect ( codeActions . length ) . to . be . equal ( 6 ) ;
150
150
const actionCommand = codeActions [ 2 ] . command ;
151
151
152
152
if ( actionCommand ) {
@@ -178,7 +178,7 @@ suite('Code Action Provider Test Suite', function () {
178
178
expect ( codeActions ) . to . exist ;
179
179
180
180
if ( codeActions ) {
181
- expect ( codeActions . length ) . to . be . equal ( 5 ) ;
181
+ expect ( codeActions . length ) . to . be . equal ( 6 ) ;
182
182
const actionCommand = codeActions [ 2 ] . command ;
183
183
184
184
if ( actionCommand ) {
@@ -227,7 +227,7 @@ suite('Code Action Provider Test Suite', function () {
227
227
expect ( codeActions ) . to . exist ;
228
228
229
229
if ( codeActions ) {
230
- expect ( codeActions . length ) . to . be . equal ( 5 ) ;
230
+ expect ( codeActions . length ) . to . be . equal ( 6 ) ;
231
231
const actionCommand = codeActions [ 3 ] . command ;
232
232
233
233
if ( actionCommand ) {
@@ -280,7 +280,7 @@ suite('Code Action Provider Test Suite', function () {
280
280
expect ( codeActions ) . to . exist ;
281
281
282
282
if ( codeActions ) {
283
- expect ( codeActions . length ) . to . be . equal ( 5 ) ;
283
+ expect ( codeActions . length ) . to . be . equal ( 6 ) ;
284
284
const actionCommand = codeActions [ 1 ] . command ;
285
285
286
286
if ( actionCommand ) {
@@ -312,6 +312,64 @@ suite('Code Action Provider Test Suite', function () {
312
312
language : 'python'
313
313
} ;
314
314
315
+ expect ( mdbTestExtension . testExtensionController . _playgroundController . _playgroundResult ) . to . be . deep . equal ( expectedResult ) ;
316
+ }
317
+ }
318
+ } ) ;
319
+ test ( 'exports to ruby and includes driver syntax' , async ( ) => {
320
+ const textFromEditor = "use('db'); db.coll.find({ name: '22' })" ;
321
+ const selection = {
322
+ start : { line : 0 , character : 24 } ,
323
+ end : { line : 0 , character : 38 }
324
+ } as vscode . Selection ;
325
+ const mode = ExportToLanguageMode . QUERY ;
326
+ const activeTextEditor = { document : { getText : ( ) => textFromEditor } } as vscode . TextEditor ;
327
+
328
+ mdbTestExtension . testExtensionController . _playgroundController . _selectedText = "{ name: '22' }" ;
329
+ mdbTestExtension . testExtensionController . _playgroundController . _codeActionProvider . selection = selection ;
330
+ mdbTestExtension . testExtensionController . _playgroundController . _codeActionProvider . mode = mode ;
331
+ mdbTestExtension . testExtensionController . _playgroundController . _activeTextEditor = activeTextEditor ;
332
+
333
+ const testCodeActionProvider = new CodeActionProvider ( ) ;
334
+ testCodeActionProvider . refresh ( { selection, mode } ) ;
335
+
336
+ const codeActions = testCodeActionProvider . provideCodeActions ( ) ;
337
+
338
+ expect ( codeActions ) . to . exist ;
339
+
340
+ if ( codeActions ) {
341
+ expect ( codeActions . length ) . to . be . equal ( 6 ) ;
342
+ const actionCommand = codeActions [ 5 ] . command ;
343
+
344
+ if ( actionCommand ) {
345
+ expect ( actionCommand . command ) . to . be . equal ( 'mdb.exportToRuby' ) ;
346
+ expect ( actionCommand . title ) . to . be . equal ( 'Export To Ruby' ) ;
347
+
348
+ await vscode . commands . executeCommand ( actionCommand . command ) ;
349
+
350
+ let expectedResult : PlaygroundResult = {
351
+ namespace : 'DATABASE_NAME.COLLECTION_NAME' ,
352
+ type : null ,
353
+ content : "{\n 'name' => '22'\n}" ,
354
+ language : 'ruby'
355
+ } ;
356
+ expect ( mdbTestExtension . testExtensionController . _playgroundController . _playgroundResult ) . to . be . deep . equal ( expectedResult ) ;
357
+
358
+ const codeLenses = mdbTestExtension . testExtensionController . _playgroundController . _exportToLanguageCodeLensProvider . provideCodeLenses ( ) ;
359
+ expect ( codeLenses . length ) . to . be . equal ( 2 ) ;
360
+
361
+ await vscode . commands . executeCommand ( 'mdb.changeExportToLanguageAddons' , {
362
+ ...mdbTestExtension . testExtensionController . _playgroundController . _exportToLanguageCodeLensProvider . _exportToLanguageAddons ,
363
+ driverSyntax : true
364
+ } ) ;
365
+
366
+ expectedResult = {
367
+ namespace : 'db.coll' ,
368
+ type : null ,
369
+ content : "# Requires the MongoDB Ruby Driver\n# https://docs.mongodb.com/ruby-driver/master/\n\nclient = Mongo::Client.new('mongodb://localhost:27018/?appname=mongodb-vscode+0.0.0-dev.0', :database => 'db')\n\nresult = client.database['coll'].find({\n 'name' => '22'\n})" ,
370
+ language : 'ruby'
371
+ } ;
372
+
315
373
expect ( mdbTestExtension . testExtensionController . _playgroundController . _playgroundResult ) . to . be . deep . equal ( expectedResult ) ;
316
374
}
317
375
}
0 commit comments