Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMantas committed Jul 8, 2024
1 parent aabac2d commit 243203f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/unit/core/plugins/spec/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,55 @@ describe("spec plugin - actions", function(){
expect(system.specActions.setMutatedRequest.mock.calls.length).toEqual(1)
expect(system.specActions.setRequest.mock.calls.length).toEqual(1)
})

it("should include duration in the response on error", async () => {
let configs = {
requestInterceptor: jest.fn(),
responseInterceptor: jest.fn()
}

const fakeDelay = 100
const system = {
fn: {
buildRequest: jest.fn(),
execute: jest.fn().mockImplementation(() => new Promise((_, reject) => {
setTimeout(() => {
reject(new Error("Error message"))
}, fakeDelay)
}))
},
specActions: {
executeRequest: jest.fn(),
setMutatedRequest: jest.fn(),
setRequest: jest.fn(),
setResponse: jest.fn()
},
specSelectors: {
spec: () => fromJS({}),
parameterValues: () => fromJS({}),
contentTypeValues: () => fromJS({}),
url: () => fromJS({}),
isOAS3: () => false
},
getConfigs: () => configs
}

const executeFn = executeRequest({
pathName: "/error",
method: "GET",
operation: fromJS({operationId: "getError"})
})

await executeFn(system)

expect(system.fn.execute.mock.calls.length).toEqual(1)
expect(system.specActions.setResponse).toHaveBeenCalled()

// Check if duration was set and is at least 100ms
const callArgs = system.specActions.setResponse.mock.calls[0][2]
expect(callArgs).toHaveProperty("duration")
expect(callArgs.duration).toBeGreaterThanOrEqual(fakeDelay)
})
})

xit("should call specActions.setResponse, when fn.execute resolves", function(){
Expand Down

0 comments on commit 243203f

Please sign in to comment.