MCPcopy
hub / github.com/mongodb/node-mongodb-native / test

Function test

test/integration/gridfs/gridfs_stream.test.ts:32–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30 metadata: { requires: { topology: ['single'] } },
31
32 async test() {
33 const bucket = new GridFSBucket(db);
34 const readStream = fs.createReadStream('./LICENSE.md');
35 const uploadStream = bucket.openUploadStream('test.dat');
36
37 const license = fs.readFileSync('./LICENSE.md');
38 const id = uploadStream.id;
39
40 await pipeline(readStream, uploadStream);
41
42 const chunksCollection = db.collection('fs.chunks');
43 const filesCollection = db.collection('fs.files');
44
45 // Get all the chunks
46 const chunks = await chunksCollection.find({ files_id: id }).toArray();
47 expect(chunks.length).to.equal(1);
48 expect(chunks[0].data.toString('hex')).to.equal(license.toString('hex'));
49
50 // Get all the files
51 const files = await filesCollection.find({ _id: id }).toArray();
52 expect(files.length).to.equal(1);
53 expect(files[0]).to.not.have.property('md5');
54
55 // Make sure we created indexes
56 const chunkIndexes = await chunksCollection.listIndexes().toArray();
57 expect(chunkIndexes.length).to.equal(2);
58 expect(chunkIndexes[1].name).to.equal('files_id_1_n_1');
59
60 const fileIndexes = await filesCollection.listIndexes().toArray();
61 expect(fileIndexes.length).to.equal(2);
62 expect(fileIndexes[1].name).to.equal('filename_1_uploadDate_1');
63 }
64 });
65
66 it('.destroy() publishes provided error', {

Callers

nothing calls this directly

Calls 15

openUploadStreamMethod · 0.95
openDownloadStreamMethod · 0.95
deleteMethod · 0.95
findMethod · 0.95
renameMethod · 0.95
onceFunction · 0.85
finishedFunction · 0.85
toArrayMethod · 0.80
listIndexesMethod · 0.80
countDocumentsMethod · 0.80

Tested by

no test coverage detected