-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(request): use options.request if provided
- Loading branch information
rstachof
committed
Oct 30, 2024
1 parent
1950a41
commit 48ecb76
Showing
6 changed files
with
104 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {assert} from '@webex/test-helper-chai'; | ||
import sinon from 'sinon'; | ||
import {EventEmitter} from 'events'; | ||
import request from '@webex/http-core/src/request'; | ||
import * as requestModule from '../../../../src/request/request'; | ||
import * as utils from '../../../../src/request/utils'; | ||
|
||
describe('request', () => { | ||
let interceptStub; | ||
let requestStub; | ||
|
||
beforeEach(() => { | ||
interceptStub = sinon.spy(utils, 'intercept'); | ||
requestStub = sinon.stub(requestModule, 'default'); | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('should modify options and call _request if no custom request function is provided', async () => { | ||
const options = { | ||
url: 'http://example.com', | ||
headers: {}, | ||
interceptors: [], | ||
}; | ||
|
||
requestStub.resolves('response'); | ||
|
||
const result = await request(options); | ||
|
||
assert.strictEqual(result, 'response'); | ||
assert.strictEqual(options.uri, 'http://example.com'); | ||
assert.isNull(options.url); | ||
assert.deepEqual(options.headers, {}); | ||
assert.instanceOf(options.download, EventEmitter); | ||
assert.instanceOf(options.upload, EventEmitter); | ||
assert.isTrue(interceptStub.calledTwice); | ||
assert.isTrue(requestStub.calledOnceWith(options)); | ||
}); | ||
|
||
it('should use custom request function if provided', async () => { | ||
const customRequest = sinon.stub().resolves('custom response'); | ||
const options = { | ||
url: 'http://example.com', | ||
headers: {}, | ||
interceptors: [], | ||
request: customRequest, | ||
}; | ||
|
||
const result = await request(options); | ||
|
||
assert.strictEqual(result, 'custom response'); | ||
assert.isTrue(customRequest.calledOnceWith(options)); | ||
assert.isTrue(interceptStub.calledTwice); | ||
assert.isFalse(requestStub.called); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters