package service

import "testing"

func TestBootstrapStoreLoadsSeededUsersAndContent(t *testing.T) {
	store := newTestGORMStore(t)

	user, ok, err := store.UserByLogin(t.Context(), "demo_admin")
	if err != nil {
		t.Fatalf("user by login: %v", err)
	}
	if !ok {
		t.Fatal("expected seeded admin user")
	}
	if user.Name == "" {
		t.Fatal("expected seeded admin profile")
	}

	items, err := store.ListContent(t.Context(), ContentFilter{})
	if err != nil {
		t.Fatalf("list content: %v", err)
	}
	if len(items) == 0 {
		t.Fatal("expected seeded content")
	}
	if items[0].ID == "" {
		t.Fatal("expected persisted content ids")
	}
}

func newTestGORMStore(t *testing.T) *gormStore {
	t.Helper()
	db, err := openDB("file::memory:?cache=shared")
	if err != nil {
		t.Fatalf("open test db: %v", err)
	}
	store, err := newGORMStore(db)
	if err != nil {
		t.Fatalf("new gorm store: %v", err)
	}
	return store
}
