package workflow import ( "testing" "github.com/samcharles93/archie-core/internal/domain/workflow/task" ) // TestConditionReadsDecodedInputs pins when: against inputs as a task carries // them, decoded with numbers kept exact. func TestConditionReadsDecodedInputs(t *testing.T) { tests := []struct { when, inputs string want bool }{ {when: "inputs.count", inputs: `{"count": 0}`, want: false}, {when: "inputs.count", inputs: `{"count": 0.0}`, want: false}, {when: "inputs.count", inputs: `{"count": 3}`, want: true}, {when: "!inputs.count", inputs: `{"count": 0}`, want: true}, {when: "inputs.flag", inputs: `{"flag": false}`, want: false}, {when: "inputs.missing", inputs: `{}`, want: false}, } for _, tt := range tests { t.Run(tt.when+" "+tt.inputs, func(t *testing.T) { inputs, err := task.DecodeInputs(tt.inputs) if err != nil { t.Fatal(err) } c, err := parseCondition(tt.when) if err != nil { t.Fatal(err) } if got := c.holds(&TaskContext{Task: &task.Task{Inputs: inputs}}); got != tt.want { t.Fatalf("holds = %v, want %v", got, tt.want) } }) } }