Files
MengMengCode 8a260e86f1 Implement automatic task management with CRUD operations and UI integration
- Added `automatic_tasks.go` and `automatic_tasks_test.go` for backend logic and testing of automatic tasks.
- Created `automatic_tasks_test.go` to validate task claiming and deletion behavior.
- Developed `AutomaticTasksPage.tsx` for frontend management of automatic tasks, including task creation, editing, and execution.
- Integrated device and eSIM profile selection for task configuration.
- Implemented automatic task scheduling and retry logic in the backend.
2026-08-10 22:15:54 +08:00

76 lines
2.4 KiB
Go

package device
import (
"testing"
"vocat/internal/modem"
)
func TestParseOperatorScanNormalizesMainlandCarrierNamesByPLMN(t *testing.T) {
response := modem.Response{Lines: []string{
`+COPS: (1,"CMCC","CMCC","46000",7),(1,"wrong modem name","CU","46001",7),(1,"","CT","46011",7),(1,"CBN","CBN","46015",7)`,
}}
operators := parseOperatorScan(response)
if len(operators) != 4 {
t.Fatalf("operators = %#v", operators)
}
want := []string{"China Mobile", "China Unicom", "China Telecom", "China Broadnet"}
for index := range want {
if operators[index].Name != want[index] {
t.Fatalf("operator %d name = %q, want %q", index, operators[index].Name, want[index])
}
}
}
func TestCarrierNameForPLMNUsesGlobalDatabase(t *testing.T) {
if got := carrierNameForPLMN("23415", "stale modem name"); got != "Vodafone" {
t.Fatalf("carrier name = %q", got)
}
if got := carrierNameForPLMN("26202", ""); got != "Vodafone" {
t.Fatalf("German carrier name = %q", got)
}
if got := carrierNameForPLMN("310260", ""); got != "T-Mobile - US" {
t.Fatalf("US carrier name = %q", got)
}
if got := carrierNameForPLMN("99999", "Test Network"); got != "Test Network" {
t.Fatalf("unknown carrier fallback = %q", got)
}
}
func TestCarrierForPLMNReturnsCountryCode(t *testing.T) {
tests := map[string]string{
"23415": "GB",
"23487": "GB",
"26202": "DE",
"310260": "US",
"22201": "IT",
"72405": "BR",
"46015": "CN",
}
for plmn, wantCountry := range tests {
name, country, ok := CarrierForPLMN(plmn)
if !ok || name == "" || country != wantCountry {
t.Errorf("CarrierForPLMN(%q) = (%q, %q, %v), want a name and country %q", plmn, name, country, ok, wantCountry)
}
}
}
func TestCarrierForIMSIHandlesTwoAndThreeDigitMNCs(t *testing.T) {
tests := []struct {
imsi string
wantPLMN string
wantCountry string
}{
{imsi: "234336570710174", wantPLMN: "23433", wantCountry: "GB"},
{imsi: "234159609054263", wantPLMN: "23415", wantCountry: "GB"},
{imsi: "234870123456789", wantPLMN: "23487", wantCountry: "GB"},
{imsi: "310260123456789", wantPLMN: "310260", wantCountry: "US"},
}
for _, item := range tests {
plmn, name, country, ok := CarrierForIMSI(item.imsi)
if !ok || plmn != item.wantPLMN || name == "" || country != item.wantCountry {
t.Errorf("CarrierForIMSI(%q) = (%q, %q, %q, %v), want PLMN %q and country %q", item.imsi, plmn, name, country, ok, item.wantPLMN, item.wantCountry)
}
}
}