package admin

import "testing"

func TestCanTransitionPostStatus(t *testing.T) {
	tests := []struct {
		name string
		from PostStatus
		to   PostStatus
		want bool
	}{
		{name: "draft to published", from: PostStatusDraft, to: PostStatusPublished, want: true},
		{name: "published to draft", from: PostStatusPublished, to: PostStatusDraft, want: true},
		{name: "published to archived", from: PostStatusPublished, to: PostStatusArchived, want: true},
		{name: "archived to draft", from: PostStatusArchived, to: PostStatusDraft, want: true},
		{name: "deleted to draft", from: PostStatusDeleted, to: PostStatusDraft, want: true},
		{name: "deleted to published blocked", from: PostStatusDeleted, to: PostStatusPublished, want: false},
		{name: "unknown blocked", from: PostStatus("unknown"), to: PostStatusDraft, want: false},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			got := CanTransitionPostStatus(test.from, test.to)
			if got != test.want {
				t.Fatalf("CanTransitionPostStatus(%q, %q) = %v, want %v", test.from, test.to, got, test.want)
			}
		})
	}
}

func TestValidatePostStatusTransition(t *testing.T) {
	if err := ValidatePostStatusTransition(PostStatusDraft, PostStatusPublished); err != nil {
		t.Fatalf("valid transition returned error: %v", err)
	}
	if err := ValidatePostStatusTransition(PostStatusDeleted, PostStatusPublished); err == nil {
		t.Fatal("invalid transition returned nil error")
	}
}
