Files
iqudo-top1/internal/run/mapping_test.go
2026-08-18 16:27:02 +08:00

25 lines
1023 B
Go

package run
import (
"reflect"
"testing"
"git.iwork-ai.com/xdc/iqudo-top1/internal/model"
)
func TestMapScenarioInputSupportsArrays(t *testing.T) {
fields := []model.ScenarioField{{FieldKey: "customer_name", SourcePath: "customer.name"}, {FieldKey: "product_ids", SourcePath: "order.items[*].product_id"}}
input := map[string]interface{}{"customer": map[string]interface{}{"name": "王女士"}, "order": map[string]interface{}{"items": []interface{}{map[string]interface{}{"product_id": "P1"}, map[string]interface{}{"product_id": "P2"}}}}
want := map[string]interface{}{"customer_name": "王女士", "product_ids": []interface{}{"P1", "P2"}}
if got := mapScenarioInput(fields, input); !reflect.DeepEqual(got, want) {
t.Fatalf("mapped input = %#v, want %#v", got, want)
}
}
func TestMergeValuesUsesExplicitValues(t *testing.T) {
got := mergeValues(map[string]interface{}{"name": "mapped"}, map[string]interface{}{"name": "explicit"})
if got["name"] != "explicit" {
t.Fatalf("name = %v", got["name"])
}
}