feat(t215): add admin order authorization
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package usecase
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateOrderAuthorizationAcceptsSingleStructuredSelection(
|
||||
t *testing.T,
|
||||
) {
|
||||
command := validOrderAuthorizationCommand()
|
||||
|
||||
if err := validateOrderAuthorizationCommand(command); err != nil {
|
||||
t.Fatalf("validate order authorization: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateOrderAuthorizationRejectsDuplicateCandidateKey(
|
||||
t *testing.T,
|
||||
) {
|
||||
command := validOrderAuthorizationCommand()
|
||||
command.Items[1].CandidateKey = command.Items[0].CandidateKey
|
||||
|
||||
if err := validateOrderAuthorizationCommand(command); err == nil {
|
||||
t.Fatal("expected duplicate candidate key to be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateOrderAuthorizationRejectsSelectedKeyMismatch(
|
||||
t *testing.T,
|
||||
) {
|
||||
command := validOrderAuthorizationCommand()
|
||||
command.CandidateKey = command.Items[1].CandidateKey
|
||||
|
||||
if err := validateOrderAuthorizationCommand(command); err == nil {
|
||||
t.Fatal("expected selected candidate mismatch to be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateOrderAuthorizationRequiresOtherNote(t *testing.T) {
|
||||
command := validOrderAuthorizationCommand()
|
||||
command.Items[0].PrimaryReasonCode = "OTHER"
|
||||
command.Items[0].ReasonCodes = []string{"OTHER"}
|
||||
command.Items[0].Note = "短"
|
||||
|
||||
if err := validateOrderAuthorizationCommand(command); err == nil {
|
||||
t.Fatal("expected short OTHER note to be rejected")
|
||||
}
|
||||
command.Items[0].Note = "人工判断规格更准确"
|
||||
if err := validateOrderAuthorizationCommand(command); err != nil {
|
||||
t.Fatalf("validate OTHER note: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func validOrderAuthorizationCommand() CreateOrderAuthorizationCommand {
|
||||
firstKey := strings.Repeat("a", 64)
|
||||
secondKey := strings.Repeat("b", 64)
|
||||
return CreateOrderAuthorizationCommand{
|
||||
ActorUserID: "00000000-0000-4000-8000-000000000001",
|
||||
TaskID: "00000000-0000-4000-8000-000000000002",
|
||||
IdempotencyKey: "authorize-order-test",
|
||||
ExecutionID: "00000000-0000-4000-8000-000000000003",
|
||||
TaskContentSHA256: strings.Repeat("c", 64),
|
||||
ExpectedTaskVersion: 2,
|
||||
CandidateKey: firstKey,
|
||||
ReasonSchemaVersion: 1,
|
||||
PrimaryReasonCode: "SELECTED_BEST_MATCH",
|
||||
Items: []OrderAuthorizationItemInput{
|
||||
{
|
||||
CandidateKey: firstKey,
|
||||
Label: "ACCEPT",
|
||||
PrimaryReasonCode: "SKU_MATCH",
|
||||
ReasonCodes: []string{"SKU_MATCH", "IMAGE_MATCH"},
|
||||
},
|
||||
{
|
||||
CandidateKey: secondKey,
|
||||
Label: "REJECT",
|
||||
PrimaryReasonCode: "NOT_BEST_MATCH",
|
||||
ReasonCodes: []string{"NOT_BEST_MATCH"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user