Skip to content

Commit

Permalink
Add SetPrimaryIntegration endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh-88 committed Oct 9, 2023
1 parent 1449de3 commit b3c3f95
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
27 changes: 27 additions & 0 deletions lib/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit b3c3f95

Please sign in to comment.