mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
Merge branch 'main' into codex/cctv-shared-batch-20261019
This commit is contained in:
6 files changed
+129
-22
No files matched your search
@@ -335,6 +335,7 @@ test('the Google places route throttles by default and keeps its places[] contra
|
||||
const overLimit = await request(handler, { url, method: 'GET' });
|
||||
assert.equal(overLimit.status, 429);
|
||||
assert.equal(overLimit.headers['retry-after'], '5');
|
||||
assert.equal(overLimit.headers['cache-control'], 'no-store');
|
||||
// Every error response on this route carries places[]; the client reads it
|
||||
// unconditionally, so a throttled reply must not be the one shape that omits it.
|
||||
assert.deepEqual(JSON.parse(overLimit.body).places, []);
|
||||
|
||||
@@ -134,6 +134,7 @@ test('a bad or keyless geocode request never reaches Google', async () => {
|
||||
]) {
|
||||
const response = await invokeRoute(routes.get(path), { url });
|
||||
assert.equal(response.statusCode, 400);
|
||||
assert.equal(response.headers['cache-control'], 'no-store');
|
||||
assert.deepEqual(response.body.results, []);
|
||||
assert.equal(response.body.status, 'REQUEST_DENIED');
|
||||
}
|
||||
@@ -144,6 +145,7 @@ test('a bad or keyless geocode request never reaches Google', async () => {
|
||||
url: '/?address=Austin&lat=30&lon=-97',
|
||||
});
|
||||
assert.equal(rejected.statusCode, 405);
|
||||
assert.equal(rejected.headers['cache-control'], 'no-store');
|
||||
}
|
||||
|
||||
// Keyless is an empty capability, not an outage: a 200 the browser adapters
|
||||
@@ -167,6 +169,33 @@ test('a bad or keyless geocode request never reaches Google', async () => {
|
||||
assert.deepEqual(upstream, []);
|
||||
});
|
||||
|
||||
test('only a Geocoding answer is kept by the browser', async () => {
|
||||
// Google can report a denied key or exhausted quota with HTTP 200.
|
||||
for (const [httpStatus, status, cacheControl] of [
|
||||
[200, 'OK', 'private, max-age=300'],
|
||||
[200, 'ZERO_RESULTS', 'private, max-age=300'],
|
||||
[200, 'REQUEST_DENIED', 'no-store'],
|
||||
[200, 'OVER_QUERY_LIMIT', 'no-store'],
|
||||
[200, 'OVER_DAILY_LIMIT', 'no-store'],
|
||||
[200, 'UNKNOWN_ERROR', 'no-store'],
|
||||
[503, 'ZERO_RESULTS', 'no-store'],
|
||||
]) {
|
||||
const routes = installRoutes({
|
||||
fetchImpl: async () =>
|
||||
Response.json({ status, results: [] }, { status: httpStatus }),
|
||||
});
|
||||
for (const path of ['/api/google/geocode', '/api/google/reverse-geocode']) {
|
||||
const label = `${path} ${httpStatus} ${status}`;
|
||||
const response = await invokeRoute(routes.get(path), {
|
||||
url: '/?address=Austin&lat=30&lon=-97',
|
||||
});
|
||||
assert.equal(response.statusCode, httpStatus, label);
|
||||
assert.equal(response.body.status, status, label);
|
||||
assert.equal(response.headers['cache-control'], cacheControl, label);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('an upstream failure reaches the browser as fixed public text', async () => {
|
||||
const routes = installRoutes({
|
||||
fetchImpl: async () => {
|
||||
@@ -178,6 +207,7 @@ test('an upstream failure reaches the browser as fixed public text', async () =>
|
||||
url: '/?address=Austin&lat=30&lon=-97',
|
||||
});
|
||||
assert.equal(response.statusCode, 502);
|
||||
assert.equal(response.headers['cache-control'], 'no-store');
|
||||
assert.deepEqual(response.body, {
|
||||
status: 'UNKNOWN_ERROR',
|
||||
results: [],
|
||||
|
||||
@@ -52,6 +52,11 @@ function install(register) {
|
||||
};
|
||||
}
|
||||
|
||||
const ROUTES = [
|
||||
['/api/google/nearby-places', '?lat=30&lon=-97'],
|
||||
['/api/google/text-search', '?q=museum&lat=30&lon=-97'],
|
||||
];
|
||||
|
||||
test('nearby labels rank landmarks, deduplicate names/addresses and bound the projection', () => {
|
||||
const place = (name, types, longitude = 0) => ({
|
||||
displayName: { text: name },
|
||||
@@ -176,16 +181,70 @@ for (const preview of [false, true]) {
|
||||
JSON.parse(calls[1].options.body).locationBias.circle.radius,
|
||||
50,
|
||||
);
|
||||
assert.equal((await request(search, '?lat=30&lon=-97')).statusCode, 400);
|
||||
assert.equal((await request(nearby, '?lat=bad&lon=-97')).statusCode, 400);
|
||||
assert.equal((await request(nearby, '', 'POST')).statusCode, 405);
|
||||
for (const [route, query, method, statusCode] of [
|
||||
[search, '?lat=30&lon=-97', 'GET', 400],
|
||||
[nearby, '?lat=bad&lon=-97', 'GET', 400],
|
||||
[nearby, '', 'POST', 405],
|
||||
]) {
|
||||
const refused = await request(route, query, method);
|
||||
assert.equal(refused.statusCode, statusCode, `${method} ${route}`);
|
||||
assert.equal(
|
||||
refused.headers['cache-control'],
|
||||
'no-store',
|
||||
`${method} ${route}`,
|
||||
);
|
||||
}
|
||||
t.mock.method(globalThis, 'fetch', async () =>
|
||||
Response.json({ error: { message: 'Denied' } }, { status: 403 }),
|
||||
);
|
||||
assert.deepEqual((await request(search, '?q=museum&lat=30&lon=-97')).body, {
|
||||
places: [],
|
||||
error: 'Denied',
|
||||
});
|
||||
for (const [route, query] of ROUTES) {
|
||||
const refused = await request(route, query);
|
||||
assert.equal(refused.statusCode, 403, route);
|
||||
assert.equal(refused.headers['cache-control'], 'no-store', route);
|
||||
assert.deepEqual(refused.body, { places: [], error: 'Denied' }, route);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (const [name, upstream, statusCode, cacheControl] of [
|
||||
[
|
||||
'unreadable 200',
|
||||
() => new Response('<html>not json</html>', { status: 200 }),
|
||||
502,
|
||||
'no-store',
|
||||
],
|
||||
[
|
||||
'unreadable 429',
|
||||
() => new Response('<html>Too Many Requests</html>', { status: 429 }),
|
||||
429,
|
||||
'no-store',
|
||||
],
|
||||
[
|
||||
'transport failure',
|
||||
() => {
|
||||
throw new TypeError('fetch failed');
|
||||
},
|
||||
502,
|
||||
'no-store',
|
||||
],
|
||||
// Google returns {} for a successful search with no places.
|
||||
['empty answer ({})', () => Response.json({}), 200, 'private, max-age=300'],
|
||||
]) {
|
||||
test(`a Places ${name} is a ${statusCode} with Cache-Control ${cacheControl}`, async () => {
|
||||
const request = install((middlewares) =>
|
||||
googlePlacesContextProxy({
|
||||
resolveApiKey: () => 'fixture-server-key',
|
||||
fetchImpl: async () => upstream(),
|
||||
}).configureServer({ middlewares }),
|
||||
);
|
||||
for (const [route, query] of ROUTES) {
|
||||
const res = await request(route, query);
|
||||
assert.equal(res.statusCode, statusCode, route);
|
||||
assert.equal(res.headers['cache-control'], cacheControl, route);
|
||||
assert.deepEqual(res.body.places, [], route);
|
||||
if (statusCode === 200) assert.equal(res.body.error, null, route);
|
||||
else assert.ok(res.body.error, route);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user