Files

65 lines
1.9 KiB
Go

package upstreamimpl
import (
"context"
"testing"
)
func TestYundaMonthAndDate(t *testing.T) {
tests := []struct {
input string
month string
date string
}{
{input: "20260921", month: "2026-09", date: "2026-09-21"},
{input: "2026-09-21", month: "2026-09", date: "2026-09-21"},
}
for _, test := range tests {
month, date, err := yundaMonthAndDate(test.input)
if err != nil || month != test.month || date != test.date {
t.Fatalf("input=%s month=%s date=%s err=%v", test.input, month, date, err)
}
}
}
func TestYundaMonthAndDateRejectsInvalidValue(t *testing.T) {
if _, _, err := yundaMonthAndDate("202609"); err == nil {
t.Fatal("expected invalid daily date")
}
}
func TestMapYundaCardStatus(t *testing.T) {
for _, tc := range []struct {
input string
want int
}{
{"0", 6}, {"1", 1}, {"2", 7}, {"3", 2}, {"正使用", 2}, {"4", 4}, {"已停机", 4}, {"5", 9}, {"已销户", 9},
} {
got, err := mapYundaCardStatus(tc.input)
if err != nil || got != tc.want {
t.Fatalf("mapYundaCardStatus(%q) = %d, %v; want %d", tc.input, got, err, tc.want)
}
}
if _, err := mapYundaCardStatus("unknown"); err == nil {
t.Fatal("expected unsupported Yunda status to return an error")
}
}
func TestTelecomCardStatusSourcesDiffer(t *testing.T) {
if got := convertDxCardStatus(context.Background(), "3"); got != 7 {
t.Fatalf("single-card product state 3 = %d, want inventory 7", got)
}
if got := convertDXBatchCardStatus(context.Background(), "3"); got != 6 {
t.Fatalf("BQ018 test deactivation 3 = %d, want testable 6", got)
}
if got := mapDXBatchInfoToBasicInfo(dxBatchInfoItem{SimStatus: "4"}).SimStatus; got != "2" {
t.Fatalf("BQ018 in-use state 4 = %q, want activated 2", got)
}
}
func TestMapDXLegacyBasicStatusKeepsMissingValueEmpty(t *testing.T) {
if got := mapDXLegacyBasicStatus(context.Background(), ""); got != "" {
t.Fatalf("missing telecom status = %q, want empty", got)
}
}