34 lines
959 B
Go
34 lines
959 B
Go
|
|
package usecase
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"apps/backend/internal/module/radar/domain"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestCostPreviewDoesNotReserveAndUsesByokMode(t *testing.T) {
|
||
|
|
svc := New(nil)
|
||
|
|
svc.ResolveKey = func(context.Context, int64, string) (string, string, error) {
|
||
|
|
return "byok", "secret", nil
|
||
|
|
}
|
||
|
|
preview, err := svc.GetCostPreview(context.Background(), 42, "explore", "", "", 10)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if preview.KeyMode != "byok" || preview.SearchCalls != 1 || preview.MaxAICandidates != 10 {
|
||
|
|
t.Fatalf("unexpected preview: %+v", preview)
|
||
|
|
}
|
||
|
|
if preview.MinCredits != 1 || preview.MaxCredits <= preview.MinCredits {
|
||
|
|
t.Fatalf("expected search plus judge range: %+v", preview)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestCostPreviewRejectsUnknownAction(t *testing.T) {
|
||
|
|
_, err := New(nil).GetCostPreview(context.Background(), 42, "unknown", "", "", 0)
|
||
|
|
if err == nil || !errors.Is(err, domain.ErrValidation) {
|
||
|
|
t.Fatalf("expected validation, got %v", err)
|
||
|
|
}
|
||
|
|
}
|