package module

import (
	"testing"

	"kra/pkg/database/migration"
)

func TestCatalogCollectsContributions(t *testing.T) {
	catalog := Catalog{Definitions: []Definition{
		{
			Name:       "system",
			Migrations: []migration.Step{{ID: "system_schema"}},
			Surface:    Surface{Menus: []Menu{{Name: "users"}}, APIs: []API{{Path: "/users"}}},
			TimedTasks: []TimedTask{{Name: "system.cleanup"}},
		},
		{
			Name:       "orders",
			Migrations: []migration.Step{{ID: "orders_schema"}},
			Surface:    Surface{Menus: []Menu{{Name: "orders"}}, APIs: []API{{Path: "/orders"}}},
			TimedTasks: []TimedTask{{Name: "orders.expire"}},
		},
	}}

	if got := catalog.MigrationSteps(); len(got) != 2 || got[0].ID != "system_schema" || got[1].ID != "orders_schema" {
		t.Fatalf("unexpected migrations: %#v", got)
	}
	if got := catalog.Definitions[1].Surface; len(got.Menus) != 1 || len(got.APIs) != 1 || got.Menus[0].Name != "orders" {
		t.Fatalf("unexpected surface: %#v", got)
	}
	if got := catalog.DefaultTimedTasks(); len(got) != 2 || got[1].Name != "orders.expire" {
		t.Fatalf("unexpected default tasks: %#v", got)
	}
}
