mirror of https://github.com/ghostfolio/ghostfolio
committed by
Thomas Kaul
5 changed files with 77 additions and 74 deletions
@ -0,0 +1,18 @@ |
|||
import { Observable } from 'rxjs'; |
|||
|
|||
export class HttpClientMock { |
|||
public constructor(private mockResponses: Map<string, any>) {} |
|||
|
|||
public get<TResponse>(url: string, options?: any): Observable<TResponse> { |
|||
if (this.mockResponses.has(url) && options) { |
|||
return new Observable<TResponse>((subscriber) => { |
|||
subscriber.next(this.mockResponses.get(url)); |
|||
subscriber.complete(); |
|||
}); |
|||
} |
|||
|
|||
return new Observable<TResponse>((subscriber) => { |
|||
subscriber.error(new Error(`No mock data for URL: ${url}`)); |
|||
}); |
|||
} |
|||
} |
@ -1,23 +0,0 @@ |
|||
import { LookupResponse } from '@ghostfolio/common/interfaces'; |
|||
|
|||
import { Observable } from 'rxjs'; |
|||
|
|||
export class HttpClientMock { |
|||
public constructor( |
|||
private readonly url: string, |
|||
private readonly mockData: LookupResponse |
|||
) {} |
|||
|
|||
get<T>(url: string, options?: any): Observable<T> { |
|||
if (url === this.url && options) { |
|||
return new Observable<T>((subscriber) => { |
|||
subscriber.next(this.mockData as T); |
|||
subscriber.complete(); |
|||
}); |
|||
} |
|||
|
|||
return new Observable<T>((subscriber) => { |
|||
subscriber.error(new Error(`No mock data for URL: ${url}`)); |
|||
}); |
|||
} |
|||
} |
Loading…
Reference in new issue