Skip to content

Commit ed30b21

Browse files
authored
chore: regression test for documents containing the field document (#4547)
regression test for documents containing the field document
1 parent ffb00c7 commit ed30b21

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

packages/compass-import-export/src/import/import-json.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff 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++) {

0 commit comments

Comments
 (0)