|
1 |
| -import { ApiClient, isApiClient } from '@ama-sdk/core'; |
2 |
| -import { ApiFetchClient, BaseApiFetchClientConstructor } from '@ama-sdk/client-fetch'; |
| 1 | +import type { ApiClient } from '@ama-sdk/core'; |
3 | 2 |
|
4 | 3 | import * as api from '../api';
|
5 | 4 |
|
6 |
| -const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2'; |
7 |
| -const MOCK_SERVER = new ApiFetchClient({basePath: MOCK_SERVER_BASE_PATH}); |
| 5 | +/** Mock Server default base path */ |
| 6 | +export const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2'; |
8 | 7 |
|
9 | 8 | export interface Api {
|
10 | 9 | petApi: api.PetApi;
|
11 | 10 | storeApi: api.StoreApi;
|
12 | 11 | userApi: api.UserApi;
|
13 | 12 | }
|
14 | 13 |
|
15 |
| -export const myApi: Api = { |
16 |
| - petApi: new api.PetApi(MOCK_SERVER), |
17 |
| - storeApi: new api.StoreApi(MOCK_SERVER), |
18 |
| - userApi: new api.UserApi(MOCK_SERVER) |
19 |
| -}; |
20 |
| - |
21 |
| - |
22 | 14 | /**
|
23 | 15 | * Retrieve mocked SDK Apis
|
24 |
| - * @param config configuration of the Api Client |
| 16 | + * @param apiClient Api Client instance |
| 17 | + * @example Default Mocked API usage |
| 18 | + * ```typescript |
| 19 | + * import { getMockedApi, MOCK_SERVER_BASE_PATH } from './api-mock'; |
| 20 | + * import { ApiFetchClient } from '@ama-sdk/client-fetch'; |
| 21 | + * const mocks = getMockedApi(new ApiFetchClient({ basePath: MOCK_SERVER_BASE_PATH })); |
| 22 | + * ``` |
25 | 23 | */
|
26 |
| -export function getMockedApi(config?: string | BaseApiFetchClientConstructor | ApiClient): Api { |
27 |
| - let apiConfigObj: ApiClient = MOCK_SERVER; |
28 |
| - if (typeof config === 'string') { |
29 |
| - apiConfigObj = new ApiFetchClient({basePath: config}); |
30 |
| - } else if (isApiClient(config)) { |
31 |
| - apiConfigObj = config; |
32 |
| - } else if (config) { |
33 |
| - apiConfigObj = new ApiFetchClient(config); |
34 |
| - } |
| 24 | +export function getMockedApi(apiClient: ApiClient): Api { |
35 | 25 | return {
|
36 |
| - petApi: new api.PetApi(apiConfigObj), |
37 |
| - storeApi: new api.StoreApi(apiConfigObj), |
38 |
| - userApi: new api.UserApi(apiConfigObj) |
| 26 | + petApi: new api.PetApi(apiClient), |
| 27 | + storeApi: new api.StoreApi(apiClient), |
| 28 | + userApi: new api.UserApi(apiClient) |
39 | 29 | };
|
40 | 30 | }
|
0 commit comments