|
| 1 | +const sinon = require('sinon'); |
| 2 | +const cloudinary = require('../../../../lib/cloudinary'); |
| 3 | +const helper = require('../../../spechelper'); |
| 4 | +const ClientRequest = require('_http_client').ClientRequest; |
| 5 | + |
| 6 | +describe('Uploader', () => { |
| 7 | + let spy; |
| 8 | + let xhr; |
| 9 | + |
| 10 | + before(() => { |
| 11 | + xhr = sinon.useFakeXMLHttpRequest(); |
| 12 | + spy = sinon.spy(ClientRequest.prototype, 'write'); |
| 13 | + }); |
| 14 | + |
| 15 | + after(() => { |
| 16 | + spy.restore(); |
| 17 | + xhr.restore(); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('upload', () => { |
| 21 | + it('should send a request with auto_transcription set to true if requested', () => { |
| 22 | + cloudinary.v2.uploader.upload('irrelevant', { auto_transcription: true }); |
| 23 | + sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '1'))); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should send a request with auto_transcription config if requested', () => { |
| 27 | + cloudinary.v2.uploader.upload('irrelevant', { auto_transcription: { translate: ['pl'] } }); |
| 28 | + sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '{"translate":["pl"]}'))); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('explicit', () => { |
| 33 | + it('should send a request with auto_transcription set to true if requested', () => { |
| 34 | + cloudinary.v2.uploader.explicit('irrelevant', { auto_transcription: true }); |
| 35 | + sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '1'))); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should send a request with auto_transcription config if requested', () => { |
| 39 | + cloudinary.v2.uploader.explicit('irrelevant', { auto_transcription: { translate: ['pl'] } }); |
| 40 | + sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '{"translate":["pl"]}'))); |
| 41 | + }); |
| 42 | + }); |
| 43 | +}); |
0 commit comments