package service import ( "reflect" "testing" "time" ) func TestInboundExportHeadersMatchLatestTemplate(t *testing.T) { expected := []string{ "ICCID*", "MSISDN*", "IMSI*", "IMEI", "通道编号*", "卡类型", "上游套餐编码", "供应商编码", "上游激活时间", "是否贴片转插拔", "是否运营商达量断网", "协议到期时间", "是否有测试期", "测试期天数", "测试期最晚过期日期", "是否有沉默期", "沉默期天数", "沉默期最晚过期日期", } if !reflect.DeepEqual(inboundExportHeaders, expected) { t.Fatalf("export headers = %#v, want %#v", inboundExportHeaders, expected) } } func TestGeneratedCardsUseTimestampIdentifiersAndFixedTraffic(t *testing.T) { batchTime := time.Date(2026, 7, 10, 10, 0, 0, 123000000, time.UTC) cards := GenerateSIMCards(batchTime, 3) if len(cards) != 3 { t.Fatalf("generated card count = %d, want 3", len(cards)) } first := cards[0] second := cards[1] if first.ICCID == second.ICCID || first.MSISDN == second.MSISDN || first.IMSI == second.IMSI || first.IMEI == second.IMEI { t.Fatalf("generated identifiers should differ within a batch: first=%#v second=%#v", first, second) } if len(first.ICCID) != 20 || first.ICCID[:6] != "898604" { t.Fatalf("iccid = %q, want 20 digits with 898604 prefix", first.ICCID) } if len(first.MSISDN) != 11 || first.MSISDN[:3] != "141" { t.Fatalf("msisdn = %q, want 11 digits with 141 prefix", first.MSISDN) } if len(first.IMSI) != 15 || first.IMSI[:5] != "46004" { t.Fatalf("imsi = %q, want 15 digits with 46004 prefix", first.IMSI) } if len(first.IMEI) != 15 || first.IMEI[:2] != "86" { t.Fatalf("imei = %q, want 15 digits with 86 prefix", first.IMEI) } if first.MonthUsageKB != 18432 || first.MonthlyBaseKB != 18432 || first.DailyBaseKB != 614.4 { t.Fatalf("fixed traffic not applied: month=%v monthly=%v daily=%v", first.MonthUsageKB, first.MonthlyBaseKB, first.DailyBaseKB) } if first.PoolUsageBytes != 18874368 { t.Fatalf("pool usage bytes = %v, want 18874368", first.PoolUsageBytes) } if first.GrowthPerMinuteKB != 0 { t.Fatalf("growth per minute = %v, want 0", first.GrowthPerMinuteKB) } if len(first.APNs) != 1 || first.APNs[0].Name != "CMIOT" || first.APNs[0].Status != "1" || first.APNs[0].UsageBytes != 18874368 { t.Fatalf("apn not fixed to CMIOT usage: %#v", first.APNs) } } func TestGeneratedExportRowMatchesInboundTemplateDefaults(t *testing.T) { batchTime := time.Date(2026, 7, 10, 10, 0, 0, 0, time.UTC) card := GenerateSIMCards(batchTime, 1)[0] row := inboundExportRow(card) if row["chanKey"] != "channel_yd_mock" { t.Fatalf("chanKey = %q", row["chanKey"]) } if row["cardType"] != "1" || row["upPkgCode"] != "CMIOT-SD-500M-24M-D01" || row["suppliersCode"] != "SUP_CMCC" { t.Fatalf("package defaults not applied: %#v", row) } if row["upstreamActivationTime"] != "2026-07-10 10:00:00" { t.Fatalf("activation time = %q", row["upstreamActivationTime"]) } if row["insertToPlugEnabled"] != "true" || row["carrierTrafficCutoffEnabled"] != "false" { t.Fatalf("boolean defaults not applied: %#v", row) } if row["agreementExpiryDate"] != "2027-07-10" { t.Fatalf("agreement expiry = %q", row["agreementExpiryDate"]) } if row["hasTestPeriod"] != "true" || row["testPeriodDays"] != "30" || row["testPeriodLatestExpiryDate"] != "2026-08-09" { t.Fatalf("test period defaults not applied: %#v", row) } if row["hasSilentPeriod"] != "false" || row["silentPeriodDays"] != "" || row["silentPeriodLatestExpiryDate"] != "" { t.Fatalf("silent period defaults not applied: %#v", row) } }