Files
hideck/internal/api/automatic_tasks_sms_test.go
T
yibaiba 24bb2e0072 fix(sms): send once via IMS or CS without a double submit
/send, automatic tasks, and the balance gateway now use SendRoutedSMS.
A VoWiFi failure falls back to CS once; it does not also send on IMS.
Notify /status shows MWI, and vocall hold from notify stays skipped.
2026-08-31 00:46:58 +08:00

71 lines
2.4 KiB
Go

package api
import (
"context"
"errors"
"strings"
"testing"
"github.com/iniwex5/vowifi-go/runtimehost/messaging"
"github.com/yibaiba/hideck/internal/automation"
"github.com/yibaiba/hideck/internal/config"
"github.com/yibaiba/hideck/internal/device"
"github.com/yibaiba/hideck/pkg/smscodec"
)
func TestExecuteSMSFallsBackToCSWithoutDoubleSend(t *testing.T) {
pool := device.NewPool(&config.Config{})
worker := &device.Worker{ID: "wwan0", Config: config.DeviceConfig{
ID: "wwan0", VoWiFiEnabled: true, PhoneMode: "wifi",
}}
pool.AttachWorkerForTest(worker)
vowifiCalls, csCalls := 0, 0
pool.SetRoutedSMSTestSenders(
func(context.Context, string, string, string, smscodec.SubmitOptions) (messaging.SendOutcome, error) {
vowifiCalls++
return messaging.SendOutcome{MessageID: "ims-1", SIPCode: 503, RecommendCSFallback: true}, errors.New("503")
},
func(string, string, string) error { csCalls++; return nil },
)
executor := &automaticTaskExecutor{server: &Server{pool: pool}}
output, err := executor.executeSMS(context.Background(), worker, automation.Task{
DeviceID: "wwan0", Environment: automation.EnvironmentVoWiFi,
Payload: automation.Payload{Phone: "888", Message: "BAL"},
}, nil)
if err != nil {
t.Fatalf("executeSMS() = %v", err)
}
if !strings.Contains(output, "回落") || !strings.Contains(output, "蜂窝") {
t.Fatalf("output=%q", output)
}
if vowifiCalls != 1 || csCalls != 1 {
t.Fatalf("calls vowifi=%d cs=%d", vowifiCalls, csCalls)
}
}
func TestExecuteSMSDoesNotFallbackAfterIMSAccept(t *testing.T) {
pool := device.NewPool(&config.Config{})
worker := &device.Worker{ID: "wwan0", Config: config.DeviceConfig{
ID: "wwan0", VoWiFiEnabled: true, PhoneMode: "wifi",
}}
pool.AttachWorkerForTest(worker)
csCalls := 0
pool.SetRoutedSMSTestSenders(
func(context.Context, string, string, string, smscodec.SubmitOptions) (messaging.SendOutcome, error) {
return messaging.SendOutcome{SIPCode: 403, RecommendCSFallback: false}, errors.New("403")
},
func(string, string, string) error { csCalls++; return nil },
)
executor := &automaticTaskExecutor{server: &Server{pool: pool}}
_, err := executor.executeSMS(context.Background(), worker, automation.Task{
DeviceID: "wwan0", Environment: automation.EnvironmentVoWiFi,
Payload: automation.Payload{Phone: "888", Message: "BAL"},
}, nil)
if err == nil {
t.Fatal("expected 403 to stay on VoWiFi")
}
if csCalls != 0 {
t.Fatalf("cs calls=%d", csCalls)
}
}