Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/core/queries/decode_vin.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func (dc DecodeVINQueryHandler) Handle(ctx context.Context, query *DecodeVINQuer
metrics.Success.With(prometheus.Labels{"method": VinExists}).Inc()
return r, nil
}
// check if vin has failed in the past, and if it has just fail now
vinAlreadyFailed, _ := models.FailedVinDecodes(models.FailedVinDecodeWhere.Vin.EQ(vinObj.String())).Exists(ctx, dc.dbs().Writer)
if vinAlreadyFailed {
return nil, fmt.Errorf("vin %s failed decoding already", vinObj.String())
}

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

Expand Down
16 changes: 16 additions & 0 deletions internal/core/queries/decode_vin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

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

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

func (s *DecodeVINQueryHandlerSuite) TestHandle_Failure_ExistingFailedVIN() {
const vin = "1FMCU0G61MUA52727" // ford escape 2021

fvin := models.FailedVinDecode{
Vin: vin,
VendorsTried: types.StringArray{"drivly"},
}
err := fvin.Insert(s.ctx, s.pdb.DBS().Writer, boil.Infer())
s.Require().NoError(err)

qryResult, err := s.queryHandler.Handle(s.ctx, &DecodeVINQuery{VIN: vin, Country: country})
s.Error(err)
s.Nil(qryResult)
}

func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_WithExistingDD_UpdatesAttributes_CreatesStyle() {
ctx := context.Background()
const vin = "1FMCU0G61MUA52727" // ford escape 2021
Expand Down
4 changes: 2 additions & 2 deletions internal/core/services/vin_decoding_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func (c vinDecodingService) GetVIN(ctx context.Context, vin string, provider cor

if len(providersToTry) == 0 {
if provider == coremodels.AllProviders {
// fill in the list, future could do something country specific
providersToTry = append(providersToTry, coremodels.DrivlyProvider, coremodels.VincarioProvider, coremodels.DATGroupProvider, coremodels.Japan17VIN)
// fill in the list, future could do something country specific. removed DAT group
providersToTry = append(providersToTry, coremodels.DrivlyProvider, coremodels.VincarioProvider, coremodels.Japan17VIN, coremodels.AutoIsoProvider)
} else {
// use the specified override
providersToTry = append(providersToTry, provider)
Expand Down
27 changes: 0 additions & 27 deletions internal/core/services/vin_decoding_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
_ "embed"
"encoding/json"
"encoding/xml"
"fmt"
"testing"

Expand Down Expand Up @@ -262,29 +261,3 @@ func (s *VINDecodingServiceSuite) Test_VINDecodingService_DD_Default_Success() {
s.NoError(err)
assert.Equal(s.T(), result.VIN, vin)
}

//go:embed datgroup_resp.xml
var testDATGroupXML []byte

func (s *VINDecodingServiceSuite) Test_VINDecodingService_DATGroup_Success() {
ctx := context.Background()
const vin = "ZFADEXTESTSTUB001"
const country = "TR"

vinInfoResp := &coremodels.DATGroupInfoResponse{
VIN: vin,
MainTypeGroupName: "Test",
Year: 2023,
}
_ = xml.Unmarshal(testDATGroupXML, vinInfoResp)

s.mockDATGroupAPIService.EXPECT().GetVINv2(vin).Times(1).Return(vinInfoResp, nil, nil)

_ = dbtesthelper.SetupCreateDeviceType(s.T(), s.pdb)

result, _, err := s.vinDecodingService.GetVIN(ctx, vin, coremodels.DATGroupProvider, country)

s.NoError(err)
assert.Equal(s.T(), result.VIN, vin)
assert.Equal(s.T(), result.Source, coremodels.DATGroupProvider)
}
Loading