package thread

import (
	"testing"

	"aegis/internal/nntp"
)

func TestBuildUsesLastReference(t *testing.T) {
	roots := Build([]nntp.ArticleHeader{
		{Number: 1, MessageID: "<root@example>", Subject: "topic"},
		{Number: 2, MessageID: "<reply@example>", References: "<root@example>"},
		{Number: 3, MessageID: "<nested@example>", References: "<root@example> <reply@example>"},
	})
	if len(roots) != 1 || len(roots[0].Children) != 1 || len(roots[0].Children[0].Children) != 1 {
		t.Fatalf("unexpected thread tree: %#v", roots)
	}
}
