mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-05 16:02:17 +00:00
GET /api/devices now returns vowifi_active and vowifi_health from the same sources as overview. Incoming SMS can be subscribed at GET /api/sms/events with Last-Event-ID or after_id; payload matches notifications latest.
120 lines
3.6 KiB
Go
120 lines
3.6 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/iniwex5/vowifi-go/runtimehost"
|
|
"github.com/yibaiba/hideck/internal/config"
|
|
"github.com/yibaiba/hideck/internal/device"
|
|
"github.com/yibaiba/hideck/internal/modem"
|
|
)
|
|
|
|
func TestApplyLifecycleToOfflineOverviewItemKeepsRecoveryVisible(t *testing.T) {
|
|
pool := device.NewPool(&config.Config{})
|
|
pool.MarkLifecycleRecovery("dev1", device.LifecyclePhaseUSBWait, "manual_reboot", 3*time.Minute)
|
|
server := &Server{pool: pool}
|
|
|
|
item := deviceMgmtOverviewLiteItem{
|
|
ID: "dev1",
|
|
Running: false,
|
|
Healthy: false,
|
|
ControlOnline: false,
|
|
}
|
|
|
|
server.applyLifecycleToOverviewLiteItem(&item, nil, config.DeviceConfig{ID: "dev1"})
|
|
|
|
if item.LifecyclePhase != string(device.LifecyclePhaseUSBWait) {
|
|
t.Fatalf("LifecyclePhase=%q want %q", item.LifecyclePhase, device.LifecyclePhaseUSBWait)
|
|
}
|
|
if !item.PhysicalPresent {
|
|
t.Fatal("PhysicalPresent=false want true during active recovery")
|
|
}
|
|
if item.WorkerRunning {
|
|
t.Fatal("WorkerRunning=true want false")
|
|
}
|
|
}
|
|
|
|
func TestApplyLifecycleToListItemDerivesRadioRegistered(t *testing.T) {
|
|
pool := device.NewPool(&config.Config{})
|
|
pool.MarkLifecycleRecovery("dev1", device.LifecyclePhaseQMIStarting, "startup", 3*time.Minute)
|
|
server := &Server{pool: pool}
|
|
|
|
item := deviceMgmtListItem{
|
|
ID: "dev1",
|
|
Running: true,
|
|
Healthy: true,
|
|
ControlOnline: true,
|
|
NetworkConnected: true,
|
|
Modem: deviceMgmtListModem{RegStatus: 5},
|
|
}
|
|
|
|
server.applyLifecycleToListItem(&item, true, config.DeviceConfig{ID: "dev1"})
|
|
|
|
if !item.RadioRegistered {
|
|
t.Fatal("RadioRegistered=false want true for reg status 5")
|
|
}
|
|
if !item.DataConnected {
|
|
t.Fatal("DataConnected=false want true when network is connected")
|
|
}
|
|
if item.LifecyclePhase != string(device.LifecyclePhaseOnline) {
|
|
t.Fatalf("LifecyclePhase=%q want %q", item.LifecyclePhase, device.LifecyclePhaseOnline)
|
|
}
|
|
}
|
|
|
|
func TestDeviceMgmtListItemJSONIncludesVoWiFiActive(t *testing.T) {
|
|
health := device.WiFiCallingHealthSnapshot{State: "healthy", Active: true, Measured: true}
|
|
body, err := json.Marshal(deviceMgmtListItem{
|
|
ID: "dev1",
|
|
VoWiFiActive: true,
|
|
VoWiFiHealth: &health,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var payload map[string]any
|
|
if err := json.Unmarshal(body, &payload); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if payload["vowifi_active"] != true {
|
|
t.Fatalf("vowifi_active=%v want true in %s", payload["vowifi_active"], body)
|
|
}
|
|
healthPayload, ok := payload["vowifi_health"].(map[string]any)
|
|
if !ok || healthPayload["state"] != "healthy" {
|
|
t.Fatalf("vowifi_health=%v want state=healthy in %s", payload["vowifi_health"], body)
|
|
}
|
|
}
|
|
|
|
func TestVoWiFiRuntimeDTOExportsReadinessFields(t *testing.T) {
|
|
dto := runtimeStateToDTO(runtimehost.State{
|
|
Phase: runtimehost.PhaseSIMReady,
|
|
DeviceID: "dev1",
|
|
SIMReady: true,
|
|
SMSMOReady: true,
|
|
LastReason: "sim_ready",
|
|
}, modem.DeviceStatus{IMSI: "001010123456789"})
|
|
|
|
if !dto.SIMReady {
|
|
t.Fatalf("SIMReady=false in dto=%+v", dto)
|
|
}
|
|
body, err := json.Marshal(dto)
|
|
if err != nil {
|
|
t.Fatalf("Marshal() err=%v", err)
|
|
}
|
|
raw := string(body)
|
|
if !strings.Contains(raw, `"sim_ready":true`) {
|
|
t.Fatalf("json=%s, want sim_ready=true", raw)
|
|
}
|
|
if !strings.Contains(raw, `"sms_mo_ready":true`) {
|
|
t.Fatalf("json=%s, want sms_mo_ready=true", raw)
|
|
}
|
|
if strings.Contains(raw, "radio_ready") {
|
|
t.Fatalf("json=%s should not contain radio_ready", raw)
|
|
}
|
|
if !strings.Contains(raw, `"mwi_known":false`) || !strings.Contains(raw, `"mwi_messages_waiting":false`) {
|
|
t.Fatalf("json=%s, want empty MWI state", raw)
|
|
}
|
|
}
|