Skip to content

Commit

Permalink
test: update unit test to mock GetHubClientByID in handler
Browse files Browse the repository at this point in the history
Updated the test to include a mocked GetHubClientByID call with an expected client. This ensures proper dependency interaction before the UpdateHubClient operation is validated.
  • Loading branch information
gabrielmaialva33 committed Feb 2, 2025
1 parent aa16b33 commit 9405ece
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/server/http/handlers/hub_client_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ func TestHubClientHandler_UpdateHubClient(t *testing.T) {
app := fiber.New()
app.Put("/hub_clients/:id", handler.UpdateHubClient)

mockClient := &models.HubClient{BaseID: models.BaseID{ID: 1}, Name: "Client1", ExternalID: "1"}
mockService.On("UpdateHubClient", mockClient).Return(nil)
mockID := uint(1)
mockClient := &models.HubClient{BaseID: models.BaseID{ID: mockID}, Name: "Client1", ExternalID: "1"}
mockService.On("GetHubClientByID", mockID).Return(mockClient, nil)
updatedClient := &models.HubClient{BaseID: models.BaseID{ID: mockID}, Name: "Client1", ExternalID: "1"}
mockService.On("UpdateHubClient", updatedClient).Return(nil)

payload := `{"name":"Client1","external_id": "1"}`
req := httptest.NewRequest("PUT", "/hub_clients/1", strings.NewReader(payload))
Expand Down

0 comments on commit 9405ece

Please sign in to comment.