From b3c3f959a89f222dd7640fadc002b59e0a27b874 Mon Sep 17 00:00:00 2001 From: Prathamesh Date: Mon, 9 Oct 2023 21:21:06 +0530 Subject: [PATCH] Add SetPrimaryIntegration endpoint --- lib/integration.go | 19 +++++++++++++++++++ lib/integration_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/integration.go b/lib/integration.go index c783b44..ac38770 100644 --- a/lib/integration.go +++ b/lib/integration.go @@ -14,6 +14,7 @@ type IIntegration interface { GetWebhookSupportStatus(ctx context.Context, providerId string) (bool, error) Update(ctx context.Context, integrationId string, request UpdateIntegrationRequest) (*IntegrationResponse, error) Delete(ctx context.Context, integrationId string) (*IntegrationResponse, error) + SetPrimary(ctx context.Context, integrationId string) (*IntegrationResponse, error) } type IntegrationService service @@ -148,3 +149,21 @@ func (i IntegrationService) Delete(ctx context.Context, integrationId string) (* return &response, nil } + +func (i IntegrationService) SetPrimary(ctx context.Context, integrationId string) (*IntegrationResponse, error) { + var response IntegrationResponse + URL := i.client.config.BackendURL.JoinPath("integrations", integrationId, "set-primary") + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, URL.String(), http.NoBody) + + if err != nil { + return nil, err + } + + _, err = i.client.sendRequest(req, &response) + if err != nil { + return nil, err + } + + return &response, nil +} diff --git a/lib/integration_test.go b/lib/integration_test.go index bcf1066..4723eda 100644 --- a/lib/integration_test.go +++ b/lib/integration_test.go @@ -254,3 +254,30 @@ func TestDeleteActiveIntegration_Success(t *testing.T) { require.NoError(t, err) } + +func TestSetPrimaryIntegration_Success(t *testing.T) { + const integrationId = "integrationId" + + var response *lib.IntegrationResponse + fileToStruct(filepath.Join("../testdata", "integration_response.json"), &response) + + httpServer := IntegrationTestServer(t, IntegrationServerOptions[interface{}]{ + ExpectedRequest: IntegrationRequestDetails[interface{}]{ + Url: fmt.Sprintf("/v1/integrations/%s/set-primary", integrationId), + Method: http.MethodPost, + }, + ExpectedResponse: IntegrationResponseDetails{ + StatusCode: http.StatusOK, + Body: response, + }, + }) + + ctx := context.Background() + novuClient := lib.NewAPIClient(novuApiKey, &lib.Config{BackendURL: lib.MustParseURL(httpServer.URL)}) + + res, err := novuClient.IntegrationsApi.SetPrimary(ctx, integrationId) + + assert.Equal(t, response, res) + + require.NoError(t, err) +}