@@ -5,6 +5,12 @@ import { TestExtensionContext } from '../stubs';
5
5
import { StorageController } from '../../../storage' ;
6
6
import TelemetryService from '../../../telemetry/telemetryService' ;
7
7
import { StatusView } from '../../../views' ;
8
+ import { ObjectId } from 'bson' ;
9
+ import { afterEach } from 'mocha' ;
10
+
11
+ import sinon from 'sinon' ;
12
+
13
+ import * as util from 'util' ;
8
14
9
15
suite ( 'Edit Document Code Lens Provider Test Suite' , ( ) => {
10
16
const mockExtensionContext = new TestExtensionContext ( ) ;
@@ -20,6 +26,10 @@ suite('Edit Document Code Lens Provider Test Suite', () => {
20
26
testTelemetryService
21
27
) ;
22
28
29
+ afterEach ( ( ) => {
30
+ sinon . restore ( ) ;
31
+ } ) ;
32
+
23
33
test ( 'provideCodeLenses returns an empty array if codeLensesInfo is empty' , ( ) => {
24
34
const testCodeLensProvider = new EditDocumentCodeLensProvider (
25
35
testConnectionController
@@ -30,6 +40,72 @@ suite('Edit Document Code Lens Provider Test Suite', () => {
30
40
assert ( codeLens . length === 0 ) ;
31
41
} ) ;
32
42
43
+ test ( 'the _updateCodeLensesForCursor function deserialize document id' , ( ) => {
44
+ const testCodeLensProvider = new EditDocumentCodeLensProvider (
45
+ testConnectionController
46
+ ) ;
47
+ const ejsinId = { $oid : '5d973ae744376d2aae72a160' } ;
48
+ const playgroundResult = {
49
+ content : [ {
50
+ _id : ejsinId ,
51
+ name : 'test name'
52
+ } ] ,
53
+ namespace : 'db.coll' ,
54
+ source : 'playground'
55
+ } ;
56
+
57
+ const mockActiveConnectionId = sinon . fake . returns ( 'tasty_sandwhich' ) ;
58
+ sinon . replace (
59
+ testCodeLensProvider . _connectionController ,
60
+ 'getActiveConnectionId' ,
61
+ mockActiveConnectionId
62
+ ) ;
63
+
64
+ const result = testCodeLensProvider . _updateCodeLensesForCursor ( playgroundResult ) ;
65
+
66
+ assert ( ! ! result ) ;
67
+ const codeLensesInfo = result [ 0 ] ;
68
+ assert ( ! ! codeLensesInfo ) ;
69
+ assert ( ! ! codeLensesInfo . documentId ) ;
70
+ const bsonId = new ObjectId ( '5d973ae744376d2aae72a160' ) ;
71
+
72
+ assert ( util . inspect ( codeLensesInfo . documentId ) !== util . inspect ( ejsinId ) ) ;
73
+ assert ( util . inspect ( codeLensesInfo . documentId ) === util . inspect ( bsonId ) ) ;
74
+ } ) ;
75
+
76
+ test ( 'the _updateCodeLensesForDocument function deserialize document id' , ( ) => {
77
+ const testCodeLensProvider = new EditDocumentCodeLensProvider (
78
+ testConnectionController
79
+ ) ;
80
+ const ejsinId = { $oid : '5d973ae744376d2aae72a160' } ;
81
+ const playgroundResult = {
82
+ content : {
83
+ _id : ejsinId ,
84
+ name : 'test name'
85
+ } ,
86
+ namespace : 'db.coll' ,
87
+ source : 'playground'
88
+ } ;
89
+
90
+ const mockActiveConnectionId = sinon . fake . returns ( 'tasty_sandwhich' ) ;
91
+ sinon . replace (
92
+ testCodeLensProvider . _connectionController ,
93
+ 'getActiveConnectionId' ,
94
+ mockActiveConnectionId
95
+ ) ;
96
+
97
+ const result = testCodeLensProvider . _updateCodeLensesForDocument ( playgroundResult ) ;
98
+
99
+ assert ( ! ! result ) ;
100
+ const codeLensesInfo = result [ 0 ] ;
101
+ assert ( ! ! codeLensesInfo ) ;
102
+ assert ( ! ! codeLensesInfo . documentId ) ;
103
+ const bsonId = new ObjectId ( '5d973ae744376d2aae72a160' ) ;
104
+
105
+ assert ( util . inspect ( codeLensesInfo . documentId ) !== util . inspect ( ejsinId ) ) ;
106
+ assert ( util . inspect ( codeLensesInfo . documentId ) === util . inspect ( bsonId ) ) ;
107
+ } ) ;
108
+
33
109
suite ( 'after updateCodeLensesForPlayground' , ( ) => {
34
110
test ( 'provideCodeLenses returns one code lens when result is a single document' , ( ) => {
35
111
const testCodeLensProvider = new EditDocumentCodeLensProvider (
0 commit comments