()
| 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', { |
nothing calls this directly
no test coverage detected