fix(t238): accept ERP minute timestamps

This commit is contained in:
QiuSW
2026-07-29 14:21:57 +08:00
parent 15b1101941
commit 01be7e7251
6 changed files with 92 additions and 12 deletions
@@ -1260,7 +1260,7 @@ func (staticFreightSource) QueryOrder(
string,
) (domain.FreightSourceBatch, error) {
shop := "测试店铺"
created := "2026-07-28 08:00:00"
created := "2026-07-28 08:00"
quantityOne := 1
quantityTwo := 2
return domain.FreightSourceBatch{
@@ -924,6 +924,8 @@ func parseERPTime(value *string) (*time.Time, error) {
time.RFC3339Nano,
"2006-01-02 15:04:05",
"2006-01-02T15:04:05",
"2006-01-02 15:04",
"2006-01-02T15:04",
}
for _, layout := range layouts {
var parsed time.Time
@@ -56,6 +56,76 @@ func TestFreightNormalizationRejectsConflictingIdentityAndInvalidTime(
}
}
func TestParseERPTimeAcceptsConfirmedMinuteAndSecondPrecision(t *testing.T) {
shanghaiExpected := time.Date(2026, 7, 29, 4, 34, 0, 0, time.UTC)
shanghaiSecondExpected := time.Date(
2026,
7,
29,
4,
34,
56,
0,
time.UTC,
)
testCases := []struct {
name string
value string
expected time.Time
}{
{"space minute", "2026-07-29 12:34", shanghaiExpected},
{"T minute", "2026-07-29T12:34", shanghaiExpected},
{"space second", "2026-07-29 12:34:56", shanghaiSecondExpected},
{"T second", "2026-07-29T12:34:56", shanghaiSecondExpected},
{
"RFC3339",
"2026-07-29T12:34:56+08:00",
shanghaiSecondExpected,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
actual, err := parseERPTime(&testCase.value)
if err != nil || actual == nil || !actual.Equal(testCase.expected) {
t.Fatalf(
"parseERPTime(%q) = %v, %v; want %v",
testCase.value,
actual,
err,
testCase.expected,
)
}
})
}
}
func TestParseERPTimeRejectsUnknownMinuteFormats(t *testing.T) {
for _, value := range []string{
"2026-02-30 12:34",
"2026-07-29 12",
"2026-07-29 12:34 extra",
"29/07/2026 12:34",
} {
if actual, err := parseERPTime(&value); err == nil || actual != nil {
t.Fatalf("parseERPTime(%q) = %v, %v", value, actual, err)
}
}
}
func TestFreightNormalizationAcceptsDetailMinutePrecisionTime(t *testing.T) {
source := validFreightSource()
value := "2026-07-29 12:34"
source.Orders[0].SourceCreatedAt = &value
service := &FreightService{ids: &sequenceIDs{}}
result, err := service.normalize(source)
expected := time.Date(2026, 7, 29, 4, 34, 0, 0, time.UTC)
if err != nil || len(result.Orders) != 1 ||
result.Orders[0].SourceCreatedAt == nil ||
!result.Orders[0].SourceCreatedAt.Equal(expected) {
t.Fatalf("normalize minute time = %+v, %v", result.Orders, err)
}
}
func TestFreightSourceErrorCodesAreSourceNeutral(t *testing.T) {
cases := []struct {
err error