@@ -87,6 +87,57 @@ suite('MongoDB Document Service Test Suite', () => {
87
87
expect ( document ) . to . be . deep . equal ( newDocument ) ;
88
88
} ) ;
89
89
90
+ test ( 'replaceDocument calls findOneAndReplace and saves a document when connected - extending the uuid type' , async ( ) => {
91
+ const namespace = 'waffle.house' ;
92
+ const connectionId = 'tasty_sandwhich' ;
93
+ const documentId = '93333a0d-83f6-4e6f-a575-af7ea6187a4a' ;
94
+ const document : { _id : string ; myUuid ?: { $uuid : string } } = {
95
+ _id : '123' ,
96
+ } ;
97
+ const newDocument = {
98
+ _id : '123' ,
99
+ myUuid : {
100
+ $binary : {
101
+ base64 : 'yO2rw/c4TKO2jauSqRR4ow==' ,
102
+ subType : '04' ,
103
+ } ,
104
+ } ,
105
+ } ;
106
+ const source = DocumentSource . DOCUMENT_SOURCE_TREEVIEW ;
107
+
108
+ const fakeActiveConnectionId = sandbox . fake . returns ( 'tasty_sandwhich' ) ;
109
+ sandbox . replace (
110
+ testConnectionController ,
111
+ 'getActiveConnectionId' ,
112
+ fakeActiveConnectionId
113
+ ) ;
114
+
115
+ const fakeGetActiveDataService = sandbox . fake . returns ( {
116
+ findOneAndReplace : ( ) => {
117
+ document . myUuid = { $uuid : 'c8edabc3-f738-4ca3-b68d-ab92a91478a3' } ;
118
+
119
+ return Promise . resolve ( document ) ;
120
+ } ,
121
+ } ) ;
122
+ sandbox . replace (
123
+ testConnectionController ,
124
+ 'getActiveDataService' ,
125
+ fakeGetActiveDataService
126
+ ) ;
127
+ sandbox . stub ( testStatusView , 'showMessage' ) ;
128
+ sandbox . stub ( testStatusView , 'hideMessage' ) ;
129
+
130
+ await testMongoDBDocumentService . replaceDocument ( {
131
+ namespace,
132
+ documentId,
133
+ connectionId,
134
+ newDocument,
135
+ source,
136
+ } ) ;
137
+
138
+ expect ( document ) . to . be . deep . equal ( document ) ;
139
+ } ) ;
140
+
90
141
test ( 'fetchDocument calls find and returns a single document when connected' , async ( ) => {
91
142
const namespace = 'waffle.house' ;
92
143
const connectionId = 'tasty_sandwhich' ;
@@ -97,7 +148,7 @@ suite('MongoDB Document Service Test Suite', () => {
97
148
98
149
const fakeGetActiveDataService = sandbox . fake . returns ( {
99
150
find : ( ) => {
100
- return Promise . resolve ( [ { _id : '123' } ] ) ;
151
+ return Promise . resolve ( documents ) ;
101
152
} ,
102
153
} ) ;
103
154
sandbox . replace (
@@ -124,7 +175,60 @@ suite('MongoDB Document Service Test Suite', () => {
124
175
source,
125
176
} ) ;
126
177
127
- expect ( result ) . to . be . deep . equal ( JSON . parse ( EJSON . stringify ( documents [ 0 ] ) ) ) ;
178
+ expect ( result ) . to . be . deep . equal ( EJSON . serialize ( documents [ 0 ] ) ) ;
179
+ } ) ;
180
+
181
+ test ( 'fetchDocument calls find and returns a single document when connected - simplifying the uuid type' , async ( ) => {
182
+ const namespace = 'waffle.house' ;
183
+ const connectionId = 'tasty_sandwhich' ;
184
+ const documentId = '93333a0d-83f6-4e6f-a575-af7ea6187a4a' ;
185
+ const line = 1 ;
186
+ const documents = [
187
+ {
188
+ _id : '123' ,
189
+ myUuid : {
190
+ $binary : {
191
+ base64 : 'yO2rw/c4TKO2jauSqRR4ow==' ,
192
+ subType : '04' ,
193
+ } ,
194
+ } ,
195
+ } ,
196
+ ] ;
197
+ const source = DocumentSource . DOCUMENT_SOURCE_PLAYGROUND ;
198
+
199
+ const fakeGetActiveDataService = sandbox . fake . returns ( {
200
+ find : ( ) => {
201
+ return Promise . resolve ( documents ) ;
202
+ } ,
203
+ } ) ;
204
+ sandbox . replace (
205
+ testConnectionController ,
206
+ 'getActiveDataService' ,
207
+ fakeGetActiveDataService
208
+ ) ;
209
+
210
+ const fakeGetActiveConnectionId = sandbox . fake . returns ( connectionId ) ;
211
+ sandbox . replace (
212
+ testConnectionController ,
213
+ 'getActiveConnectionId' ,
214
+ fakeGetActiveConnectionId
215
+ ) ;
216
+
217
+ sandbox . stub ( testStatusView , 'showMessage' ) ;
218
+ sandbox . stub ( testStatusView , 'hideMessage' ) ;
219
+
220
+ const result = await testMongoDBDocumentService . fetchDocument ( {
221
+ namespace,
222
+ documentId,
223
+ line,
224
+ connectionId,
225
+ source,
226
+ } ) ;
227
+
228
+ expect ( result ) . to . be . deep . equal ( {
229
+ _id : '123' ,
230
+ myUuid : { $uuid : 'c8edabc3-f738-4ca3-b68d-ab92a91478a3' } ,
231
+ } ) ;
128
232
} ) ;
129
233
130
234
test ( "if a user is not connected, documents won't be saved to MongoDB" , async ( ) => {
0 commit comments