Skip to content

Commit b7d087a

Browse files
authored
INTG-1878 if vin already failed, fail now, remove dat group (#303)
* if vin already failed, fail now, remove dat group * fixes
1 parent 2bbc702 commit b7d087a

4 files changed

Lines changed: 23 additions & 29 deletions

File tree

internal/core/queries/decode_vin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ func (dc DecodeVINQueryHandler) Handle(ctx context.Context, query *DecodeVINQuer
123123
metrics.Success.With(prometheus.Labels{"method": VinExists}).Inc()
124124
return r, nil
125125
}
126+
// check if vin has failed in the past, and if it has just fail now
127+
vinAlreadyFailed, _ := models.FailedVinDecodes(models.FailedVinDecodeWhere.Vin.EQ(vinObj.String())).Exists(ctx, dc.dbs().Writer)
128+
if vinAlreadyFailed {
129+
return nil, fmt.Errorf("vin %s failed decoding already", vinObj.String())
130+
}
126131

127132
localLog.Info().Msgf("Start Decode VIN ")
128133

internal/core/queries/decode_vin_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
mock_repository "github.com/DIMO-Network/device-definitions-api/internal/infrastructure/db/repositories/mocks"
13+
"github.com/aarondl/sqlboiler/v4/types"
1314
"github.com/segmentio/ksuid"
1415

1516
coremodels "github.com/DIMO-Network/device-definitions-api/internal/core/models"
@@ -87,6 +88,21 @@ func (s *DecodeVINQueryHandlerSuite) TearDownSuite() {
8788
}
8889
}
8990

91+
func (s *DecodeVINQueryHandlerSuite) TestHandle_Failure_ExistingFailedVIN() {
92+
const vin = "1FMCU0G61MUA52727" // ford escape 2021
93+
94+
fvin := models.FailedVinDecode{
95+
Vin: vin,
96+
VendorsTried: types.StringArray{"drivly"},
97+
}
98+
err := fvin.Insert(s.ctx, s.pdb.DBS().Writer, boil.Infer())
99+
s.Require().NoError(err)
100+
101+
qryResult, err := s.queryHandler.Handle(s.ctx, &DecodeVINQuery{VIN: vin, Country: country})
102+
s.Error(err)
103+
s.Nil(qryResult)
104+
}
105+
90106
func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_WithExistingDD_UpdatesAttributes_CreatesStyle() {
91107
ctx := context.Background()
92108
const vin = "1FMCU0G61MUA52727" // ford escape 2021

internal/core/services/vin_decoding_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func (c vinDecodingService) GetVIN(ctx context.Context, vin string, provider cor
8585

8686
if len(providersToTry) == 0 {
8787
if provider == coremodels.AllProviders {
88-
// fill in the list, future could do something country specific
89-
providersToTry = append(providersToTry, coremodels.DrivlyProvider, coremodels.VincarioProvider, coremodels.DATGroupProvider, coremodels.Japan17VIN)
88+
// fill in the list, future could do something country specific. removed DAT group
89+
providersToTry = append(providersToTry, coremodels.DrivlyProvider, coremodels.VincarioProvider, coremodels.Japan17VIN, coremodels.AutoIsoProvider)
9090
} else {
9191
// use the specified override
9292
providersToTry = append(providersToTry, provider)

internal/core/services/vin_decoding_service_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
_ "embed"
66
"encoding/json"
7-
"encoding/xml"
87
"fmt"
98
"testing"
109

@@ -262,29 +261,3 @@ func (s *VINDecodingServiceSuite) Test_VINDecodingService_DD_Default_Success() {
262261
s.NoError(err)
263262
assert.Equal(s.T(), result.VIN, vin)
264263
}
265-
266-
//go:embed datgroup_resp.xml
267-
var testDATGroupXML []byte
268-
269-
func (s *VINDecodingServiceSuite) Test_VINDecodingService_DATGroup_Success() {
270-
ctx := context.Background()
271-
const vin = "ZFADEXTESTSTUB001"
272-
const country = "TR"
273-
274-
vinInfoResp := &coremodels.DATGroupInfoResponse{
275-
VIN: vin,
276-
MainTypeGroupName: "Test",
277-
Year: 2023,
278-
}
279-
_ = xml.Unmarshal(testDATGroupXML, vinInfoResp)
280-
281-
s.mockDATGroupAPIService.EXPECT().GetVINv2(vin).Times(1).Return(vinInfoResp, nil, nil)
282-
283-
_ = dbtesthelper.SetupCreateDeviceType(s.T(), s.pdb)
284-
285-
result, _, err := s.vinDecodingService.GetVIN(ctx, vin, coremodels.DATGroupProvider, country)
286-
287-
s.NoError(err)
288-
assert.Equal(s.T(), result.VIN, vin)
289-
assert.Equal(s.T(), result.Source, coremodels.DATGroupProvider)
290-
}

0 commit comments

Comments
 (0)