package appendorder

import (
	"context"
	"reflect"
	"testing"

	"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
)

func TestTypedMergerCombinesValuesInFrameworkOrder(t *testing.T) {
	merger, err := NewTyped(func(values []string) (string, error) {
		if !reflect.DeepEqual(values, []string{"first", "second"}) {
			t.Fatalf("values=%#v", values)
		}
		return values[0] + values[1], nil
	})
	if err != nil {
		t.Fatal(err)
	}
	result, err := merger.Merge(context.Background(), contracts.TypedMergeRequest[string]{ExtractOutputs: []contracts.ExtractArtifact[string]{{ChunkIndex: 0, Value: "first"}, {ChunkIndex: 1, Value: "second"}}})
	if err != nil || result.Value != "firstsecond" {
		t.Fatalf("result=%#v err=%v", result, err)
	}
}
