From 151083119729bc2ec705312a0da440156ce6ff1c Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 19 Feb 2024 14:05:22 +0100 Subject: [PATCH 1/2] fix(searcheffects): do not check geojson validity if geom undefined --- .../search/src/lib/state/effects.spec.ts | 15 +++++++++++++ libs/feature/search/src/lib/state/effects.ts | 22 ++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libs/feature/search/src/lib/state/effects.spec.ts b/libs/feature/search/src/lib/state/effects.spec.ts index 218190d26a..98d60c2e54 100644 --- a/libs/feature/search/src/lib/state/effects.spec.ts +++ b/libs/feature/search/src/lib/state/effects.spec.ts @@ -483,6 +483,21 @@ describe('Effects', () => { ) }) }) + describe('when geometry is undefined', () => { + beforeEach(() => { + effects['filterGeometry$'] = of(undefined) as any + effects = TestBed.inject(SearchEffects) + actions$ = of(new RequestMoreResults('main')) + }) + it('skips the geometry in the search', async () => { + await firstValueFrom(effects.loadResults$) + expect(repository.search).toHaveBeenCalledWith( + expect.not.objectContaining({ + filterGeometry: { type: 'Polygon', coordinates: [[]] }, + }) + ) + }) + }) }) describe('when useSpatialFilter is disabled', () => { beforeEach(() => { diff --git a/libs/feature/search/src/lib/state/effects.ts b/libs/feature/search/src/lib/state/effects.ts index 5c411efce4..8735ea60cc 100644 --- a/libs/feature/search/src/lib/state/effects.ts +++ b/libs/feature/search/src/lib/state/effects.ts @@ -130,17 +130,19 @@ export class SearchEffects { } return this.filterGeometry$.pipe( tap((geom) => { - try { - const trace = validGeoJson(geom, true) as string[] - if (trace?.length > 0) { - throw new Error(trace.join('\n')) + if (geom) { + try { + const trace = validGeoJson(geom, true) as string[] + if (trace?.length > 0) { + throw new Error(trace.join('\n')) + } + } catch (error) { + console.warn( + 'Error while parsing the geometry filter\n', + error + ) + throw new Error() } - } catch (error) { - console.warn( - 'Error while parsing the geometry filter\n', - error - ) - throw new Error() } }), map((geom) => [state, favorites, geom]), From 696ca821a12189c6fd5e184f0a61f4493a91bbee Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 21 Feb 2024 10:42:01 +0100 Subject: [PATCH 2/2] review(effects): address comments --- .../search/src/lib/state/effects.spec.ts | 4 +-- libs/feature/search/src/lib/state/effects.ts | 29 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/libs/feature/search/src/lib/state/effects.spec.ts b/libs/feature/search/src/lib/state/effects.spec.ts index 98d60c2e54..d7c49215bc 100644 --- a/libs/feature/search/src/lib/state/effects.spec.ts +++ b/libs/feature/search/src/lib/state/effects.spec.ts @@ -492,8 +492,8 @@ describe('Effects', () => { it('skips the geometry in the search', async () => { await firstValueFrom(effects.loadResults$) expect(repository.search).toHaveBeenCalledWith( - expect.not.objectContaining({ - filterGeometry: { type: 'Polygon', coordinates: [[]] }, + expect.objectContaining({ + filterGeometry: undefined, }) ) }) diff --git a/libs/feature/search/src/lib/state/effects.ts b/libs/feature/search/src/lib/state/effects.ts index 8735ea60cc..4cc5cda439 100644 --- a/libs/feature/search/src/lib/state/effects.ts +++ b/libs/feature/search/src/lib/state/effects.ts @@ -126,28 +126,27 @@ export class SearchEffects { ), switchMap(([state, favorites]) => { if (!state.params.useSpatialFilter || !this.filterGeometry$) { - return of([state, favorites, null]) + return of([state, favorites, undefined]) } return this.filterGeometry$.pipe( tap((geom) => { - if (geom) { - try { - const trace = validGeoJson(geom, true) as string[] - if (trace?.length > 0) { - throw new Error(trace.join('\n')) - } - } catch (error) { - console.warn( - 'Error while parsing the geometry filter\n', - error - ) - throw new Error() + if (!geom) return + try { + const trace = validGeoJson(geom, true) as string[] + if (trace?.length > 0) { + throw new Error(trace.join('\n')) } + } catch (error) { + console.warn( + 'Error while parsing the geometry filter\n', + error + ) + throw new Error() } }), map((geom) => [state, favorites, geom]), catchError((e) => { - return of([state, favorites, null]) + return of([state, favorites, undefined]) }) ) }), @@ -155,7 +154,7 @@ export class SearchEffects { ([state, favorites, geometry]: [ SearchStateSearch, string[], - Geometry | null + Geometry | undefined ]) => { const { currentPage, pageSize, sort } = state.params const filters = {