Skip to content

Commit

Permalink
Create endpoint for fetching all commands available to an integration
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdev22 committed Apr 12, 2024
1 parent 858883c commit 2ddd6f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 3 additions & 7 deletions internal/controllers/user_integrations_auth_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,12 @@ func (u *UserIntegrationAuthController) GetCommandsByIntegration(c *fiber.Ctx) e
}

func (u *UserIntegrationAuthController) getTeslaCommands(version int) *services.UserDeviceAPIIntegrationsMetadataCommands {
if version == 0 {
version = constants.TeslaAPIV1
}

if version == constants.TeslaAPIV2 {
return u.teslaFleetAPISvc.GetAvailableCommands()
} else {
svc := services.NewTeslaService(u.Settings)
return svc.GetAvailableCommands()
}

svc := services.NewTeslaService(u.Settings)
return svc.GetAvailableCommands()
}

func (u *UserIntegrationAuthController) getSmartCarCommands() *services.UserDeviceAPIIntegrationsMetadataCommands {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,14 @@ func (s *UserIntegrationAuthControllerTestSuite) TestGetTeslaV2Commands() {
Vendor: constants.TeslaVendor,
}, nil)

logger := test.Logger()
teslaFleetSvc := services.NewTeslaFleetAPIService(nil, logger)
c := NewUserIntegrationAuthController(&config.Settings{}, nil, logger, s.deviceDefSvc, teslaFleetSvc, nil, nil, nil)
app := test.SetupAppFiber(*logger)
app.Get("/integration/:tokenID/commands", test.AuthInjectorTestHandler(s.testUserID), c.GetCommandsByIntegration)

request := test.BuildRequest("GET", "/integration/2/commands?version=2", "")
response, _ := s.app.Test(request)
response, _ := app.Test(request)

s.Assert().Equal(fiber.StatusOK, response.StatusCode)
body, _ := io.ReadAll(response.Body)
Expand Down

0 comments on commit 2ddd6f1

Please sign in to comment.