Skip to content

Commit

Permalink
Apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
fnmunhoz committed Feb 6, 2021
1 parent 1c65417 commit 98f9641
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/utils/getResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export const getResponse = async <
handlers: H,
): Promise<ResponsePayload> => {
const relevantHandlers = handlers
.filter((requestHandler) => {
// Skip a handler if it has been already used for a one-time response.
return !requestHandler.shouldSkip
})
.map<[RequestHandler<any, any>, any]>((requestHandler) => {
// Parse the captured request to get additional information.
// Make the predicate function accept all the necessary information
Expand Down Expand Up @@ -81,16 +85,13 @@ export const getResponse = async <

const mockedResponse = await resolver(publicRequest, response, context)

if (!mockedResponse) {
// Skip a handler if there is no response or if it has been already used for
// a one-time response.
if (!mockedResponse || requestHandler.shouldSkip) {
return acc
}

if (mockedResponse && mockedResponse.once) {
// Skip a handler if it has been already used for a one-time response.
if (requestHandler.shouldSkip) {
return acc
}

// When responded with a one-time response, match the relevant request handler
// as skipped, so it cannot affect the captured requests anymore.
requestHandler.shouldSkip = true
Expand Down

0 comments on commit 98f9641

Please sign in to comment.