mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 02:14:01 +00:00
fix(osm): default an absent /api/osm/features limit to 500
Without a limit parameter the route read null, Number(null) is 0, and the clamp turned that into a one-feature list. An absent or empty limit now gets the documented default of 500.
This commit is contained in:
1 parent
68667e2e3c
commit
3d2896cf27
2 files changed
+29
-1
No files matched your search
@@ -109,7 +109,13 @@ export function compileOsmFeatureQuery(request = {}) {
|
||||
? 'That area is too large to search; narrow it down.'
|
||||
: 'That area is too large to list; count first or narrow it down.',
|
||||
);
|
||||
const requested = Number(request.limit);
|
||||
// An absent or empty limit is the default, not Number(null) = 0.
|
||||
const requested =
|
||||
request.limit === null ||
|
||||
request.limit === undefined ||
|
||||
String(request.limit).trim() === ''
|
||||
? NaN
|
||||
: Number(request.limit);
|
||||
const limit = Math.max(
|
||||
1,
|
||||
Math.min(
|
||||
|
||||
@@ -256,6 +256,28 @@ function mount(
|
||||
return { request, start, writes };
|
||||
}
|
||||
|
||||
test('a search without a limit lists up to 500 features', async () => {
|
||||
const sent = [];
|
||||
const { request } = mount(async (body) => {
|
||||
sent.push(decodeURIComponent(body));
|
||||
return { status: 200, body: JSON.stringify({ elements: [] }) };
|
||||
});
|
||||
for (const search of [
|
||||
'preset=hospital&bbox=0,0,1,1',
|
||||
'preset=school&bbox=0,0,1,1&limit=',
|
||||
]) {
|
||||
const answer = await request(search);
|
||||
assert.equal(answer.status, 200, search);
|
||||
}
|
||||
assert.equal(sent.length, 2);
|
||||
for (const ql of sent) assert.match(ql, /out center tags 500;$/);
|
||||
assert.equal(
|
||||
compileOsmFeatureQuery({ preset: 'hospital', bbox: '0,0,1,1', limit: '7' })
|
||||
.limit,
|
||||
7,
|
||||
);
|
||||
});
|
||||
|
||||
test('the route answers, caches, and shares upstream slots fairly', async () => {
|
||||
const release = [];
|
||||
let upstream = 0;
|
||||
|
||||
Reference in new issue
Block a user