Skip to content

Commit

Permalink
fix(searcheffects): do not check geojson validity if geom undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Feb 19, 2024
1 parent 266c975 commit 1510831
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
15 changes: 15 additions & 0 deletions libs/feature/search/src/lib/state/effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
22 changes: 12 additions & 10 deletions libs/feature/search/src/lib/state/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down

0 comments on commit 1510831

Please sign in to comment.