fix(gateway): keep canonical stats fields in field events
This commit is contained in:
@@ -39,7 +39,7 @@ func TestRealtimeKVFieldsFromGB32960ParsedDomains(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildFieldsEnvelopeUsesOnlyMappedFieldNames(t *testing.T) {
|
||||
func TestBuildFieldsEnvelopeKeepsMappedAndCanonicalStatFields(t *testing.T) {
|
||||
fieldsEnv, ok := BuildFieldsEnvelope(envelope.FrameEnvelope{
|
||||
Protocol: envelope.ProtocolGB32960,
|
||||
VIN: "VIN001",
|
||||
@@ -65,9 +65,9 @@ func TestBuildFieldsEnvelopeUsesOnlyMappedFieldNames(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatal("BuildFieldsEnvelope() should emit mapped fields")
|
||||
}
|
||||
for _, bareKey := range []string{"charge_status", "soc_percent", "total_mileage_km"} {
|
||||
for _, bareKey := range []string{"charge_status"} {
|
||||
if _, exists := fieldsEnv.Fields[bareKey]; exists {
|
||||
t.Fatalf("fields envelope should not expose bare env.Fields key %q: %#v", bareKey, fieldsEnv.Fields)
|
||||
t.Fatalf("fields envelope should not expose non-canonical bare env.Fields key %q: %#v", bareKey, fieldsEnv.Fields)
|
||||
}
|
||||
}
|
||||
for _, mappedKey := range []string{
|
||||
@@ -79,6 +79,14 @@ func TestBuildFieldsEnvelopeUsesOnlyMappedFieldNames(t *testing.T) {
|
||||
t.Fatalf("fields envelope missing mapped key %q: %#v", mappedKey, fieldsEnv.Fields)
|
||||
}
|
||||
}
|
||||
for _, canonicalKey := range []string{envelope.FieldSOCPercent, envelope.FieldTotalMileageKM} {
|
||||
if _, exists := fieldsEnv.Fields[canonicalKey]; !exists {
|
||||
t.Fatalf("fields envelope should keep canonical stat key %q: %#v", canonicalKey, fieldsEnv.Fields)
|
||||
}
|
||||
if _, exists := fieldsEnv.ParsedFields[canonicalKey]; exists {
|
||||
t.Fatalf("parsed fields should stay protocol-mapped without canonical duplicate %q: %#v", canonicalKey, fieldsEnv.ParsedFields)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRealtimeKVFieldsFromJT808ParsedFields(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user