make sure to pass through offset too
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -359,13 +359,17 @@ export class CatalogClient implements CatalogApi {
|
||||
const body: QueryEntitiesByPredicateRequest = {};
|
||||
|
||||
if (isQueryEntitiesInitialRequest(request)) {
|
||||
const { query, limit, orderFields, fullTextFilter, fields } = request;
|
||||
const { query, limit, offset, orderFields, fullTextFilter, fields } =
|
||||
request;
|
||||
if (query && typeof query === 'object') {
|
||||
body.query = query;
|
||||
}
|
||||
if (limit !== undefined) {
|
||||
body.limit = limit;
|
||||
}
|
||||
if (offset !== undefined) {
|
||||
body.offset = offset;
|
||||
}
|
||||
if (orderFields !== undefined) {
|
||||
body.orderBy = [orderFields].flat();
|
||||
}
|
||||
|
||||
+1
@@ -27,6 +27,7 @@ import { QueryEntitiesByPredicateRequestOrderByInner } from '../models/QueryEnti
|
||||
export interface QueryEntitiesByPredicateRequest {
|
||||
cursor?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
orderBy?: Array<QueryEntitiesByPredicateRequestOrderByInner>;
|
||||
fullTextFilter?: QueryEntitiesByPredicateRequestFullTextFilter;
|
||||
fields?: Array<string>;
|
||||
|
||||
@@ -1125,6 +1125,8 @@ paths:
|
||||
type: string
|
||||
limit:
|
||||
type: number
|
||||
offset:
|
||||
type: number
|
||||
orderBy:
|
||||
type: array
|
||||
items:
|
||||
|
||||
+1
@@ -27,6 +27,7 @@ import { QueryEntitiesByPredicateRequestOrderByInner } from '../models/QueryEnti
|
||||
export interface QueryEntitiesByPredicateRequest {
|
||||
cursor?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
orderBy?: Array<QueryEntitiesByPredicateRequestOrderByInner>;
|
||||
fullTextFilter?: QueryEntitiesByPredicateRequestFullTextFilter;
|
||||
fields?: Array<string>;
|
||||
|
||||
@@ -1269,6 +1269,9 @@ export const spec = {
|
||||
limit: {
|
||||
type: 'number',
|
||||
},
|
||||
offset: {
|
||||
type: 'number',
|
||||
},
|
||||
orderBy: {
|
||||
type: 'array',
|
||||
items: {
|
||||
|
||||
@@ -509,6 +509,31 @@ describe('createRouter readonly disabled', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('queries entities with an offset', async () => {
|
||||
const items: Entity[] = [
|
||||
{ apiVersion: 'a', kind: 'b', metadata: { name: 'n' } },
|
||||
];
|
||||
entitiesCatalog.queryEntities.mockResolvedValue({
|
||||
items: { type: 'object', entities: items },
|
||||
pageInfo: {},
|
||||
totalItems: 5,
|
||||
});
|
||||
|
||||
const response = await request(app)
|
||||
.post('/entities/by-query')
|
||||
.send({ query: { kind: 'b' }, limit: 2, offset: 3 });
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(entitiesCatalog.queryEntities).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
query: { kind: 'b' },
|
||||
limit: 2,
|
||||
offset: 3,
|
||||
credentials: mockCredentials.user(),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('paginates with a cursor in the body', async () => {
|
||||
const items: Entity[] = [
|
||||
{ apiVersion: 'a', kind: 'b', metadata: { name: 'n' } },
|
||||
|
||||
@@ -28,6 +28,7 @@ describe('parseEntityQuery', () => {
|
||||
fullTextFilter: undefined,
|
||||
fields: undefined,
|
||||
limit: undefined,
|
||||
offset: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -68,6 +69,18 @@ describe('parseEntityQuery', () => {
|
||||
expect(result).toEqual(expect.objectContaining({ limit: 50 }));
|
||||
});
|
||||
|
||||
it('passes through offset', () => {
|
||||
const result = parseEntityQuery({ offset: 100 });
|
||||
expect(result).toEqual(expect.objectContaining({ offset: 100 }));
|
||||
});
|
||||
|
||||
it('passes through limit and offset together', () => {
|
||||
const result = parseEntityQuery({ limit: 50, offset: 100 });
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({ limit: 50, offset: 100 }),
|
||||
);
|
||||
});
|
||||
|
||||
it('passes through fields', () => {
|
||||
const result = parseEntityQuery({
|
||||
fields: ['metadata.name', 'kind'],
|
||||
|
||||
@@ -110,5 +110,6 @@ export function parseEntityQuery(
|
||||
: undefined,
|
||||
fields: request.fields,
|
||||
limit: request.limit,
|
||||
offset: request.offset,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user