Files
archie/internal/domain/workflow/task/enablement_test.go
T
sam 8cbbdb20b5 feat(eda): per-org workflow enable/disable gating bindings
A workflow-enablement control-plane resource lists, per org, the workflows
that org has disabled. A binding targeting a disabled workflow is skipped at
dispatch like an unarmed one, is refused on save, and is flagged on the
binding list; the workflows page toggles it. Bindings now carry the org_id
column they already had in storage, over the State Store wire too.

Org-owned workflow definitions are deferred to a follow-up bead: they need
the caller's org, which the access chain resolves.
2026-09-30 02:59:23 +10:00

59 lines
1.9 KiB
Go

package task
import (
"testing"
"github.com/samcharles93/archie-core/internal/domain/org"
)
func TestWorkflowEnablementEnabled(t *testing.T) {
enablement := WorkflowEnablement{Orgs: map[org.OrgID]OrgWorkflows{
"acme": {Disabled: []string{"triage"}},
}}
cases := []struct {
org org.OrgID
workflow string
want bool
}{
{"acme", "triage", false},
{"acme", "implement", true},
{"other", "triage", true},
}
for _, c := range cases {
if got := enablement.Enabled(c.org, c.workflow); got != c.want {
t.Errorf("Enabled(%q, %q) = %v, want %v", c.org, c.workflow, got, c.want)
}
}
}
func TestWorkflowEnablementSetEnabledRoundTrips(t *testing.T) {
var enablement WorkflowEnablement
enablement = enablement.SetEnabled("acme", "triage", false)
enablement = enablement.SetEnabled("acme", "triage", false)
if enablement.Enabled("acme", "triage") || len(enablement.Orgs["acme"].Disabled) != 1 {
t.Fatalf("disable twice: %+v", enablement)
}
enablement = enablement.SetEnabled("acme", "triage", true)
if !enablement.Enabled("acme", "triage") {
t.Fatalf("re-enable: %+v", enablement)
}
}
func TestWorkflowEnablementValidate(t *testing.T) {
cases := map[string]struct {
enablement WorkflowEnablement
ok bool
}{
"empty": {WorkflowEnablement{}, true},
"valid": {WorkflowEnablement{Orgs: map[org.OrgID]OrgWorkflows{"acme": {Disabled: []string{"triage"}}}}, true},
"blank org": {WorkflowEnablement{Orgs: map[org.OrgID]OrgWorkflows{" ": {Disabled: []string{"triage"}}}}, false},
"blank workflow": {WorkflowEnablement{Orgs: map[org.OrgID]OrgWorkflows{"acme": {Disabled: []string{""}}}}, false},
"duplicate entry": {WorkflowEnablement{Orgs: map[org.OrgID]OrgWorkflows{"acme": {Disabled: []string{"triage", "triage"}}}}, false},
}
for name, c := range cases {
if err := c.enablement.Validate(); (err == nil) != c.ok {
t.Errorf("%s: Validate() = %v, want ok=%v", name, err, c.ok)
}
}
}