Skip to content

Commit

Permalink
Fix tests and types
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Dec 30, 2019
1 parent 29d03bf commit 9bb0b78
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [IHttpFetchError](./kibana-plugin-public.ihttpfetcherror.md) &gt; [body](./kibana-plugin-public.ihttpfetcherror.body.md)

## IHttpFetchError.body property

<b>Signature:</b>

```typescript
readonly body?: any;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IHttpFetchError extends Error
| Property | Type | Description |
| --- | --- | --- |
| [body](./kibana-plugin-public.ihttpfetcherror.body.md) | <code>any</code> | |
| [req](./kibana-plugin-public.ihttpfetcherror.req.md) | <code>Request</code> | |
| [request](./kibana-plugin-public.ihttpfetcherror.request.md) | <code>Request</code> | |
| [res](./kibana-plugin-public.ihttpfetcherror.res.md) | <code>Response</code> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Search for objects
<b>Signature:</b>

```typescript
find: <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "page" | "fields" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "perPage">) => Promise<SavedObjectsFindResponsePublic<T>>;
find: <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "page" | "perPage" | "sortField" | "fields" | "searchFields" | "hasReference" | "defaultSearchOperator">) => Promise<SavedObjectsFindResponsePublic<T>>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export declare class SavedObjectsClient
| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | <code>(objects?: {</code><br/><code> id: string;</code><br/><code> type: string;</code><br/><code> }[]) =&gt; Promise&lt;SavedObjectsBatchResponse&lt;SavedObjectAttributes&gt;&gt;</code> | Returns an array of objects by id |
| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <code>&lt;T extends SavedObjectAttributes&gt;(type: string, attributes: T, options?: SavedObjectsCreateOptions) =&gt; Promise&lt;SimpleSavedObject&lt;T&gt;&gt;</code> | Persists an object |
| [delete](./kibana-plugin-public.savedobjectsclient.delete.md) | | <code>(type: string, id: string) =&gt; Promise&lt;{}&gt;</code> | Deletes an object |
| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <code>&lt;T extends SavedObjectAttributes&gt;(options: Pick&lt;SavedObjectFindOptionsServer, &quot;search&quot; &#124; &quot;filter&quot; &#124; &quot;type&quot; &#124; &quot;page&quot; &#124; &quot;fields&quot; &#124; &quot;searchFields&quot; &#124; &quot;defaultSearchOperator&quot; &#124; &quot;hasReference&quot; &#124; &quot;sortField&quot; &#124; &quot;perPage&quot;&gt;) =&gt; Promise&lt;SavedObjectsFindResponsePublic&lt;T&gt;&gt;</code> | Search for objects |
| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <code>&lt;T extends SavedObjectAttributes&gt;(options: Pick&lt;SavedObjectFindOptionsServer, &quot;search&quot; &#124; &quot;filter&quot; &#124; &quot;type&quot; &#124; &quot;page&quot; &#124; &quot;perPage&quot; &#124; &quot;sortField&quot; &#124; &quot;fields&quot; &#124; &quot;searchFields&quot; &#124; &quot;hasReference&quot; &#124; &quot;defaultSearchOperator&quot;&gt;) =&gt; Promise&lt;SavedObjectsFindResponsePublic&lt;T&gt;&gt;</code> | Search for objects |
| [get](./kibana-plugin-public.savedobjectsclient.get.md) | | <code>&lt;T extends SavedObjectAttributes&gt;(type: string, id: string) =&gt; Promise&lt;SimpleSavedObject&lt;T&gt;&gt;</code> | Fetches a single object |

## Methods
Expand Down
1 change: 1 addition & 0 deletions src/core/public/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export interface IHttpFetchError extends Error {
* @deprecated Provided for legacy compatibility. Prefer the `response` property instead.
*/
readonly res?: Response;
readonly body?: any;
}

/** @public */
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ export type IContextProvider<THandler extends HandlerFunction<any>, TContextName

// @public (undocumented)
export interface IHttpFetchError extends Error {
// (undocumented)
readonly body?: any;
// @deprecated (undocumented)
readonly req: Request;
// (undocumented)
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/data/public/search/sync_search_strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ describe('Sync search strategy', () => {
},
{}
);
expect(mockCoreSetup.http.fetch.mock.calls[0][0]).toBe(
`/internal/search/${SYNC_SEARCH_STRATEGY}`
);
expect(mockCoreSetup.http.fetch.mock.calls[0][1]).toEqual({
expect(mockCoreSetup.http.fetch.mock.calls[0][0]).toEqual({
path: `/internal/search/${SYNC_SEARCH_STRATEGY}`,
body: JSON.stringify({
serverStrategy: 'SYNC_SEARCH_STRATEGY',
}),
Expand Down
14 changes: 6 additions & 8 deletions src/plugins/data/public/search/sync_search_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ export const syncSearchStrategyProvider: TSearchStrategyProvider<typeof SYNC_SEA
request: ISyncSearchRequest,
options: ISearchOptions = {}
) => {
const response: Promise<IKibanaSearchResponse> = context.core.http.fetch(
`/internal/search/${request.serverStrategy}`,
{
method: 'POST',
body: JSON.stringify(request),
signal: options.signal,
}
);
const response: Promise<IKibanaSearchResponse> = context.core.http.fetch({
path: `/internal/search/${request.serverStrategy}`,
method: 'POST',
body: JSON.stringify(request),
signal: options.signal,
});

return from(response);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ describe('IndexPattern Data Panel', () => {

function testProps() {
const setState = jest.fn();
core.http.get.mockImplementation(async (url: string) => {
const parts = url.split('/');
core.http.get.mockImplementation(async ({ path }) => {
const parts = path.split('/');
const indexPatternTitle = parts[parts.length - 1];
return {
indexPatternTitle,
Expand Down Expand Up @@ -397,15 +397,17 @@ describe('IndexPattern Data Panel', () => {
expect(setState).toHaveBeenCalledTimes(2);
expect(core.http.get).toHaveBeenCalledTimes(2);

expect(core.http.get).toHaveBeenCalledWith('/api/lens/existing_fields/aaa', {
expect(core.http.get).toHaveBeenCalledWith({
path: '/api/lens/existing_fields/aaa',
query: {
fromDate: '2019-01-01',
toDate: '2020-01-01',
timeFieldName: 'atime',
},
});

expect(core.http.get).toHaveBeenCalledWith('/api/lens/existing_fields/aaa', {
expect(core.http.get).toHaveBeenCalledWith({
path: '/api/lens/existing_fields/aaa',
query: {
fromDate: '2019-01-01',
toDate: '2020-01-02',
Expand Down Expand Up @@ -436,15 +438,17 @@ describe('IndexPattern Data Panel', () => {

expect(setState).toHaveBeenCalledTimes(2);

expect(core.http.get).toHaveBeenCalledWith('/api/lens/existing_fields/aaa', {
expect(core.http.get).toHaveBeenCalledWith({
path: '/api/lens/existing_fields/aaa',
query: {
fromDate: '2019-01-01',
toDate: '2020-01-01',
timeFieldName: 'atime',
},
});

expect(core.http.get).toHaveBeenCalledWith('/api/lens/existing_fields/bbb', {
expect(core.http.get).toHaveBeenCalledWith({
path: '/api/lens/existing_fields/bbb',
query: {
fromDate: '2019-01-01',
toDate: '2020-01-01',
Expand Down Expand Up @@ -484,13 +488,13 @@ describe('IndexPattern Data Panel', () => {
let overlapCount = 0;
const props = testProps();

core.http.get.mockImplementation((url: string) => {
core.http.get.mockImplementation(({ path }) => {
if (queryCount) {
++overlapCount;
}
++queryCount;

const parts = url.split('/');
const parts = path.split('/');
const indexPatternTitle = parts[parts.length - 1];
const result = Promise.resolve({
indexPatternTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ describe('loader', () => {
describe('syncExistingFields', () => {
it('should call once for each index pattern', async () => {
const setState = jest.fn();
const fetchJson = jest.fn(async (url: string) => {
const indexPatternTitle = _.last(url.split('/'));
const fetchJson = jest.fn(({ path }: { path: string }) => {
const indexPatternTitle = _.last(path.split('/'));
return {
indexPatternTitle,
existingFieldNames: ['field_1', 'field_2'].map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ export async function syncExistingFields({
query.timeFieldName = pattern.timeFieldName;
}

return fetchJson(`${BASE_API_URL}/existing_fields/${pattern.title}`, {
return fetchJson({
path: `${BASE_API_URL}/existing_fields/${pattern.title}`,
query,
}) as Promise<ExistingFields>;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const buildRequest = (path = '/app/kibana') => {
return {
path,
route: { settings: {} },
headers: {},
raw: {
req: {
socket: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('response', () => {
http.intercept(interceptor);
fetchMock.mock('*', 200);

await http.fetch('/foo-api', { headers: { 'kbn-system-api': 'true' } });
await http.fetch('/foo-api', { asSystemApi: true });

expect(sessionTimeoutMock.extend).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -99,9 +99,9 @@ describe('responseError', () => {
http.intercept(interceptor);
fetchMock.mock('*', 401);

await expect(
http.fetch('/foo-api', { headers: { 'kbn-system-api': 'true' } })
).rejects.toMatchInlineSnapshot(`[Error: Unauthorized]`);
await expect(http.fetch('/foo-api', { asSystemApi: true })).rejects.toMatchInlineSnapshot(
`[Error: Unauthorized]`
);

expect(sessionTimeoutMock.extend).not.toHaveBeenCalled();
});
Expand Down

0 comments on commit 9bb0b78

Please sign in to comment.