Add HTTPClientMock.mockAddTyped
This commit is contained in:
parent
45f0cb76d3
commit
a20ac8cbbc
@ -1,7 +1,8 @@
|
|||||||
import {HTTPClient} from '../http/HTTPClient'
|
import {HTTPClient} from '../http/HTTPClient'
|
||||||
import {IRoutes} from '@rondo/common'
|
|
||||||
import {IRequest} from '../http/IRequest'
|
import {IRequest} from '../http/IRequest'
|
||||||
import {IResponse} from '../http/IResponse'
|
import {IResponse} from '../http/IResponse'
|
||||||
|
import {IRoutes, TMethod} from '@rondo/common'
|
||||||
|
import {ITypedRequestParams} from '../http/ITypedRequestParams'
|
||||||
|
|
||||||
interface IReqRes {
|
interface IReqRes {
|
||||||
req: IRequest
|
req: IRequest
|
||||||
@ -94,6 +95,22 @@ export class HTTPClientMock<T extends IRoutes> extends HTTPClient<T> {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new mock with predefined type
|
||||||
|
*/
|
||||||
|
mockAddTyped<P extends keyof T & string, M extends TMethod>(
|
||||||
|
params: ITypedRequestParams<T, P, M>,
|
||||||
|
response: T[P][M]['response'],
|
||||||
|
): this {
|
||||||
|
const url = this.formatter.format(params.path, params.params)
|
||||||
|
return this.mockAdd({
|
||||||
|
method: params.method,
|
||||||
|
url,
|
||||||
|
params: params.query,
|
||||||
|
data: params.body,
|
||||||
|
}, response)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all mocks and recorded requests
|
* Clear all mocks and recorded requests
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user