todo: move filter encoding fix to backend

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-08-11 15:04:40 +02:00
parent ad3fb54017
commit c6b29f3dbe
5 changed files with 28 additions and 13 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
---
'@backstage/plugin-todo': patch
'@backstage/plugin-todo-backend': patch
---
Fixed URL encoding of filters where the filter was always rejected by the backend validation.
Fixed a bug where filter queries from the frontend would always fail validation.
@@ -173,6 +173,7 @@ export const spec = {
name: 'filter',
in: 'query',
required: false,
allowReserved: true,
schema: {
type: 'array',
description:
@@ -111,6 +111,7 @@ paths:
- name: filter
in: query
required: false
allowReserved: true
schema:
type: array
description: A list of filters used to narrow down the listed TODO items
@@ -131,6 +131,23 @@ describe('createRouter', () => {
);
});
it('forwards filter query', async () => {
mockService.listTodos.mockResolvedValueOnce(mockListBody);
const response = await request(app).get('/v1/todos?filter=text=*borked*');
expect(response.status).toEqual(200);
expect(response.body).toEqual(mockListBody);
expect(mockService.listTodos).toHaveBeenCalledWith(
{
entity: undefined,
offset: undefined,
limit: undefined,
filters: [{ field: 'text', value: '*borked*' }],
},
{ token: undefined },
);
});
it('rejects invalid queries', async () => {
request(app)
.get('/v1/todos?entity=k:n&entity=k:n')
+7 -11
View File
@@ -67,17 +67,13 @@ export class TodoClient implements TodoApi {
}
}
const res = await fetch(
// TODO(Rugvip): Figure out a better solution to '*' not being URL encoded but that being required by OpenAPI
`${baseUrl}/v1/todos?${String(query).replace(/\*/g, '%2A')}`,
{
headers: token
? {
Authorization: `Bearer ${token}`,
}
: undefined,
},
);
const res = await fetch(`${baseUrl}/v1/todos?${query}`, {
headers: token
? {
Authorization: `Bearer ${token}`,
}
: undefined,
});
if (!res.ok) {
throw await ResponseError.fromResponse(res);