Files
hideck/internal/api/automatic_tasks_executor_profile_test.go
T
BFNOC beabc334fe feat(vowifi): add a per-SIM voicemail indication setting
- Add mwi_mode to card policies with auto, on and off keyed by ICCID
- Add the ims_mwi_rejections table keyed by ICCID and IMS identity without expiry
- Implement the MWI policy store in the delivery store
- Accept mwi_mode in the card policy API and clear MWI rejections when it is set to on
- Restart WiFi calling after a clear or an explicit redetect so the live registration retries
- Keep mwi_mode edited during an automatic task when the task restores the card policy
- Add the voicemail indication select and redetect button to the card policy panel
- Handle every card_policy_saved_ error code like the restart failure
2026-11-05 11:15:40 +08:00

112 lines
3.0 KiB
Go

package api
import (
"strings"
"testing"
"github.com/yibaiba/hideck/internal/automation"
"github.com/yibaiba/hideck/internal/db"
)
func TestResolveAutomaticTaskProfileUsesCurrentPhysicalSIM(t *testing.T) {
task := automation.Task{ProfileICCID: "8944101234567890123"}
action, err := resolveAutomaticTaskProfile(task, "\"8944101234567890123F\"")
if err != nil {
t.Fatal(err)
}
if action != automaticTaskUseCurrentSIM {
t.Fatalf("action=%d want current SIM", action)
}
}
func TestAutomaticTaskRestoreKeepsManualPhoneEditedDuringTask(t *testing.T) {
openTestDB(t)
const iccid = "8944101234567890123"
snapshot := db.DefaultCardPolicy(iccid)
snapshot.NetworkEnabled = false
snapshot.LocalPhoneOverride = "+447700900123"
if err := db.UpsertCardPolicy(snapshot); err != nil {
t.Fatal(err)
}
current := snapshot
current.NetworkEnabled = true
current.LocalPhoneOverride = "+447911123456"
current.Source = "user"
if err := db.UpsertCardPolicy(current); err != nil {
t.Fatal(err)
}
if err := restoreAutomaticTaskCardPolicy(snapshot); err != nil {
t.Fatal(err)
}
got, err := db.GetCardPolicy(iccid)
if err != nil {
t.Fatal(err)
}
if got.NetworkEnabled || got.LocalPhoneOverride != "+447911123456" || got.Source != "user" {
t.Fatalf("restored policy=%+v", got)
}
}
func TestAutomaticTaskRestoreKeepsMWIModeEditedDuringTask(t *testing.T) {
openTestDB(t)
const iccid = "8944101234567890123"
snapshot := db.DefaultCardPolicy(iccid)
snapshot.NetworkEnabled = false
if err := db.UpsertCardPolicy(snapshot); err != nil {
t.Fatal(err)
}
current := snapshot
current.NetworkEnabled = true
current.MWIMode = db.MWIModeOff
current.Source = "user"
if err := db.UpsertCardPolicy(current); err != nil {
t.Fatal(err)
}
if err := restoreAutomaticTaskCardPolicy(snapshot); err != nil {
t.Fatal(err)
}
got, err := db.GetCardPolicy(iccid)
if err != nil {
t.Fatal(err)
}
if got.NetworkEnabled || got.MWIMode != db.MWIModeOff || got.Source != "user" {
t.Fatalf("restored policy=%+v", got)
}
}
func TestResolveAutomaticTaskProfileSwitchesOnlyWithAID(t *testing.T) {
task := automation.Task{
ProfileICCID: "8944101234567890123",
ProfileAID: "A0000005591010FFFFFFFF8900000100",
}
action, err := resolveAutomaticTaskProfile(task, "8944100000000000000")
if err != nil {
t.Fatal(err)
}
if action != automaticTaskSwitchESIM {
t.Fatalf("action=%d want eSIM switch", action)
}
}
func TestResolveAutomaticTaskProfileRejectsUnverifiablePhysicalSIM(t *testing.T) {
tests := []struct {
name string
current string
wantErr string
}{
{name: "identity unavailable", wantErr: "current SIM ICCID is unavailable"},
{name: "different card", current: "8944100000000000000", wantErr: "eSIM AID is required"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
task := automation.Task{ProfileICCID: "8944101234567890123"}
_, err := resolveAutomaticTaskProfile(task, test.current)
if err == nil || !strings.Contains(err.Error(), test.wantErr) {
t.Fatalf("error=%v want containing %q", err, test.wantErr)
}
})
}
}