Make listLocations conform with current API

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2021-05-07 15:01:17 +02:00
parent b0d711e718
commit e53223f15c
3 changed files with 27 additions and 5 deletions
@@ -137,8 +137,23 @@ describe('DefaultLocationServiceTest', () => {
});
});
describe('listLocations', () => {
it('should call locationStore.deleteLocation', async () => {
await locationService.listLocations();
it('should call locationStore.listLocations', async () => {
store.listLocations.mockResolvedValue([
{
id: '123',
target: 'https://backstage.io/catalog-info.yaml',
type: 'url',
},
]);
await expect(locationService.listLocations()).resolves.toEqual([
{
data: {
id: '123',
target: 'https://backstage.io/catalog-info.yaml',
type: 'url',
},
},
]);
expect(store.listLocations).toBeCalled();
});
});
@@ -24,6 +24,7 @@ import {
LocationService,
LocationStore,
CatalogProcessingOrchestrator,
LocationResponse,
} from './types';
import { locationSpecToMetadataName } from './util';
@@ -87,9 +88,11 @@ export class DefaultLocationService implements LocationService {
return { location, entities: [] };
}
listLocations(): Promise<Location[]> {
return this.store.listLocations();
async listLocations(): Promise<LocationResponse[]> {
const locations = await this.store.listLocations();
return locations.map(location => ({ data: location }));
}
getLocation(id: string): Promise<Location> {
return this.store.getLocation(id);
}
+5 -1
View File
@@ -27,11 +27,15 @@ export interface LocationService {
spec: LocationSpec,
dryRun: boolean,
): Promise<{ location: Location; entities: Entity[] }>;
listLocations(): Promise<Location[]>;
listLocations(): Promise<LocationResponse[]>;
getLocation(id: string): Promise<Location>;
deleteLocation(id: string): Promise<void>;
}
export type LocationResponse = {
data: Location;
};
export interface LocationStore {
createLocation(spec: LocationSpec): Promise<Location>;
listLocations(): Promise<Location[]>;