An action judgement holds at propose and wait is no longer a dead end. The new approvals module owns the request: it binds to the decision and the action's digest, so an answer covers the action the person was shown and nothing else, and it settles once. The answer wakes the run, which judges the action again and runs it only as the approval allows: a refusal still refuses, an altered input runs nothing, and a judgement that came back worse runs nothing on that approval. The composer carries the request as a message with the request id and its deadline, and its answer is a message too, so the trail shows what was asked and what was answered. A request nobody answers inside its deadline is settled as expired and nothing runs. How long a request waits is an organisation setting, edited in the dashboard and stored in milliseconds, because a Postgres interval scans as text. A run pins the deadline it started with, like its model. An agent that proposes the same action twice is asked about it once, and the notification says when the investigation proposed nothing at all.
43 lines
1.6 KiB
Go
43 lines
1.6 KiB
Go
package runs
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/modules/judgement"
|
|
)
|
|
|
|
// TestHeldByJudgementAsksOncePerAction guards against asking a person twice: an
|
|
// agent that proposes the same action more than once gets one request, an
|
|
// action that runs unattended is not put to them, and a refusal is not offered
|
|
// either.
|
|
func TestHeldByJudgementAsksOncePerAction(t *testing.T) {
|
|
decided := func(level judgement.Level, digest string) judgement.Decision {
|
|
return judgement.Decision{Level: level, Action: judgement.Action{Digest: digest}}
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
in []judgement.Decision
|
|
wantN int
|
|
}{
|
|
{name: "nothing proposed asks nothing", in: nil, wantN: 0},
|
|
{name: "a held action is asked about", in: []judgement.Decision{decided(judgement.ProposeAndWait, "a")}, wantN: 1},
|
|
{name: "the same action twice is asked about once", in: []judgement.Decision{
|
|
decided(judgement.ProposeAndWait, "a"), decided(judgement.ProposeAndWait, "a"),
|
|
}, wantN: 1},
|
|
{name: "two different actions are both asked about", in: []judgement.Decision{
|
|
decided(judgement.ProposeAndWait, "a"), decided(judgement.Escalate, "b"),
|
|
}, wantN: 2},
|
|
{name: "an action that runs unattended is not asked about", in: []judgement.Decision{
|
|
decided(judgement.ActAndTell, "a"),
|
|
}, wantN: 0},
|
|
{name: "a refused action is not asked about", in: []judgement.Decision{decided(judgement.Never, "a")}, wantN: 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := len(heldByJudgement(tt.in)); got != tt.wantN {
|
|
t.Fatalf("asked about %d actions, want %d", got, tt.wantN)
|
|
}
|
|
})
|
|
}
|
|
}
|