Skip to content

Commit

Permalink
Make cursor an optional parameter to findLists
Browse files Browse the repository at this point in the history
This param is an optimization and not required for basic functionality.
  • Loading branch information
rylnd committed Jul 2, 2020
1 parent 5be0e87 commit 0e4fee7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions x-pack/plugins/lists/public/lists/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ describe('Value Lists API', () => {
it('GETs from the lists endpoint', async () => {
const abortCtrl = new AbortController();
await findLists({
cursor: undefined,
http: httpMock,
pageIndex: 1,
pageSize: 10,
Expand All @@ -106,7 +105,7 @@ describe('Value Lists API', () => {
it('sends pagination as query parameters', async () => {
const abortCtrl = new AbortController();
await findLists({
cursor: undefined,
cursor: 'cursor',
http: httpMock,
pageIndex: 1,
pageSize: 10,
Expand All @@ -116,15 +115,18 @@ describe('Value Lists API', () => {
expect(httpMock.fetch).toHaveBeenCalledWith(
'/api/lists/_find',
expect.objectContaining({
query: { page: 1, per_page: 10 },
query: {
cursor: 'cursor',
page: 1,
per_page: 10,
},
})
);
});

it('rejects with an error if request payload is invalid (and does not make API call)', async () => {
const abortCtrl = new AbortController();
const payload: ApiPayload<FindListsParams> = {
cursor: undefined,
pageIndex: 10,
pageSize: 0,
};
Expand All @@ -142,7 +144,6 @@ describe('Value Lists API', () => {
it('rejects with an error if response payload is invalid', async () => {
const abortCtrl = new AbortController();
const payload: ApiPayload<FindListsParams> = {
cursor: undefined,
pageIndex: 1,
pageSize: 10,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('useFindLists', () => {
it('invokes Api.findLists', async () => {
const { result, waitForNextUpdate } = renderHook(() => useFindLists());
act(() => {
result.current.start({ cursor: undefined, http: httpMock, pageIndex: 1, pageSize: 10 });
result.current.start({ http: httpMock, pageIndex: 1, pageSize: 10 });
});
await waitForNextUpdate();

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lists/public/lists/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ApiParams {
export type ApiPayload<T extends ApiParams> = Omit<T, 'http' | 'signal'>;

export interface FindListsParams extends ApiParams {
cursor: string | undefined;
cursor?: string | undefined;
pageSize: number | undefined;
pageIndex: number | undefined;
}
Expand Down

0 comments on commit 0e4fee7

Please sign in to comment.