// Copyright © 2026 Setti Solutions S.R.L, www.setti.md. All rights reserved. package main import ( "os" "path/filepath" "testing" ) // The heartbeat's setup_done: the panel's flag, false without the file. func TestSetupDone(t *testing.T) { p := filepath.Join(t.TempDir(), "config.json") if setupDone(p) { t.Fatal("no file: not set up") } os.WriteFile(p, []byte(`{"admin": "x", "setup_done": true}`), 0o600) if !setupDone(p) { t.Fatal("set up") } os.WriteFile(p, []byte(`{"setup_done": "yes"}`), 0o600) if setupDone(p) { t.Fatal("not a bool") } } // The heartbeat's location: country and postcode (never lat/lon), "at". func TestBoxLocation(t *testing.T) { p := filepath.Join(t.TempDir(), "config.json") if boxLocation(p) != nil { t.Fatal("no file: none") } os.WriteFile(p, []byte(`{"location": {"country": "DE", "postal_code": "10115", "latitude": 52.53, "longitude": 13.38, "at": 1761800000}}`), 0o600) l := boxLocation(p) if l["country"] != "DE" || l["postal_code"] != "10115" || l["at"] != int64(1761800000) || l["latitude"] != nil || len(l) != 3 { t.Fatalf("%v", l) } os.WriteFile(p, []byte(`{"location": {"country": "AT"}}`), 0o600) if l := boxLocation(p); l["country"] != "AT" || l["postal_code"] != "" || l["at"] != nil { t.Fatalf("%v", l) } os.WriteFile(p, []byte(`{"location": {"latitude": 1}}`), 0o600) if boxLocation(p) != nil { t.Fatal("no country: none") } }