@smartsoft001/mongo 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -196,54 +196,63 @@ describe('shared-mongo: MongoAttachmentRepository', () => {
|
|
|
196
196
|
expect(result).toBeNull(); // Expect null if no file is found
|
|
197
197
|
});
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
199
|
+
it('upload() should call MongoClient.connect with correct URL', async () => {
|
|
200
|
+
const mockUrl = 'mock-url';
|
|
201
|
+
jest.spyOn(model as any, 'getUrl').mockImplementation(() => mockUrl);
|
|
202
|
+
const mockStream = new Readable();
|
|
203
|
+
mockStream._read = jest.fn();
|
|
204
|
+
data.stream = mockStream;
|
|
205
|
+
model.upload(data);
|
|
206
|
+
expect(MongoClient.connect).toHaveBeenCalledWith(mockUrl);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('upload() should resolve the upload promise', async () => {
|
|
210
|
+
const mockUrl = 'mock-url';
|
|
211
|
+
jest.spyOn(model as any, 'getUrl').mockImplementation(() => mockUrl);
|
|
212
|
+
const mockStream = new Readable();
|
|
213
|
+
mockStream._read = jest.fn();
|
|
214
|
+
data.stream = mockStream;
|
|
215
|
+
const result = model.upload(data);
|
|
216
|
+
await expect(result).resolves.toBeUndefined();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('upload() should call GridFSBucket and openUploadStreamWithId', async () => {
|
|
220
|
+
const mockUrl = 'mock-url';
|
|
221
|
+
jest.spyOn(model as any, 'getUrl').mockImplementation(() => mockUrl);
|
|
222
|
+
const mockStream = new Readable();
|
|
223
|
+
mockStream._read = jest.fn();
|
|
224
|
+
data.stream = mockStream;
|
|
225
|
+
await model.upload(data);
|
|
226
|
+
expect(GridFSBucket).toHaveBeenCalledWith(expect.anything(), {
|
|
227
|
+
bucketName: mockConfig.collection,
|
|
228
|
+
});
|
|
229
|
+
expect(mockOpenUploadStreamWithId).toHaveBeenCalledWith(
|
|
230
|
+
data.id,
|
|
231
|
+
data.fileName,
|
|
232
|
+
{
|
|
233
|
+
contentType: data.mimeType,
|
|
234
|
+
},
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('upload() should call streamCallback if provided', async () => {
|
|
239
|
+
const mockUrl = 'mock-url';
|
|
240
|
+
jest.spyOn(model as any, 'getUrl').mockImplementation(() => mockUrl);
|
|
241
|
+
const mockStream = new Readable();
|
|
242
|
+
mockStream._read = jest.fn();
|
|
243
|
+
data.stream = mockStream;
|
|
244
|
+
await model.upload(data, options);
|
|
245
|
+
expect(options.streamCallback).toHaveBeenCalled();
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('upload() should call pipe of the provided data stream', async () => {
|
|
249
|
+
const mockUrl = 'mock-url';
|
|
250
|
+
jest.spyOn(model as any, 'getUrl').mockImplementation(() => mockUrl);
|
|
251
|
+
const mockStream = new Readable();
|
|
252
|
+
mockStream._read = jest.fn();
|
|
253
|
+
mockStream.pipe = jest.fn();
|
|
254
|
+
data.stream = mockStream;
|
|
255
|
+
await model.upload(data);
|
|
256
|
+
expect(mockStream.pipe).toHaveBeenCalled();
|
|
257
|
+
});
|
|
249
258
|
});
|