mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package approval
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestNextStatus(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
current string
|
|
action string
|
|
want string
|
|
wantErr error
|
|
}{
|
|
{"pending approve -> approved", StatusPending, ActionApprove, StatusApproved, nil},
|
|
{"pending reject -> rejected", StatusPending, ActionReject, StatusRejected, nil},
|
|
{"pending unknown action -> error", StatusPending, "escalate", StatusPending, ErrUnknownAction},
|
|
{"approved approve -> already resolved", StatusApproved, ActionApprove, StatusApproved, ErrAlreadyResolved},
|
|
{"approved reject -> already resolved", StatusApproved, ActionReject, StatusApproved, ErrAlreadyResolved},
|
|
{"rejected approve -> already resolved", StatusRejected, ActionApprove, StatusRejected, ErrAlreadyResolved},
|
|
{"rejected reject -> already resolved", StatusRejected, ActionReject, StatusRejected, ErrAlreadyResolved},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
got, err := NextStatus(c.current, c.action)
|
|
if got != c.want {
|
|
t.Fatalf("NextStatus(%q, %q) status = %q, want %q", c.current, c.action, got, c.want)
|
|
}
|
|
if !errors.Is(err, c.wantErr) {
|
|
t.Fatalf("NextStatus(%q, %q) err = %v, want %v", c.current, c.action, err, c.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|