Skip to content

Commit

Permalink
fix(TryItOutExecutor): pass request/response interceptors via instanc…
Browse files Browse the repository at this point in the history
…e method (#1559)

Refs #1476
  • Loading branch information
char0n committed Jun 18, 2020
1 parent 9c60723 commit a91e11a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Expand Up @@ -62,6 +62,8 @@ Swagger.prototype = {
http: this.http,
securities: {authorized: this.authorizations},
contextUrl: typeof this.url === 'string' ? this.url : undefined,
requestInterceptor: this.requestInterceptor || null,
responseInterceptor: this.responseInterceptor || null,
...argHash
})
},
Expand Down
36 changes: 36 additions & 0 deletions test/index.js
Expand Up @@ -550,6 +550,42 @@ describe('constructor', () => {
})
})
})

test('should add global request interceptor', async () => {
const spec = {
paths: {
'/pet': {
get: {
operationId: 'getPets',
}
}
}
}
const http = jest.fn()
const requestInterceptor = jest.fn(request => request)
const client = await Swagger({spec, requestInterceptor})
await client.execute({http, operationId: 'getPets'})

expect(http.mock.calls[0][0].requestInterceptor).toStrictEqual(requestInterceptor)
})

test('should add global response interceptor', async () => {
const spec = {
paths: {
'/pet': {
get: {
operationId: 'getPets',
}
}
}
}
const http = jest.fn()
const responseInterceptor = jest.fn(request => request)
const client = await Swagger({spec, responseInterceptor})
await client.execute({http, operationId: 'getPets'})

expect(http.mock.calls[0][0].responseInterceptor).toStrictEqual(responseInterceptor)
})
})

describe('interceptor', () => {
Expand Down

0 comments on commit a91e11a

Please sign in to comment.