Skip to content

Commit f4de1fb

Browse files
committed
add the test for handling stream errors
1 parent fe83a76 commit f4de1fb

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

spec/test.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,44 @@ describe('S3Adapter tests', () => {
304304
expect(resp.end).not.toHaveBeenCalled();
305305
});
306306
});
307+
308+
it('should handle stream errors', async () => {
309+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket');
310+
const s3ClientMock = jasmine.createSpyObj('S3Client', ['send']);
311+
312+
const mockStream = {
313+
on: (event, callback) => {
314+
if (event === 'error') {
315+
callback(new Error('Mock S3 Body error'));
316+
}
317+
},
318+
};
319+
320+
s3ClientMock.send.and.returnValue(Promise.resolve({
321+
Body: mockStream,
322+
AcceptRanges: 'bytes',
323+
ContentLength: 1024,
324+
ContentRange: 'bytes 0-1024/2048',
325+
ContentType: 'application/octet-stream',
326+
}));
327+
s3._s3Client = s3ClientMock;
328+
329+
const mockReq = {
330+
get: () => 'bytes=0-1024',
331+
};
332+
const mockRes = {
333+
status: jasmine.createSpy('status'),
334+
send: jasmine.createSpy('send'),
335+
writeHead: jasmine.createSpy('writeHead'),
336+
write: jasmine.createSpy('write'),
337+
end: jasmine.createSpy('end'),
338+
};
339+
340+
s3.handleFileStream('test.mov', mockReq, mockRes).catch(() => {
341+
expect(mockRes.status).toHaveBeenCalledWith(404);
342+
expect(mockRes.send).toHaveBeenCalledWith('Mock S3 Body error');
343+
});
344+
});
307345
});
308346

309347
describe('getFileLocation with directAccess', () => {

0 commit comments

Comments
 (0)