From 27506bbaa9cb2a2d818c987320e0391f873cd14c Mon Sep 17 00:00:00 2001 From: adust09 Date: Mon, 16 Mar 2026 14:43:01 +0900 Subject: [PATCH] test: add JSDF bases tests (RED phase) - Add gsdf/msdf/asdf to known_branches in test_branch_values_are_known - Add test_includes_jsdf_bases for Yonaguni, Naha, Kure - Add test_colocated_bases_have_separate_entries for Misawa - Add buildMilitaryBasesGeoJSON tests with ASDF branch validation Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/tests/test_military_bases.py | 18 +++++++++++- .../src/__tests__/map/geoJSONBuilders.test.ts | 29 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/backend/tests/test_military_bases.py b/backend/tests/test_military_bases.py index eecd967..d8fb1a1 100644 --- a/backend/tests/test_military_bases.py +++ b/backend/tests/test_military_bases.py @@ -35,7 +35,7 @@ class TestMilitaryBasesData: assert -180 <= entry["lng"] <= 180, f"{entry['name']} has invalid lng" def test_branch_values_are_known(self): - known_branches = {"air_force", "navy", "marines", "army"} + known_branches = {"air_force", "navy", "marines", "army", "gsdf", "msdf", "asdf"} raw = json.loads(BASES_PATH.read_text(encoding="utf-8")) for entry in raw: assert entry["branch"] in known_branches, f"{entry['name']} has unknown branch: {entry['branch']}" @@ -60,3 +60,19 @@ class TestFetchMilitaryBases: assert "Kadena Air Base" in names assert "Fleet Activities Yokosuka" in names assert "Andersen Air Force Base" in names + + def test_includes_jsdf_bases(self): + from services.fetchers.infrastructure import fetch_military_bases + fetch_military_bases() + with _data_lock: + names = {b["name"] for b in latest_data["military_bases"]} + assert "Yonaguni Garrison" in names + assert "Naha Air Base" in names + assert "Kure Naval Base" in names + + def test_colocated_bases_have_separate_entries(self): + from services.fetchers.infrastructure import fetch_military_bases + fetch_military_bases() + with _data_lock: + misawa_entries = [b for b in latest_data["military_bases"] if "Misawa" in b["name"]] + assert len(misawa_entries) == 2, f"Expected 2 Misawa entries, got {len(misawa_entries)}" diff --git a/frontend/src/__tests__/map/geoJSONBuilders.test.ts b/frontend/src/__tests__/map/geoJSONBuilders.test.ts index dfd0549..cbe1628 100644 --- a/frontend/src/__tests__/map/geoJSONBuilders.test.ts +++ b/frontend/src/__tests__/map/geoJSONBuilders.test.ts @@ -2,9 +2,34 @@ import { describe, it, expect } from 'vitest'; import { buildEarthquakesGeoJSON, buildJammingGeoJSON, buildCctvGeoJSON, buildKiwisdrGeoJSON, buildFirmsGeoJSON, buildInternetOutagesGeoJSON, buildDataCentersGeoJSON, - buildGdeltGeoJSON, buildLiveuaGeoJSON, buildFrontlineGeoJSON + buildGdeltGeoJSON, buildLiveuaGeoJSON, buildFrontlineGeoJSON, buildMilitaryBasesGeoJSON } from '@/components/map/geoJSONBuilders'; -import type { Earthquake, GPSJammingZone, FireHotspot, InternetOutage, DataCenter, GDELTIncident, LiveUAmapIncident, CCTVCamera, KiwiSDR } from '@/types/dashboard'; +import type { Earthquake, GPSJammingZone, FireHotspot, InternetOutage, DataCenter, GDELTIncident, LiveUAmapIncident, CCTVCamera, KiwiSDR, MilitaryBase } from '@/types/dashboard'; + +// ─── Military Bases ──────────────────────────────────────────────────────── + +describe('buildMilitaryBasesGeoJSON', () => { + it('returns null for empty/undefined input', () => { + expect(buildMilitaryBasesGeoJSON(undefined)).toBeNull(); + expect(buildMilitaryBasesGeoJSON([])).toBeNull(); + }); + + it('builds valid Feature for ASDF branch base', () => { + const bases: MilitaryBase[] = [ + { name: 'Naha Air Base', country: 'Japan', operator: 'ASDF 9th Air Wing', branch: 'asdf', lat: 26.196, lng: 127.646 }, + ]; + const result = buildMilitaryBasesGeoJSON(bases); + expect(result).not.toBeNull(); + expect(result!.type).toBe('FeatureCollection'); + expect(result!.features).toHaveLength(1); + + const f = result!.features[0]; + expect(f.geometry).toEqual({ type: 'Point', coordinates: [127.646, 26.196] }); + expect(f.properties?.type).toBe('military_base'); + expect(f.properties?.branch).toBe('asdf'); + expect(f.properties?.name).toBe('Naha Air Base'); + }); +}); // ─── Earthquakes ────────────────────────────────────────────────────────────