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]),