fix(requestInterceptor): use async/await to support return new Promise (#6279)
ref: #4778
This commit is contained in:
@@ -429,8 +429,8 @@ export const executeRequest = (req) =>
|
|||||||
|
|
||||||
specActions.setRequest(req.pathName, req.method, parsedRequest)
|
specActions.setRequest(req.pathName, req.method, parsedRequest)
|
||||||
|
|
||||||
let requestInterceptorWrapper = function(r) {
|
let requestInterceptorWrapper = async (r) => {
|
||||||
let mutatedRequest = requestInterceptor.apply(this, [r])
|
let mutatedRequest = await requestInterceptor.apply(this, [r])
|
||||||
let parsedMutatedRequest = Object.assign({}, mutatedRequest)
|
let parsedMutatedRequest = Object.assign({}, mutatedRequest)
|
||||||
specActions.setMutatedRequest(req.pathName, req.method, parsedMutatedRequest)
|
specActions.setMutatedRequest(req.pathName, req.method, parsedMutatedRequest)
|
||||||
return mutatedRequest
|
return mutatedRequest
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ describe("spec plugin - actions", function(){
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should pass requestInterceptor/responseInterceptor to fn.execute", function(){
|
it("should pass requestInterceptor/responseInterceptor to fn.execute", async () => {
|
||||||
// Given
|
// Given
|
||||||
let configs = {
|
let configs = {
|
||||||
requestInterceptor: createSpy(),
|
requestInterceptor: createSpy(),
|
||||||
@@ -107,7 +107,8 @@ describe("spec plugin - actions", function(){
|
|||||||
specActions: {
|
specActions: {
|
||||||
executeRequest: createSpy(),
|
executeRequest: createSpy(),
|
||||||
setMutatedRequest: createSpy(),
|
setMutatedRequest: createSpy(),
|
||||||
setRequest: createSpy()
|
setRequest: createSpy(),
|
||||||
|
setResponse: createSpy()
|
||||||
},
|
},
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
spec: () => fromJS({}),
|
spec: () => fromJS({}),
|
||||||
@@ -124,7 +125,7 @@ describe("spec plugin - actions", function(){
|
|||||||
method: "GET",
|
method: "GET",
|
||||||
operation: fromJS({operationId: "getOne"})
|
operation: fromJS({operationId: "getOne"})
|
||||||
})
|
})
|
||||||
let res = executeFn(system)
|
await executeFn(system)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
expect(system.fn.execute.calls.length).toEqual(1)
|
expect(system.fn.execute.calls.length).toEqual(1)
|
||||||
@@ -137,7 +138,7 @@ describe("spec plugin - actions", function(){
|
|||||||
|
|
||||||
|
|
||||||
let wrappedRequestInterceptor = system.fn.execute.calls[0].arguments[0].requestInterceptor
|
let wrappedRequestInterceptor = system.fn.execute.calls[0].arguments[0].requestInterceptor
|
||||||
wrappedRequestInterceptor(system.fn.execute.calls[0].arguments[0])
|
await wrappedRequestInterceptor(system.fn.execute.calls[0].arguments[0])
|
||||||
expect(configs.requestInterceptor.calls.length).toEqual(1)
|
expect(configs.requestInterceptor.calls.length).toEqual(1)
|
||||||
expect(system.specActions.setMutatedRequest.calls.length).toEqual(1)
|
expect(system.specActions.setMutatedRequest.calls.length).toEqual(1)
|
||||||
expect(system.specActions.setRequest.calls.length).toEqual(1)
|
expect(system.specActions.setRequest.calls.length).toEqual(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user