|
| 1 | +const sinon = require('sinon'); |
| 2 | + |
| 3 | +const cloudinary = require('../../../../lib/cloudinary'); |
| 4 | +const api_http = require("https"); |
| 5 | +const ClientRequest = require('_http_client').ClientRequest; |
| 6 | + |
| 7 | +describe('Admin API - Config', () => { |
| 8 | + const mocked = {}; |
| 9 | + |
| 10 | + beforeEach(function () { |
| 11 | + mocked.xhr = sinon.useFakeXMLHttpRequest(); |
| 12 | + mocked.write = sinon.spy(ClientRequest.prototype, 'write'); |
| 13 | + mocked.request = sinon.spy(api_http, 'request'); |
| 14 | + }); |
| 15 | + |
| 16 | + afterEach(function () { |
| 17 | + mocked.request.restore(); |
| 18 | + mocked.write.restore(); |
| 19 | + mocked.xhr.restore(); |
| 20 | + }); |
| 21 | + |
| 22 | + describe('config', () => { |
| 23 | + it('should send a request to config endpoint', () => { |
| 24 | + cloudinary.v2.api.config(); |
| 25 | + |
| 26 | + sinon.assert.calledWith(mocked.request, sinon.match({ |
| 27 | + pathname: sinon.match('config'), |
| 28 | + method: sinon.match('GET'), |
| 29 | + query: sinon.match('') |
| 30 | + })); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should send a request to config endpoint with optional parameters', () => { |
| 34 | + cloudinary.v2.api.config({ settings: true }); |
| 35 | + |
| 36 | + sinon.assert.calledWith(mocked.request, sinon.match({ |
| 37 | + pathname: sinon.match('config'), |
| 38 | + method: sinon.match('GET'), |
| 39 | + query: sinon.match('settings=true') |
| 40 | + })); |
| 41 | + }); |
| 42 | + }); |
| 43 | +}); |
0 commit comments