()
| 30 | metadata: { requires: { topology: [class="st">'single'] } }, |
| 31 | |
| 32 | async test() { |
| 33 | const bucket = new GridFSBucket(db); |
| 34 | const readStream = fs.createReadStream(class="st">'./LICENSE.md'); |
| 35 | const uploadStream = bucket.openUploadStream(class="st">'test.dat'); |
| 36 | |
| 37 | const license = fs.readFileSync(class="st">'./LICENSE.md'); |
| 38 | const id = uploadStream.id; |
| 39 | |
| 40 | await pipeline(readStream, uploadStream); |
| 41 | |
| 42 | const chunksCollection = db.collection(class="st">'fs.chunks'); |
| 43 | const filesCollection = db.collection(class="st">'fs.files'); |
| 44 | |
| 45 | class="cm">// 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(class="st">'hex')).to.equal(license.toString(class="st">'hex')); |
| 49 | |
| 50 | class="cm">// 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(class="st">'md5'); |
| 54 | |
| 55 | class="cm">// 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(class="st">'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(class="st">'filename_1_uploadDate_1'); |
| 63 | } |
| 64 | }); |
| 65 | |
| 66 | it(class="st">'.destroy() publishes provided error', { |
nothing calls this directly
no test coverage detected