mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
fix(earthquakes): reject malformed feature properties
This commit is contained in:
1 parent
c390724bc0
commit
ac3926c7db
4 files changed
+18
No files matched your search
@@ -130,6 +130,7 @@ export function normalizeEarthquakeSnapshot(geojson) {
|
||||
const coordinates = feature?.geometry?.coordinates;
|
||||
const properties = feature?.properties;
|
||||
if (!Array.isArray(coordinates) || coordinates.length < 2 || !properties
|
||||
|| typeof properties !== 'object' || Array.isArray(properties)
|
||||
|| (feature.geometry.type != null && feature.geometry.type !== 'Point')) return null;
|
||||
const [lon, lat, depthKm] = coordinates;
|
||||
const mag = properties.mag;
|
||||
|
||||
@@ -359,6 +359,19 @@ test('malformed earthquake refresh preserves entities, overlays, count and times
|
||||
assert.equal(await layer.update(viewer), true);
|
||||
const entity = dataSources[0].entities.values[0];
|
||||
const stats = layer.getStats();
|
||||
for (const properties of ['invalid', 123, [], true]) {
|
||||
const bad = { ...good, id: 'bad-properties', properties };
|
||||
for (const features of [[bad], [good, bad]]) {
|
||||
respond(features);
|
||||
assert.equal(await layer.update(viewer), false);
|
||||
assert.equal(dataSources[0].entities.values.length, 1);
|
||||
assert.equal(dataSources[0].entities.values[0], entity);
|
||||
assert.equal(layer.getStats().count, stats.count);
|
||||
assert.equal(layer.getStats().lastUpdate, stats.lastUpdate);
|
||||
assert.equal(layer.getStats().error, 'Malformed USGS response');
|
||||
assert.equal(publications.length, 1);
|
||||
}
|
||||
}
|
||||
for (const bad of [null, { ...good, geometry: null },
|
||||
{ ...good, geometry: { type: 'LineString', coordinates: [1, 2] } },
|
||||
{ ...good, geometry: { coordinates: [181, 20] } },
|
||||
|
||||
Reference in new issue
Block a user