package storage

import "testing"

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

	repo := NewAuditLogsRepo(store.DB())
	if err := repo.Append(AuditLogRecord{
		Actor:       "system",
		Action:      "config_apply",
		TargetType:  "device",
		TargetID:    "edge-01",
		DetailsJSON: `{"task_id":"task-1"}`,
	}); err != nil {
		t.Fatalf("Append: %v", err)
	}

	items, err := repo.List()
	if err != nil {
		t.Fatalf("List: %v", err)
	}
	if len(items) != 1 {
		t.Fatalf("expected one audit log, got %d", len(items))
	}
	if items[0].Action != "config_apply" || items[0].TargetID != "edge-01" {
		t.Fatalf("unexpected audit log: %#v", items[0])
	}
}
