[#10582] 👌 Re-add tests and code to throw exceptions when entity type is not url.
See https://github.com/backstage/backstage/pull/10584#discussion_r841505986 See https://github.com/backstage/backstage/pull/10584#discussion_r841502848 Signed-off-by: LvffY <louberger@hotmail.fr> (cherry picked from commit 8a986150cc1e96b3150516ef36f24bdd89c55bff)
This commit is contained in:
@@ -326,45 +326,45 @@ describe('TodoReaderService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not throw if entity has an invalid location', async () => {
|
||||
it('should throw if entity has an invalid location', async () => {
|
||||
const todoReader = mockTodoReader([]);
|
||||
const catalogClient = mockCatalogClient({
|
||||
...mockEntity,
|
||||
metadata: {
|
||||
...mockEntity.metadata,
|
||||
annotations: {
|
||||
['backstage.io/managed-by-location']: 'file:../info.yaml',
|
||||
['backstage.io/managed-by-location']: 'file:../managed-by-location.yaml',
|
||||
},
|
||||
},
|
||||
});
|
||||
const service = new TodoReaderService({ todoReader, catalogClient });
|
||||
|
||||
await expect(service.listTodos({ entity: entityName })).resolves.toEqual({
|
||||
items: [],
|
||||
totalCount: 0,
|
||||
offset: 0,
|
||||
limit: 10,
|
||||
});
|
||||
await expect(service.listTodos({ entity: entityName })).rejects.toEqual(
|
||||
expect.objectContaining({
|
||||
name: 'InputError',
|
||||
message: `Invalid entity location type for component:default/my-component, got 'file' for location ../managed-by-location.yaml`,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should not throw if entity has an invalid source location', async () => {
|
||||
it('should throw if entity has an invalid source location', async () => {
|
||||
const todoReader = mockTodoReader([]);
|
||||
const catalogClient = mockCatalogClient({
|
||||
...mockEntity,
|
||||
metadata: {
|
||||
...mockEntity.metadata,
|
||||
annotations: {
|
||||
['backstage.io/source-location']: 'file:../info.yaml',
|
||||
['backstage.io/source-location']: 'file:../source-location.yaml',
|
||||
},
|
||||
},
|
||||
});
|
||||
const service = new TodoReaderService({ todoReader, catalogClient });
|
||||
|
||||
await expect(service.listTodos({ entity: entityName })).resolves.toEqual({
|
||||
items: [],
|
||||
totalCount: 0,
|
||||
offset: 0,
|
||||
limit: 10,
|
||||
});
|
||||
await expect(service.listTodos({ entity: entityName })).rejects.toEqual(
|
||||
expect.objectContaining({
|
||||
name: 'InputError',
|
||||
message: `Invalid entity location type for component:default/my-component, got 'file' for location ../source-location.yaml`,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,8 +71,15 @@ export class TodoReaderService implements TodoService {
|
||||
`Entity not found, ${stringifyEntityRef(req.entity)}`,
|
||||
);
|
||||
}
|
||||
|
||||
const url = getEntitySourceLocation(entity).target;
|
||||
const entitySourceLocation = getEntitySourceLocation(entity)
|
||||
if (entitySourceLocation.type !== 'url') {
|
||||
throw new InputError(
|
||||
`Invalid entity location type for ${stringifyEntityRef(
|
||||
entity,
|
||||
)}, got '${entitySourceLocation.type}' for location ${entitySourceLocation.target}`,
|
||||
);
|
||||
}
|
||||
const url = entitySourceLocation.target;
|
||||
const todos = await this.todoReader.readTodos({ url });
|
||||
|
||||
let limit = req.limit ?? this.defaultPageSize;
|
||||
|
||||
Reference in New Issue
Block a user