Skip to content

Commit

Permalink
remove endpoints not being used. Add eth address to test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesReate committed Jan 23, 2025
1 parent 6225f22 commit 8141cf1
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 157 deletions.
3 changes: 0 additions & 3 deletions cmd/devices-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, pdb db.Store,
udOwner.Get("/commands/mint", userDeviceController.GetMintDevice)
udOwner.Post("/commands/mint", userDeviceController.PostMintDevice)

udOwner.Patch("/vin", userDeviceController.UpdateVIN)
udOwner.Patch("/country-code", userDeviceController.UpdateCountryCode)

udOwner.Post("/error-codes", userDeviceController.QueryDeviceErrorCodes)
udOwner.Get("/error-codes", userDeviceController.GetUserDeviceErrorCodeQueries)
udOwner.Post("/error-codes/clear", userDeviceController.ClearUserDeviceErrorCodeQuery)
Expand Down
18 changes: 10 additions & 8 deletions internal/controllers/device_data_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/common"

"github.com/DIMO-Network/device-definitions-api/pkg/grpc"
"github.com/DIMO-Network/devices-api/internal/config"
"github.com/DIMO-Network/devices-api/internal/constants"
Expand Down Expand Up @@ -100,7 +102,7 @@ func TestUserDevicesController_QueryDeviceErrorCodes(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, common.Address{}), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {
req := QueryDeviceErrorCodesReq{
Expand Down Expand Up @@ -175,7 +177,7 @@ func TestUserDevicesController_ShouldErrorOnTooManyErrorCodes(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, common.Address{}), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {

Expand Down Expand Up @@ -249,7 +251,7 @@ func TestUserDevicesController_ShouldErrorInvalidErrorCodes(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, common.Address{}), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {

Expand Down Expand Up @@ -319,7 +321,7 @@ func TestUserDevicesController_ShouldErrorOnEmptyErrorCodes(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, common.Address{}), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {

Expand Down Expand Up @@ -389,7 +391,7 @@ func TestUserDevicesController_ShouldStoreErrorCodeResponse(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, common.Address{}), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {
erCodeReq := []string{"P0017", "P0016"}
Expand Down Expand Up @@ -475,7 +477,7 @@ func TestUserDevicesController_GetUserDevicesErrorCodeQueries(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Get("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.GetUserDeviceErrorCodeQueries)
app.Get("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, common.Address{}), c.GetUserDeviceErrorCodeQueries)

t.Run("GET - all saved error code response for current user devices", func(t *testing.T) {

Expand Down Expand Up @@ -551,7 +553,7 @@ func TestUserDevicesController_ClearUserDeviceErrorCodeQuery(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes/clear", test.AuthInjectorTestHandler(testUserID), c.ClearUserDeviceErrorCodeQuery)
app.Post("/user/devices/:userDeviceID/error-codes/clear", test.AuthInjectorTestHandler(testUserID, common.Address{}), c.ClearUserDeviceErrorCodeQuery)

t.Run("POST - clear last saved error code response for current user devices", func(t *testing.T) {
autoPiInteg := test.BuildIntegrationGRPC(ksuid.New().String(), constants.AutoPiVendor, 10, 0)
Expand Down Expand Up @@ -638,7 +640,7 @@ func TestUserDevicesController_ErrorOnAllErrorCodesCleared(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes/clear", test.AuthInjectorTestHandler(testUserID), c.ClearUserDeviceErrorCodeQuery)
app.Post("/user/devices/:userDeviceID/error-codes/clear", test.AuthInjectorTestHandler(testUserID, common.Address{}), c.ClearUserDeviceErrorCodeQuery)

t.Run("POST - clear last saved error code response for current user devices", func(t *testing.T) {
autoPiInteg := test.BuildIntegrationGRPC(ksuid.New().String(), constants.AutoPiVendor, 10, 0)
Expand Down
16 changes: 8 additions & 8 deletions internal/controllers/geofences_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (s *GeofencesControllerTestSuite) TestPostGeofence() {
producer := saramamocks.NewSyncProducer(s.T(), sarama.NewConfig())
c := NewGeofencesController(&config.Settings{Port: "3000"}, s.pdb.DBS, s.logger, producer, s.deviceDefSvc, usersClient)
app := fiber.New()
app.Post("/user/geofences", test.AuthInjectorTestHandler(injectedUserID), c.Create)
app.Post("/user/geofences", test.AuthInjectorTestHandler(injectedUserID, common.Address{}), c.Create)
ud := test.SetupCreateUserDevice(s.T(), injectedUserID, ksuid.New().String(), nil, "", s.pdb)
ud.TokenID = types.NewNullDecimal(decimal.New(1, 0))
_, err := ud.Update(s.ctx, s.pdb.DBS().Writer, boil.Infer())
Expand Down Expand Up @@ -178,7 +178,7 @@ func (s *GeofencesControllerTestSuite) TestPostGeofenceRespectsWallet() {
producer := saramamocks.NewSyncProducer(s.T(), sarama.NewConfig())
c := NewGeofencesController(&config.Settings{Port: "3000"}, s.pdb.DBS, s.logger, producer, s.deviceDefSvc, usersClient)
app := fiber.New()
app.Post("/user/geofences", test.AuthInjectorTestHandler(injectedUserID), c.Create)
app.Post("/user/geofences", test.AuthInjectorTestHandler(injectedUserID, common.Address{}), c.Create)
someOtherUserID := ksuid.New().String()
ud := test.SetupCreateUserDevice(s.T(), someOtherUserID, ksuid.New().String(), nil, "", s.pdb)
ud.TokenID = types.NewNullDecimal(decimal.New(1, 0))
Expand Down Expand Up @@ -207,7 +207,7 @@ func (s *GeofencesControllerTestSuite) TestPostGeofence400IfSameName() {
injectedUserID := ksuid.New().String()
c := NewGeofencesController(&config.Settings{Port: "3000"}, s.pdb.DBS, s.logger, nil, s.deviceDefSvc, nil)
app := fiber.New()
app.Post("/user/geofences", test.AuthInjectorTestHandler(injectedUserID), c.Create)
app.Post("/user/geofences", test.AuthInjectorTestHandler(injectedUserID, common.Address{}), c.Create)
ud := test.SetupCreateUserDevice(s.T(), injectedUserID, ksuid.New().String(), nil, "", s.pdb)
test.SetupCreateGeofence(s.T(), injectedUserID, "Home", &ud, s.pdb)

Expand All @@ -227,7 +227,7 @@ func (s *GeofencesControllerTestSuite) TestPostGeofence400IfNotYourDevice() {
usersClient.EXPECT().GetUser(gomock.Any(), gomock.Any()).Return(&users.User{}, nil)
c := NewGeofencesController(&config.Settings{Port: "3000"}, s.pdb.DBS, s.logger, nil, s.deviceDefSvc, usersClient)
app := fiber.New()
app.Post("/user/geofences", test.AuthInjectorTestHandler(injectedUserID), c.Create)
app.Post("/user/geofences", test.AuthInjectorTestHandler(injectedUserID, common.Address{}), c.Create)
otherUserID := "7734"
ud := test.SetupCreateUserDevice(s.T(), otherUserID, ksuid.New().String(), nil, "", s.pdb)

Expand All @@ -246,7 +246,7 @@ func (s *GeofencesControllerTestSuite) TestGetAllUserGeofences() {
injectedUserID := ksuid.New().String()
c := NewGeofencesController(&config.Settings{Port: "3000"}, s.pdb.DBS, s.logger, nil, s.deviceDefSvc, nil)
app := fiber.New()
app.Get("/user/geofences", test.AuthInjectorTestHandler(injectedUserID), c.GetAll)
app.Get("/user/geofences", test.AuthInjectorTestHandler(injectedUserID, common.Address{}), c.GetAll)
dd := test.BuildDeviceDefinitionGRPC(ksuid.New().String(), "Ford", "escaped", 2020, nil)
s.deviceDefSvc.EXPECT().GetDeviceDefinitionBySlug(gomock.Any(), dd[0].Id).Return(dd[0], nil)
ud := test.SetupCreateUserDevice(s.T(), injectedUserID, dd[0].Id, nil, "", s.pdb)
Expand All @@ -271,8 +271,8 @@ func (s *GeofencesControllerTestSuite) TestPutGeofence() {
producer := saramamocks.NewSyncProducer(s.T(), sarama.NewConfig())
c := NewGeofencesController(&config.Settings{Port: "3000"}, s.pdb.DBS, s.logger, producer, s.deviceDefSvc, usersClient)
app := fiber.New()
app.Get("/user/geofences", test.AuthInjectorTestHandler(injectedUserID), c.GetAll)
app.Put("/user/geofences/:geofenceID", test.AuthInjectorTestHandler(injectedUserID), c.Update)
app.Get("/user/geofences", test.AuthInjectorTestHandler(injectedUserID, common.Address{}), c.GetAll)
app.Put("/user/geofences/:geofenceID", test.AuthInjectorTestHandler(injectedUserID, common.Address{}), c.Update)

dd := test.BuildDeviceDefinitionGRPC(ksuid.New().String(), "Ford", "escaped", 2020, nil)
s.deviceDefSvc.EXPECT().GetDeviceDefinitionBySlug(gomock.Any(), dd[0].Id).Return(dd[0], nil)
Expand Down Expand Up @@ -320,7 +320,7 @@ func (s *GeofencesControllerTestSuite) TestDeleteGeofence() {
producer := saramamocks.NewSyncProducer(s.T(), sarama.NewConfig())
c := NewGeofencesController(&config.Settings{Port: "3000"}, s.pdb.DBS, s.logger, producer, s.deviceDefSvc, nil)
app := fiber.New()
app.Delete("/user/geofences/:geofenceID", test.AuthInjectorTestHandler(injectedUserID), c.Delete)
app.Delete("/user/geofences/:geofenceID", test.AuthInjectorTestHandler(injectedUserID, common.Address{}), c.Delete)
ud := test.SetupCreateUserDevice(s.T(), injectedUserID, ksuid.New().String(), nil, "", s.pdb)
gf := test.SetupCreateGeofence(s.T(), injectedUserID, "something", &ud, s.pdb)

Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/nft_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func validVINChar(r rune) bool {

// UpdateVINV2 godoc
// @Description updates the VIN on the user device record. Can optionally also update the protocol and the country code.
// VIN now comes from attestations, no need for this soon
// VIN now comes from attestations, no need for this soon.
// @Tags user-devices
// @Produce json
// @Accept json
Expand All @@ -81,7 +81,7 @@ func validVINChar(r rune) bool {
func (udc *UserDevicesController) UpdateVINV2(c *fiber.Ctx) error {
tis := c.Params("tokenID")
tokenID, ok := new(big.Int).SetString(tis, 10)
userEthAddr, _ := helpers.GetJWTEthAddr(c)
userEthAddr, _ := helpers.GetJWTEthAddr(c) // we use privilege auth - need to test in dev this would still work
if !ok {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Couldn't parse token id %q.", tis))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/synthetic_devices_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (s *SyntheticDevicesControllerTestSuite) SetupTest() {

app := test.SetupAppFiber(*logger)

app.Post("/v1/user/devices/:userDeviceID/integrations/:integrationID/commands/mint", test.AuthInjectorTestHandler(mockUserID), c.MintSyntheticDevice)
app.Get("/v1/user/devices/:userDeviceID/integrations/:integrationID/commands/mint", test.AuthInjectorTestHandler(mockUserID), c.GetSyntheticDeviceMintingPayload)
app.Post("/v1/user/devices/:userDeviceID/integrations/:integrationID/commands/mint", test.AuthInjectorTestHandler(mockUserID, common.Address{}), c.MintSyntheticDevice)
app.Get("/v1/user/devices/:userDeviceID/integrations/:integrationID/commands/mint", test.AuthInjectorTestHandler(mockUserID, common.Address{}), c.GetSyntheticDeviceMintingPayload)

s.app = app
}
Expand Down
58 changes: 0 additions & 58 deletions internal/controllers/user_devices_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,23 +1130,6 @@ func (udc *UserDevicesController) DeviceOptIn(c *fiber.Ctx) error {
return nil
}

// UpdateVIN godoc
// @Description Deprecated. updates the VIN on the user device record. Keeping this alive to not break mobile app. VIN's now come from attestations.
// @Tags user-devices
// @Produce json
// @Accept json
// @Param vin body controllers.UpdateVINReq true "VIN"
// @Param userDeviceID path string true "user id"
// @Success 204
// @Security BearerAuth
// @Router /user/devices/{userDeviceID}/vin [patch]
func (udc *UserDevicesController) UpdateVIN(_ *fiber.Ctx) error {
// todo remove this endpoint on next mobile app release
return fiber.NewError(fiber.StatusBadRequest, "this update vin endpoint is deprecated")

// this has been replaced by nft_controller.go > UpdateVINV2
}

const (
PowerTrainTypeKey = "powertrain_type"
)
Expand Down Expand Up @@ -1183,47 +1166,6 @@ func (udc *UserDevicesController) updatePowerTrain(ctx context.Context, userDevi
return nil
}

// UpdateCountryCode godoc
// @Description updates the CountryCode on the user device record
// @Tags user-devices
// @Produce json
// @Accept json
// @Param name body controllers.UpdateCountryCodeReq true "Country code"
// @Success 204
// @Security BearerAuth
// @Router /user/devices/{userDeviceID}/country_code [patch]
func (udc *UserDevicesController) UpdateCountryCode(c *fiber.Ctx) error {
udi := c.Params("userDeviceID")

userDevice, err := models.UserDevices(models.UserDeviceWhere.ID.EQ(udi)).One(c.Context(), udc.DBS().Writer)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
return err
}
countryCode := &UpdateCountryCodeReq{}
if err := c.BodyParser(countryCode); err != nil {
// Return status 400 and error message.
return helpers.ErrorResponseHandler(c, err, fiber.StatusBadRequest)
}
// validate country_code
if countryCode.CountryCode == nil {
return fiber.NewError(fiber.StatusBadRequest, "CountryCode is required")
}
if constants.FindCountry(*countryCode.CountryCode) == nil {
return fiber.NewError(fiber.StatusBadRequest, "CountryCode does not exist: "+*countryCode.CountryCode)
}

userDevice.CountryCode = null.StringFromPtr(countryCode.CountryCode)
_, err = userDevice.Update(c.Context(), udc.DBS().Writer, boil.Infer())
if err != nil {
return helpers.ErrorResponseHandler(c, err, fiber.StatusInternalServerError)
}

return c.SendStatus(fiber.StatusNoContent)
}

// DeleteUserDevice godoc
// @Description delete the user device record (hard delete)
// @Tags user-devices
Expand Down
Loading

0 comments on commit 8141cf1

Please sign in to comment.