package storage

import (
	"testing"

	"3588AdminBackend/internal/models"
)

func TestDevicesRepoUpsertsRuntimeSnapshot(t *testing.T) {
	store := openTestStore(t)
	defer store.Close()

	repo := NewDevicesRepo(store.DB())
	dev := &models.Device{
		DeviceID:   "edge-01",
		Hostname:   "orangepi5plus",
		IP:         "10.0.0.8",
		AgentPort:  9100,
		MediaPort:  9000,
		DeviceName: "入口识别节点",
		Online:     true,
		Version:    "1.0.0",
	}
	if err := repo.Upsert(dev); err != nil {
		t.Fatalf("Upsert: %v", err)
	}

	saved, err := repo.List()
	if err != nil {
		t.Fatalf("List: %v", err)
	}
	if len(saved) != 1 {
		t.Fatalf("expected one device snapshot, got %d", len(saved))
	}
	if saved[0].DeviceID != "edge-01" || saved[0].IP != "10.0.0.8" || !saved[0].Online {
		t.Fatalf("unexpected saved device snapshot: %#v", saved[0])
	}
}
