From 2ddd6f1f2b6a26c025e892889e4894bab618b2e4 Mon Sep 17 00:00:00 2001 From: 0xdev22 Date: Fri, 12 Apr 2024 17:40:10 -0400 Subject: [PATCH] Create endpoint for fetching all commands available to an integration --- .../controllers/user_integrations_auth_controller.go | 10 +++------- .../user_integrations_auth_controller_test.go | 8 +++++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/controllers/user_integrations_auth_controller.go b/internal/controllers/user_integrations_auth_controller.go index 7c9b8317b..55a387e5c 100644 --- a/internal/controllers/user_integrations_auth_controller.go +++ b/internal/controllers/user_integrations_auth_controller.go @@ -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 { diff --git a/internal/controllers/user_integrations_auth_controller_test.go b/internal/controllers/user_integrations_auth_controller_test.go index 33b7cbf1b..c68d23da4 100644 --- a/internal/controllers/user_integrations_auth_controller_test.go +++ b/internal/controllers/user_integrations_auth_controller_test.go @@ -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)