Skip to content

Commit

Permalink
Add the new methods for integration endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
EshaanAgg committed Oct 8, 2023
1 parent 1449de3 commit f60f6d4
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
38 changes: 38 additions & 0 deletions lib/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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)
SetIntegrationAsPrimary(ctx context.Context, integrationId string) (*SetIntegrationAsPrimaryResponse, error)
GetChannelLimit(ctx context.Context, channelType string) (*IntegrationChannelLimitResponse, error)
}

type IntegrationService service
Expand Down Expand Up @@ -148,3 +150,39 @@ func (i IntegrationService) Delete(ctx context.Context, integrationId string) (*

return &response, nil
}

func (i IntegrationService) SetIntegrationAsPrimary(ctx context.Context, integrationId string) (*SetIntegrationAsPrimaryResponse, error) {
var response SetIntegrationAsPrimaryResponse

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
}

func (i IntegrationService) GetChannelLimit(ctx context.Context, channelType string) (*IntegrationChannelLimitResponse, error) {
var response IntegrationChannelLimitResponse

URL := i.client.config.BackendURL.JoinPath("integrations", channelType, "limit")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, 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
}
52 changes: 52 additions & 0 deletions lib/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,55 @@ func TestDeleteActiveIntegration_Success(t *testing.T) {

require.NoError(t, err)
}

func TestSetIntegrationAsPrimary_Success(t *testing.T) {
const integrationId = "IntegrationId"

var response *lib.SetIntegrationAsPrimaryResponse
fileToStruct(filepath.Join("../testdata", "set_integration_as_primary_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.SetIntegrationAsPrimary(ctx, integrationId)

assert.Equal(t, response, res)
require.NoError(t, err)
}

func TestGetChannelLimit_Success(t *testing.T) {
const channelType = "ChannelType"

var response *lib.IntegrationChannelLimitResponse
fileToStruct(filepath.Join("../testdata", "integration_channel_limit_response.json"), &response)

httpServer := IntegrationTestServer(t, IntegrationServerOptions[interface{}]{
ExpectedRequest: IntegrationRequestDetails[interface{}]{
Url: fmt.Sprintf("/v1/integrations/%s/limit", channelType),
Method: http.MethodGet,
},
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.GetChannelLimit(ctx, channelType)

assert.Equal(t, response, res)
require.NoError(t, err)
}
26 changes: 25 additions & 1 deletion lib/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,30 @@ type GetIntegrationsResponse struct {
Data []Integration `json:"data"`
}

type IntegrationChannelLimitResponse struct {
Data struct {
Limit int `json:"limit"`
Count int `json:"count"`
} `json:"data"`
}

type SetIntegrationAsPrimaryResponse struct {
Data struct {
ID string `json:"_id"`
EnvironmentID string `json:"_environmentId"`
OrganizationID string `json:"_organizationId"`
Name string `json:"name"`
Identifier string `json:"identifier"`
ProviderID string `json:"providerId"`
Channel string `json:"channel"`
Credentials IntegrationCredentials `json:"credentials"`
Active bool `json:"active"`
Deleted bool `json:"deleted"`
DeletedAt string `json:"deletedAt"`
DeletedBy string `json:"deletedBy"`
Primary bool `json:"primary"`
} `json:"data"`
}
type BulkTriggerOptions struct {
Name interface{} `json:"name,omitempty"`
To interface{} `json:"to,omitempty"`
Expand Down Expand Up @@ -437,5 +461,5 @@ type BlueprintByTemplateIdResponse struct {

type BlueprintGroupByCategoryResponse struct {
General []interface{} `json:"general,omitempty"`
Popular interface{} `json:"popular,omitempty"`
Popular interface{} `json:"popular,omitempty"`
}
6 changes: 6 additions & 0 deletions testdata/integration_channel_limit_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data": {
"limit": 0,
"count": 0
}
}
43 changes: 43 additions & 0 deletions testdata/set_integration_as_primary_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"data": {
"_id": "string",
"_environmentId": "string",
"_organizationId": "string",
"name": "string",
"identifier": "string",
"providerId": "string",
"channel": "in_app",
"credentials": {
"apiKey": "string",
"user": "string",
"secretKey": "string",
"domain": "string",
"password": "string",
"host": "string",
"port": "string",
"secure": true,
"region": "string",
"accountSid": "string",
"messageProfileId": "string",
"token": "string",
"from": "string",
"senderName": "string",
"projectName": "string",
"applicationId": "string",
"clientId": "string",
"requireTls": true,
"ignoreTls": true,
"baseUrl": "string",
"webhookUrl": "string",
"redirectUrl": "string",
"hmac": true,
"serviceAccount": "string",
"ipPoolName": "string"
},
"active": true,
"deleted": true,
"deletedAt": "string",
"deletedBy": "string",
"primary": true
}
}

0 comments on commit f60f6d4

Please sign in to comment.