catalog-backend: move endpoint to /entities/by-query
Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
'@backstage/plugin-catalog-backend': minor
|
||||
---
|
||||
|
||||
Add /v2/entities endpoint returning paginated entities.
|
||||
Add /entities/by-query endpoint returning paginated entities.
|
||||
|
||||
The endpoint supports cursor base pagination and server side sorting of the entities by name or uid.
|
||||
|
||||
@@ -300,7 +300,7 @@ describe('CatalogClient', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
server.use(
|
||||
rest.get(`${mockBaseUrl}/v2/entities`, (_, res, ctx) => {
|
||||
rest.get(`${mockBaseUrl}/entities/by-query`, (_, res, ctx) => {
|
||||
return res(ctx.json(defaultServiceResponse));
|
||||
}),
|
||||
);
|
||||
@@ -321,7 +321,7 @@ describe('CatalogClient', () => {
|
||||
res(ctx.json({ entities: [], totalItems: 0 })),
|
||||
);
|
||||
|
||||
server.use(rest.get(`${mockBaseUrl}/v2/entities`, mockedEndpoint));
|
||||
server.use(rest.get(`${mockBaseUrl}/entities/by-query`, mockedEndpoint));
|
||||
|
||||
const response = await client.getPaginatedEntities(
|
||||
{
|
||||
@@ -356,7 +356,7 @@ describe('CatalogClient', () => {
|
||||
res(ctx.json({ entities: [], totalItems: 0 })),
|
||||
);
|
||||
|
||||
server.use(rest.get(`${mockBaseUrl}/v2/entities`, mockedEndpoint));
|
||||
server.use(rest.get(`${mockBaseUrl}/entities/by-query`, mockedEndpoint));
|
||||
|
||||
await client.getPaginatedEntities({
|
||||
fields: ['a', 'b'],
|
||||
@@ -379,7 +379,7 @@ describe('CatalogClient', () => {
|
||||
res(ctx.json({ entities: [], totalItems: 0 })),
|
||||
);
|
||||
|
||||
server.use(rest.get(`${mockBaseUrl}/v2/entities`, mockedEndpoint));
|
||||
server.use(rest.get(`${mockBaseUrl}/entities/by-query`, mockedEndpoint));
|
||||
|
||||
await client.getPaginatedEntities({
|
||||
fields: ['a', 'b'],
|
||||
@@ -422,7 +422,7 @@ describe('CatalogClient', () => {
|
||||
),
|
||||
);
|
||||
|
||||
server.use(rest.get(`${mockBaseUrl}/v2/entities`, mockedEndpoint));
|
||||
server.use(rest.get(`${mockBaseUrl}/entities/by-query`, mockedEndpoint));
|
||||
|
||||
const response = await client.getPaginatedEntities({
|
||||
limit: 2,
|
||||
|
||||
@@ -251,7 +251,7 @@ export class CatalogClient implements CatalogApi {
|
||||
totalItems: number;
|
||||
nextCursor?: string;
|
||||
prevCursor?: string;
|
||||
}>('GET', `/v2/entities${query}`, options);
|
||||
}>('GET', `/entities/by-query${query}`, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -136,7 +136,7 @@ describe('createRouter readonly disabled', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /v2/entities', () => {
|
||||
describe('GET /entities/by-query', () => {
|
||||
it('happy path: lists entities', async () => {
|
||||
const entities: Entity[] = [
|
||||
{ apiVersion: 'a', kind: 'b', metadata: { name: 'n' } },
|
||||
@@ -148,7 +148,7 @@ describe('createRouter readonly disabled', () => {
|
||||
nextCursor: 'something',
|
||||
});
|
||||
|
||||
const response = await request(app).get('/v2/entities');
|
||||
const response = await request(app).get('/entities/by-query');
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual({
|
||||
entities,
|
||||
@@ -163,7 +163,7 @@ describe('createRouter readonly disabled', () => {
|
||||
totalItems: 0,
|
||||
});
|
||||
const response = await request(app).get(
|
||||
'/v2/entities?filter=a=1,a=2,b=3&filter=c=4&sortField=metadata.name,asc&sortField=metadata.uid,desc',
|
||||
'/entities/by-query?filter=a=1,a=2,b=3&filter=c=4&sortField=metadata.name,asc&sortField=metadata.uid,desc',
|
||||
);
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
@@ -198,7 +198,9 @@ describe('createRouter readonly disabled', () => {
|
||||
nextCursor: 'next',
|
||||
});
|
||||
|
||||
const response = await request(app).get('/v2/entities?cursor=something');
|
||||
const response = await request(app).get(
|
||||
'/entities/by-query?cursor=something',
|
||||
);
|
||||
expect(entitiesCatalog.paginatedEntities).toHaveBeenCalledTimes(1);
|
||||
expect(entitiesCatalog.paginatedEntities).toHaveBeenCalledWith({
|
||||
cursor: 'something',
|
||||
|
||||
@@ -131,7 +131,7 @@ export async function createRouter(
|
||||
// TODO(freben): encode the pageInfo in the response
|
||||
res.json(entities);
|
||||
})
|
||||
.get('/v2/entities', async (req, res) => {
|
||||
.get('/entities/by-query', async (req, res) => {
|
||||
const response = await entitiesCatalog.paginatedEntities({
|
||||
...parsePaginatedEntitiesParams(req.query),
|
||||
authorizationToken: getBearerToken(req.header('authorization')),
|
||||
|
||||
Reference in New Issue
Block a user