File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
packages/compass-import-export/src/import Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,52 @@ describe('importJSON', function () {
162162 }
163163 }
164164
165+ it ( 'imports a file with a document field' , async function ( ) {
166+ const lines : string [ ] = [ JSON . stringify ( { document : 1 } ) ] ;
167+
168+ const progressCallback = sinon . spy ( ) ;
169+
170+ const ns = 'db.col' ;
171+
172+ const output = temp . createWriteStream ( ) ;
173+
174+ const result = await importJSON ( {
175+ dataService,
176+ ns,
177+ input : Readable . from ( lines . join ( '\n' ) ) ,
178+ output,
179+ progressCallback,
180+ jsonVariant : 'jsonl' ,
181+ } ) ;
182+
183+ expect ( result ) . to . deep . equal ( {
184+ docsProcessed : 1 ,
185+ docsWritten : 1 ,
186+ dbErrors : [ ] ,
187+ dbStats : {
188+ nInserted : 1 ,
189+ nMatched : 0 ,
190+ nModified : 0 ,
191+ nRemoved : 0 ,
192+ nUpserted : 0 ,
193+ ok : 1 ,
194+ writeConcernErrors : [ ] ,
195+ writeErrors : [ ] ,
196+ } ,
197+ } ) ;
198+
199+ const docs : any [ ] = await dataService . find ( ns , { } ) ;
200+
201+ expect ( docs ) . to . have . length ( 1 ) ;
202+
203+ for ( const doc of docs ) {
204+ delete doc . _id ;
205+ expect ( doc ) . to . deep . equal ( { document : 1 } ) ;
206+ }
207+
208+ expect ( progressCallback . callCount ) . to . equal ( 1 ) ;
209+ } ) ;
210+
165211 it ( 'imports a file containing multiple batches' , async function ( ) {
166212 const lines : string [ ] = [ ] ;
167213 for ( let i = 0 ; i < 2000 ; i ++ ) {
You can’t perform that action at this time.
0 commit comments