mirror of
https://github.com/MengMengCode/VoCat.git
synced 2026-08-13 03:13:43 +08:00
- Implemented a new `unsupportedBackend` in `backend_stub.go` to handle unsupported platforms. - Created a `Service` struct in `service.go` to manage interactions with smart cards, including session management and identity reading. - Added methods for reading identity, checking readiness, and authenticating with USIM applications. - Introduced a `scriptedCard` for testing purposes in `service_test.go` to simulate card responses. - Defined necessary types and error handling in `types.go` for better clarity and usability. - Developed a `PCSCAdapter` in `vowifi/pcsc_adapter.go` to integrate PC/SC service with Wi-Fi calling functionalities. - Added a new SVG icon for USB SIM readers in `public/sim-reader.svg`. - Implemented tests to ensure correct functionality and error handling in various scenarios.
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package server
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"vocat/internal/store"
|
|
)
|
|
|
|
func TestNextAutomaticRunUsesIntervalAndLocalClock(t *testing.T) {
|
|
location := time.FixedZone("test", 8*60*60)
|
|
now := time.Date(2026, 8, 10, 12, 0, 0, 0, location)
|
|
next, err := nextAutomaticRun("2026-08-01", "09:30", 3, now)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := time.Date(2026, 8, 13, 9, 30, 0, 0, location)
|
|
if !next.Equal(want) {
|
|
t.Fatalf("next run = %v, want %v", next, want)
|
|
}
|
|
}
|
|
|
|
func TestUSBSIMReaderAutomaticTasksRequireVoWiFi(t *testing.T) {
|
|
reader := store.Device{DeviceType: store.DeviceTypeUSBSIMReader}
|
|
for _, test := range []struct {
|
|
taskType string
|
|
environment string
|
|
wantError bool
|
|
}{
|
|
{taskType: "sms", environment: "vowifi"},
|
|
{taskType: "call", environment: "vowifi"},
|
|
{taskType: "sms", environment: "cellular", wantError: true},
|
|
{taskType: "public_ip", environment: "cellular", wantError: true},
|
|
} {
|
|
err := validateAutomaticTaskDeviceCapabilities(reader, test.taskType, test.environment)
|
|
if (err != nil) != test.wantError {
|
|
t.Errorf("type=%s environment=%s error=%v", test.taskType, test.environment, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAutomaticSMSRetrySafetyPreventsDuplicateSubmission(t *testing.T) {
|
|
unsafe := []byte(`{"data":{"parts_attempted":1,"parts_accepted":1,"retry_safe":false}}`)
|
|
if automaticSMSRetrySafe(unsafe) {
|
|
t.Fatal("partially submitted SMS was considered safe to retry")
|
|
}
|
|
safe := []byte(`{"data":{"parts_attempted":0,"parts_accepted":0}}`)
|
|
if !automaticSMSRetrySafe(safe) {
|
|
t.Fatal("unattempted SMS was not considered safe to retry")
|
|
}
|
|
}
|