From dd395335bc252ff02c07e6457b519792fba917f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20MORI?= Date: Mon, 8 Aug 2022 15:06:01 +0200 Subject: [PATCH 1/5] Allow unknown typed location from being registered via the location service by configuration settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane MORI --- .changeset/flat-plums-shout.md | 5 + plugins/catalog-backend/config.d.ts | 17 +++ .../src/service/CatalogBuilder.ts | 2 +- .../service/DefaultLocationService.test.ts | 116 +++++++++++++++++- .../src/service/DefaultLocationService.ts | 10 +- 5 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 .changeset/flat-plums-shout.md diff --git a/.changeset/flat-plums-shout.md b/.changeset/flat-plums-shout.md new file mode 100644 index 0000000000..578952c9c3 --- /dev/null +++ b/.changeset/flat-plums-shout.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Allow unknown typed location from being registered via the location service by configuration settings diff --git a/plugins/catalog-backend/config.d.ts b/plugins/catalog-backend/config.d.ts index 950ed2f63c..473db9a35a 100644 --- a/plugins/catalog-backend/config.d.ts +++ b/plugins/catalog-backend/config.d.ts @@ -54,6 +54,23 @@ export interface Config { */ readonly?: boolean; + /** + * Allow unknown type when create location. + * + * Setting 'locationService.create.allowUnknownType=false' forbids to create + * location with unknown type through location service. + * This is the default value. + * + * Setting 'locationService.create.allowUnknownType=true' allows to create + * location with unknown type through location service. + * + */ + locationService?: { + create?: { + allowUnknownType: boolean; + }; + }; + /** * A set of static locations that the catalog shall always keep itself * up-to-date with. This is commonly used for large, permanent integrations diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index e9e35301c3..57b5160a97 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -465,7 +465,7 @@ export class CatalogBuilder { const locationAnalyzer = this.locationAnalyzer ?? new RepoLocationAnalyzer(logger, integrations); const locationService = new AuthorizedLocationService( - new DefaultLocationService(locationStore, orchestrator), + new DefaultLocationService(locationStore, orchestrator, config), permissionEvaluator, ); const refreshService = new AuthorizedRefreshService( diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts index 4399d48d69..e936d2de93 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts @@ -18,6 +18,7 @@ import { DefaultLocationService } from './DefaultLocationService'; import { CatalogProcessingOrchestrator } from '../processing/types'; import { LocationStore } from './types'; import { InputError } from '@backstage/errors'; +import { ConfigReader } from '@backstage/config'; describe('DefaultLocationServiceTest', () => { const orchestrator: jest.Mocked = { @@ -29,7 +30,17 @@ describe('DefaultLocationServiceTest', () => { listLocations: jest.fn(), getLocation: jest.fn(), }; - const locationService = new DefaultLocationService(store, orchestrator); + + const mockConfig = (allowUnknownType: boolean) => + new ConfigReader({ + catalog: { + locationService: { + create: { + allowUnknownType, + }, + }, + }, + }); beforeEach(() => { jest.resetAllMocks(); @@ -81,6 +92,11 @@ describe('DefaultLocationServiceTest', () => { errors: [], }); + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -144,6 +160,12 @@ describe('DefaultLocationServiceTest', () => { store.listLocations.mockResolvedValueOnce([ { id: '137', ...locationSpec }, ]); + + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); const result = await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -197,6 +219,11 @@ describe('DefaultLocationServiceTest', () => { errors: [], }); + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); await expect( locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, @@ -225,6 +252,12 @@ describe('DefaultLocationServiceTest', () => { store.listLocations.mockResolvedValueOnce([ { id: '987', type: 'url', target: 'https://example.com' }, ]); + + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); const result = await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -243,6 +276,11 @@ describe('DefaultLocationServiceTest', () => { id: '123', }); + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); await expect( locationService.createLocation(locationSpec, false), ).resolves.toEqual({ @@ -259,7 +297,61 @@ describe('DefaultLocationServiceTest', () => { }); }); - it('should not allow locations of unknown types', async () => { + it('should create location with unknown type if configuration allows it', async () => { + const locationSpec = { + type: 'unknown', + target: 'https://backstage.io/catalog-info.yaml', + }; + + store.createLocation.mockResolvedValue({ + ...locationSpec, + id: '123', + }); + + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(true), + ); + await expect( + locationService.createLocation(locationSpec, false), + ).resolves.toEqual({ + entities: [], + location: { + id: '123', + target: 'https://backstage.io/catalog-info.yaml', + type: 'unknown', + }, + }); + expect(store.createLocation).toBeCalledWith({ + target: 'https://backstage.io/catalog-info.yaml', + type: 'unknown', + }); + }); + + it('should not allow locations of unknown types by default', async () => { + const locationService = new DefaultLocationService( + store, + orchestrator, + new ConfigReader({}), + ); + await expect( + locationService.createLocation( + { + type: 'unknown', + target: 'https://backstage.io/catalog-info.yaml', + }, + false, + ), + ).rejects.toThrow(InputError); + }); + + it('should not allow locations of unknown types if configuration forbids it', async () => { + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); await expect( locationService.createLocation( { @@ -279,6 +371,11 @@ describe('DefaultLocationServiceTest', () => { errors: [new Error('Error: Unable to read url')], }); + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); await expect( locationService.createLocation( { @@ -293,6 +390,11 @@ describe('DefaultLocationServiceTest', () => { describe('listLocations', () => { it('should call locationStore.deleteLocation', async () => { + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); await locationService.listLocations(); expect(store.listLocations).toBeCalled(); }); @@ -300,6 +402,11 @@ describe('DefaultLocationServiceTest', () => { describe('deleteLocation', () => { it('should call locationStore.deleteLocation', async () => { + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); await locationService.deleteLocation('123'); expect(store.deleteLocation).toBeCalledWith('123'); }); @@ -307,6 +414,11 @@ describe('DefaultLocationServiceTest', () => { describe('getLocation', () => { it('should call locationStore.getLocation', async () => { + const locationService = new DefaultLocationService( + store, + orchestrator, + mockConfig(false), + ); await locationService.getLocation('123'); expect(store.getLocation).toBeCalledWith('123'); }); diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.ts b/plugins/catalog-backend/src/service/DefaultLocationService.ts index 819cead63d..e70d72a9ee 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.ts @@ -26,18 +26,26 @@ import { LocationInput, LocationService, LocationStore } from './types'; import { locationSpecToMetadataName } from '../util/conversion'; import { InputError } from '@backstage/errors'; import { DeferredEntity } from '@backstage/plugin-catalog-node'; +import { Config } from '@backstage/config'; export class DefaultLocationService implements LocationService { constructor( private readonly store: LocationStore, private readonly orchestrator: CatalogProcessingOrchestrator, + private readonly config: Config, ) {} async createLocation( input: LocationInput, dryRun: boolean, ): Promise<{ location: Location; entities: Entity[]; exists?: boolean }> { - if (input.type !== 'url') { + const allowUnknownTypeConfigName = + 'catalog.locationService.create.allowUnknownType'; + const allowUnknownType = + this.config.has(allowUnknownTypeConfigName) && + this.config.getBoolean(allowUnknownTypeConfigName); + + if (!allowUnknownType && input.type !== 'url') { throw new InputError(`Registered locations must be of type 'url'`); } if (dryRun) { From fdc6f0ad7dc27525ff29fae6eadedf6e39ce28a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20MORI?= Date: Fri, 19 Aug 2022 16:45:16 +0200 Subject: [PATCH 2/5] Use options instead of configuration for allowed location types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/backstage/backstage/pull/13013 Signed-off-by: Stéphane MORI --- .changeset/flat-plums-shout.md | 2 +- plugins/catalog-backend/config.d.ts | 17 ---- .../src/service/CatalogBuilder.ts | 18 +++- .../service/DefaultLocationService.test.ts | 97 +++---------------- .../src/service/DefaultLocationService.ts | 23 +++-- 5 files changed, 43 insertions(+), 114 deletions(-) diff --git a/.changeset/flat-plums-shout.md b/.changeset/flat-plums-shout.md index 578952c9c3..250d6a1b35 100644 --- a/.changeset/flat-plums-shout.md +++ b/.changeset/flat-plums-shout.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-catalog-backend': patch +'@backstage/plugin-catalog-backend': minor --- Allow unknown typed location from being registered via the location service by configuration settings diff --git a/plugins/catalog-backend/config.d.ts b/plugins/catalog-backend/config.d.ts index 473db9a35a..950ed2f63c 100644 --- a/plugins/catalog-backend/config.d.ts +++ b/plugins/catalog-backend/config.d.ts @@ -54,23 +54,6 @@ export interface Config { */ readonly?: boolean; - /** - * Allow unknown type when create location. - * - * Setting 'locationService.create.allowUnknownType=false' forbids to create - * location with unknown type through location service. - * This is the default value. - * - * Setting 'locationService.create.allowUnknownType=true' allows to create - * location with unknown type through location service. - * - */ - locationService?: { - create?: { - allowUnknownType: boolean; - }; - }; - /** * A set of static locations that the catalog shall always keep itself * up-to-date with. This is commonly used for large, permanent integrations diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index 57b5160a97..9015bf4297 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -147,7 +147,8 @@ export class CatalogBuilder { maxSeconds: 150, }); private locationAnalyzer: LocationAnalyzer | undefined = undefined; - private permissionRules: CatalogPermissionRule[]; + private readonly permissionRules: CatalogPermissionRule[]; + private allowedLocationType: string[]; /** * Creates a catalog builder. @@ -167,6 +168,7 @@ export class CatalogBuilder { this.processorsReplace = false; this.parser = undefined; this.permissionRules = Object.values(catalogPermissionRules); + this.allowedLocationType = ['url']; } /** @@ -363,6 +365,16 @@ export class CatalogBuilder { this.permissionRules.push(...permissionRules.flat()); } + /** + * Sets up the allowed location types from being registered via the location service. + * + * @param allowedLocationTypes + */ + setAllowedLocationTypes(allowedLocationTypes: string[]) { + this.allowedLocationType = allowedLocationTypes; + return this; + } + /** * Wires up and returns all of the component parts of the catalog */ @@ -465,7 +477,9 @@ export class CatalogBuilder { const locationAnalyzer = this.locationAnalyzer ?? new RepoLocationAnalyzer(logger, integrations); const locationService = new AuthorizedLocationService( - new DefaultLocationService(locationStore, orchestrator, config), + new DefaultLocationService(locationStore, orchestrator, { + allowedLocationTypes: this.allowedLocationType, + }), permissionEvaluator, ); const refreshService = new AuthorizedRefreshService( diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts index e936d2de93..d377ece202 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts @@ -18,7 +18,6 @@ import { DefaultLocationService } from './DefaultLocationService'; import { CatalogProcessingOrchestrator } from '../processing/types'; import { LocationStore } from './types'; import { InputError } from '@backstage/errors'; -import { ConfigReader } from '@backstage/config'; describe('DefaultLocationServiceTest', () => { const orchestrator: jest.Mocked = { @@ -31,17 +30,6 @@ describe('DefaultLocationServiceTest', () => { getLocation: jest.fn(), }; - const mockConfig = (allowUnknownType: boolean) => - new ConfigReader({ - catalog: { - locationService: { - create: { - allowUnknownType, - }, - }, - }, - }); - beforeEach(() => { jest.resetAllMocks(); }); @@ -92,11 +80,7 @@ describe('DefaultLocationServiceTest', () => { errors: [], }); - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -161,11 +145,7 @@ describe('DefaultLocationServiceTest', () => { { id: '137', ...locationSpec }, ]); - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); const result = await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -219,11 +199,7 @@ describe('DefaultLocationServiceTest', () => { errors: [], }); - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); await expect( locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, @@ -253,11 +229,7 @@ describe('DefaultLocationServiceTest', () => { { id: '987', type: 'url', target: 'https://example.com' }, ]); - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); const result = await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -276,11 +248,7 @@ describe('DefaultLocationServiceTest', () => { id: '123', }); - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); await expect( locationService.createLocation(locationSpec, false), ).resolves.toEqual({ @@ -308,11 +276,9 @@ describe('DefaultLocationServiceTest', () => { id: '123', }); - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(true), - ); + const locationService = new DefaultLocationService(store, orchestrator, { + allowedLocationTypes: ['url', 'unknown'], + }); await expect( locationService.createLocation(locationSpec, false), ).resolves.toEqual({ @@ -330,28 +296,7 @@ describe('DefaultLocationServiceTest', () => { }); it('should not allow locations of unknown types by default', async () => { - const locationService = new DefaultLocationService( - store, - orchestrator, - new ConfigReader({}), - ); - await expect( - locationService.createLocation( - { - type: 'unknown', - target: 'https://backstage.io/catalog-info.yaml', - }, - false, - ), - ).rejects.toThrow(InputError); - }); - - it('should not allow locations of unknown types if configuration forbids it', async () => { - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); await expect( locationService.createLocation( { @@ -371,11 +316,7 @@ describe('DefaultLocationServiceTest', () => { errors: [new Error('Error: Unable to read url')], }); - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); await expect( locationService.createLocation( { @@ -390,11 +331,7 @@ describe('DefaultLocationServiceTest', () => { describe('listLocations', () => { it('should call locationStore.deleteLocation', async () => { - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); await locationService.listLocations(); expect(store.listLocations).toBeCalled(); }); @@ -402,11 +339,7 @@ describe('DefaultLocationServiceTest', () => { describe('deleteLocation', () => { it('should call locationStore.deleteLocation', async () => { - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); await locationService.deleteLocation('123'); expect(store.deleteLocation).toBeCalledWith('123'); }); @@ -414,11 +347,7 @@ describe('DefaultLocationServiceTest', () => { describe('getLocation', () => { it('should call locationStore.getLocation', async () => { - const locationService = new DefaultLocationService( - store, - orchestrator, - mockConfig(false), - ); + const locationService = new DefaultLocationService(store, orchestrator); await locationService.getLocation('123'); expect(store.getLocation).toBeCalledWith('123'); }); diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.ts b/plugins/catalog-backend/src/service/DefaultLocationService.ts index e70d72a9ee..6603ebc08b 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.ts @@ -26,27 +26,30 @@ import { LocationInput, LocationService, LocationStore } from './types'; import { locationSpecToMetadataName } from '../util/conversion'; import { InputError } from '@backstage/errors'; import { DeferredEntity } from '@backstage/plugin-catalog-node'; -import { Config } from '@backstage/config'; + +export type DefaultLocationServiceOptions = { + allowedLocationTypes: string[]; +}; export class DefaultLocationService implements LocationService { constructor( private readonly store: LocationStore, private readonly orchestrator: CatalogProcessingOrchestrator, - private readonly config: Config, + private readonly options: DefaultLocationServiceOptions = { + allowedLocationTypes: ['url'], + }, ) {} async createLocation( input: LocationInput, dryRun: boolean, ): Promise<{ location: Location; entities: Entity[]; exists?: boolean }> { - const allowUnknownTypeConfigName = - 'catalog.locationService.create.allowUnknownType'; - const allowUnknownType = - this.config.has(allowUnknownTypeConfigName) && - this.config.getBoolean(allowUnknownTypeConfigName); - - if (!allowUnknownType && input.type !== 'url') { - throw new InputError(`Registered locations must be of type 'url'`); + if (!this.options.allowedLocationTypes.includes(input.type)) { + throw new InputError( + `Registered locations must be of an allowed type ${JSON.stringify( + this.options.allowedLocationTypes, + )}`, + ); } if (dryRun) { return this.dryRunCreateLocation(input); From 916369ae10242ded1ff4d57ba4cb5d93249b1491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20MORI?= Date: Mon, 22 Aug 2022 11:23:14 +0200 Subject: [PATCH 3/5] Refactor test to avoid multiple decalarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane MORI --- .../service/DefaultLocationService.test.ts | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts index d377ece202..8169fc484d 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts @@ -29,6 +29,7 @@ describe('DefaultLocationServiceTest', () => { listLocations: jest.fn(), getLocation: jest.fn(), }; + const locationService = new DefaultLocationService(store, orchestrator); beforeEach(() => { jest.resetAllMocks(); @@ -80,7 +81,6 @@ describe('DefaultLocationServiceTest', () => { errors: [], }); - const locationService = new DefaultLocationService(store, orchestrator); await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -145,7 +145,6 @@ describe('DefaultLocationServiceTest', () => { { id: '137', ...locationSpec }, ]); - const locationService = new DefaultLocationService(store, orchestrator); const result = await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -199,7 +198,6 @@ describe('DefaultLocationServiceTest', () => { errors: [], }); - const locationService = new DefaultLocationService(store, orchestrator); await expect( locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, @@ -229,7 +227,6 @@ describe('DefaultLocationServiceTest', () => { { id: '987', type: 'url', target: 'https://example.com' }, ]); - const locationService = new DefaultLocationService(store, orchestrator); const result = await locationService.createLocation( { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, @@ -248,7 +245,6 @@ describe('DefaultLocationServiceTest', () => { id: '123', }); - const locationService = new DefaultLocationService(store, orchestrator); await expect( locationService.createLocation(locationSpec, false), ).resolves.toEqual({ @@ -276,11 +272,15 @@ describe('DefaultLocationServiceTest', () => { id: '123', }); - const locationService = new DefaultLocationService(store, orchestrator, { - allowedLocationTypes: ['url', 'unknown'], - }); + const locationServiceAllowingUnknownType = new DefaultLocationService( + store, + orchestrator, + { + allowedLocationTypes: ['url', 'unknown'], + }, + ); await expect( - locationService.createLocation(locationSpec, false), + locationServiceAllowingUnknownType.createLocation(locationSpec, false), ).resolves.toEqual({ entities: [], location: { @@ -296,7 +296,6 @@ describe('DefaultLocationServiceTest', () => { }); it('should not allow locations of unknown types by default', async () => { - const locationService = new DefaultLocationService(store, orchestrator); await expect( locationService.createLocation( { @@ -316,7 +315,6 @@ describe('DefaultLocationServiceTest', () => { errors: [new Error('Error: Unable to read url')], }); - const locationService = new DefaultLocationService(store, orchestrator); await expect( locationService.createLocation( { @@ -331,7 +329,6 @@ describe('DefaultLocationServiceTest', () => { describe('listLocations', () => { it('should call locationStore.deleteLocation', async () => { - const locationService = new DefaultLocationService(store, orchestrator); await locationService.listLocations(); expect(store.listLocations).toBeCalled(); }); @@ -339,7 +336,6 @@ describe('DefaultLocationServiceTest', () => { describe('deleteLocation', () => { it('should call locationStore.deleteLocation', async () => { - const locationService = new DefaultLocationService(store, orchestrator); await locationService.deleteLocation('123'); expect(store.deleteLocation).toBeCalledWith('123'); }); @@ -347,7 +343,6 @@ describe('DefaultLocationServiceTest', () => { describe('getLocation', () => { it('should call locationStore.getLocation', async () => { - const locationService = new DefaultLocationService(store, orchestrator); await locationService.getLocation('123'); expect(store.getLocation).toBeCalledWith('123'); }); From f9ad79cedc2a395ded5fd7b5b259a12f45a4bfc5 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 24 Aug 2022 21:40:09 +0200 Subject: [PATCH 4/5] chore: updating the api-report and fix the warning Signed-off-by: blam --- plugins/catalog-backend/api-report.md | 1 + plugins/catalog-backend/src/service/CatalogBuilder.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 22a7f8192c..d15c631e0c 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -150,6 +150,7 @@ export class CatalogBuilder { getDefaultProcessors(): CatalogProcessor[]; replaceEntityPolicies(policies: EntityPolicy[]): CatalogBuilder; replaceProcessors(processors: CatalogProcessor[]): CatalogBuilder; + setAllowedLocationTypes(allowedLocationTypes: string[]): this; setEntityDataParser(parser: CatalogProcessorParser): CatalogBuilder; setFieldFormatValidators(validators: Partial): CatalogBuilder; setLocationAnalyzer(locationAnalyzer: LocationAnalyzer): CatalogBuilder; diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index 9015bf4297..a8ed0f492a 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -368,7 +368,7 @@ export class CatalogBuilder { /** * Sets up the allowed location types from being registered via the location service. * - * @param allowedLocationTypes + * @param allowedLocationTypes - the allowed location types */ setAllowedLocationTypes(allowedLocationTypes: string[]) { this.allowedLocationType = allowedLocationTypes; From 7b718aae29a3e6f07385902248b5b6dd25fd049d Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 25 Aug 2022 11:38:25 +0200 Subject: [PATCH 5/5] chore: use CatalogBuilder as return type Signed-off-by: blam --- plugins/catalog-backend/api-report.md | 2 +- plugins/catalog-backend/src/service/CatalogBuilder.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index d15c631e0c..aa667b01d7 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -150,7 +150,7 @@ export class CatalogBuilder { getDefaultProcessors(): CatalogProcessor[]; replaceEntityPolicies(policies: EntityPolicy[]): CatalogBuilder; replaceProcessors(processors: CatalogProcessor[]): CatalogBuilder; - setAllowedLocationTypes(allowedLocationTypes: string[]): this; + setAllowedLocationTypes(allowedLocationTypes: string[]): CatalogBuilder; setEntityDataParser(parser: CatalogProcessorParser): CatalogBuilder; setFieldFormatValidators(validators: Partial): CatalogBuilder; setLocationAnalyzer(locationAnalyzer: LocationAnalyzer): CatalogBuilder; diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index a8ed0f492a..25f9fde313 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -370,7 +370,7 @@ export class CatalogBuilder { * * @param allowedLocationTypes - the allowed location types */ - setAllowedLocationTypes(allowedLocationTypes: string[]) { + setAllowedLocationTypes(allowedLocationTypes: string[]): CatalogBuilder { this.allowedLocationType = allowedLocationTypes; return this; }