Add HTTPClientMock.mockAddTyped

This commit is contained in:
Jerko Steiner 2019-06-04 15:11:54 +10:00
parent 45f0cb76d3
commit a20ac8cbbc

View File

@ -1,7 +1,8 @@
import {HTTPClient} from '../http/HTTPClient'
import {IRoutes} from '@rondo/common'
import {IRequest} from '../http/IRequest'
import {IResponse} from '../http/IResponse'
import {IRoutes, TMethod} from '@rondo/common'
import {ITypedRequestParams} from '../http/ITypedRequestParams'
interface IReqRes {
req: IRequest
@ -94,6 +95,22 @@ export class HTTPClientMock<T extends IRoutes> extends HTTPClient<T> {
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
*/