46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package batchimport
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNormalizeBatchNoPrefix(t *testing.T) {
|
|
prefix, err := normalizeBatchNoPrefix(" inb ")
|
|
if err != nil {
|
|
t.Fatalf("normalize prefix: %v", err)
|
|
}
|
|
if prefix != "INB" {
|
|
t.Fatalf("unexpected prefix: %s", prefix)
|
|
}
|
|
|
|
if _, err = normalizeBatchNoPrefix("IN"); err == nil {
|
|
t.Fatal("expected error for non-three-character prefix")
|
|
}
|
|
}
|
|
|
|
func TestFormatBatchNo(t *testing.T) {
|
|
now := time.Date(2026, 8, 10, 12, 34, 56, 789000000, time.Local)
|
|
batchNo, err := formatBatchNo("REN", now, 7)
|
|
if err != nil {
|
|
t.Fatalf("format batch no: %v", err)
|
|
}
|
|
if batchNo != "REN20260810123456007" {
|
|
t.Fatalf("unexpected batch no: %s", batchNo)
|
|
}
|
|
if len(batchNo) != 20 {
|
|
t.Fatalf("unexpected batch no length: %d", len(batchNo))
|
|
}
|
|
if strings.Contains(batchNo, "789") {
|
|
t.Fatalf("batch no should not include milliseconds: %s", batchNo)
|
|
}
|
|
}
|
|
|
|
func TestFormatBatchNoRejectsOverflowSequence(t *testing.T) {
|
|
_, err := formatBatchNo("REN", time.Now(), 1000)
|
|
if err == nil {
|
|
t.Fatal("expected overflow sequence error")
|
|
}
|
|
}
|