From 30f99e4e90ae168fcb8bbe25d939124640f73406 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Thu, 23 May 2024 13:14:13 -0600 Subject: [PATCH] chore(organization): add mutation `organizationUpdateSharedAccount` (#1140) --- .tutone.yml | 4 +- pkg/organization/organization_api.go | 48 +++++++++++++++++++ .../organization_integration_test.go | 3 +- pkg/organization/organization_test.go | 3 ++ pkg/organization/organization_unit_test.go | 44 +++++++++++++++++ 5 files changed, 99 insertions(+), 3 deletions(-) diff --git a/.tutone.yml b/.tutone.yml index d52ca269..f8c76f3d 100644 --- a/.tutone.yml +++ b/.tutone.yml @@ -1455,8 +1455,8 @@ packages: # max_query_field_depth: 2 # - name: organizationRevokeSharedAccount # max_query_field_depth: 2 -# - name: organizationUpdateSharedAccount -# max_query_field_depth: 2 + - name: organizationUpdateSharedAccount + max_query_field_depth: 2 types: - name: OrganizationNewManagedAccountInput field_type_override: "*OrganizationNewManagedAccountInput" diff --git a/pkg/organization/organization_api.go b/pkg/organization/organization_api.go index b756f8d5..c1c98cfd 100644 --- a/pkg/organization/organization_api.go +++ b/pkg/organization/organization_api.go @@ -121,3 +121,51 @@ const OrganizationUpdateMutation = `mutation( name } } }` + +// The shared account to update +func (a *Organization) OrganizationUpdateSharedAccount( + sharedAccount OrganizationUpdateSharedAccountInput, +) (*OrganizationUpdateSharedAccountResponse, error) { + return a.OrganizationUpdateSharedAccountWithContext(context.Background(), + sharedAccount, + ) +} + +// The shared account to update +func (a *Organization) OrganizationUpdateSharedAccountWithContext( + ctx context.Context, + sharedAccount OrganizationUpdateSharedAccountInput, +) (*OrganizationUpdateSharedAccountResponse, error) { + + resp := OrganizationUpdateSharedAccountQueryResponse{} + vars := map[string]interface{}{ + "sharedAccount": sharedAccount, + } + + if err := a.client.NerdGraphQueryWithContext(ctx, OrganizationUpdateSharedAccountMutation, vars, &resp); err != nil { + return nil, err + } + + return &resp.OrganizationUpdateSharedAccountResponse, nil +} + +type OrganizationUpdateSharedAccountQueryResponse struct { + OrganizationUpdateSharedAccountResponse OrganizationUpdateSharedAccountResponse `json:"OrganizationUpdateSharedAccount"` +} + +const OrganizationUpdateSharedAccountMutation = `mutation( + $sharedAccount: OrganizationUpdateSharedAccountInput!, +) { organizationUpdateSharedAccount( + sharedAccount: $sharedAccount, +) { + sharedAccount { + accountId + id + limitingRoleId + name + sourceOrganizationId + sourceOrganizationName + targetOrganizationId + targetOrganizationName + } +} }` diff --git a/pkg/organization/organization_integration_test.go b/pkg/organization/organization_integration_test.go index 451d5687..7ab78fd6 100644 --- a/pkg/organization/organization_integration_test.go +++ b/pkg/organization/organization_integration_test.go @@ -5,8 +5,9 @@ import ( "regexp" "testing" - mock "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" "github.com/stretchr/testify/require" + + mock "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" ) func TestIntegrationOrganizationCreate_CustomerIdNotFoundError(t *testing.T) { diff --git a/pkg/organization/organization_test.go b/pkg/organization/organization_test.go index b8d5e115..7480adb6 100644 --- a/pkg/organization/organization_test.go +++ b/pkg/organization/organization_test.go @@ -26,6 +26,9 @@ var ( unitTestMockOrganizationOneName = "Mock Organization One" unitTestMockOrganizationOneId = "e1fe1ff8-0032-43d5-935f-caf47567a71d" + unitTestMockAccountOneId = 123456 + unitTestMockLimitingRoleId = 1000 + organizationNameUpdated = "Virtuoso / OaC Organization" organizationId = os.Getenv("INTEGRATION_TESTING_NEW_RELIC_ORGANIZATION_ID") ) diff --git a/pkg/organization/organization_unit_test.go b/pkg/organization/organization_unit_test.go index 61ce8a2a..4308de62 100644 --- a/pkg/organization/organization_unit_test.go +++ b/pkg/organization/organization_unit_test.go @@ -1,6 +1,7 @@ package organization import ( + "fmt" "net/http" "testing" @@ -26,6 +27,21 @@ var ( } } }` + + testUpdateSharedAccountResponseJSON = `{ + "data": { + "organizationUpdateSharedAccount": { + "sharedAccount": { + "accountId": ` + fmt.Sprint(unitTestMockAccountOneId) + `, + "id": "` + unitTestMockOrganizationOneId + `", + "limitingRoleId": ` + fmt.Sprint(unitTestMockLimitingRoleId) + `, + "name": "` + unitTestMockOrganizationOneName + `", + "sourceOrganizationId": "` + unitTestMockOrganizationOneId + `", + "sourceOrganizationName": "` + unitTestMockOrganizationOneName + `" + } + } + } + }` ) func TestUnitCreateOrganization(t *testing.T) { @@ -76,3 +92,31 @@ func TestUnitUpdateOrganization(t *testing.T) { assert.NotNil(t, actual) assert.Equal(t, expected, actual) } + +func TestUnitOrganizationUpdateSharedAccount(t *testing.T) { + t.Parallel() + + organization := newMockResponse(t, testUpdateSharedAccountResponseJSON, http.StatusOK) + + expected := &OrganizationUpdateSharedAccountResponse{ + SharedAccount: OrganizationSharedAccount{ + AccountID: unitTestMockAccountOneId, + ID: unitTestMockOrganizationOneId, + LimitingRoleId: unitTestMockLimitingRoleId, + Name: unitTestMockOrganizationOneName, + SourceOrganizationId: unitTestMockOrganizationOneId, + SourceOrganizationName: unitTestMockOrganizationOneName, + }, + } + + actual, err := organization.OrganizationUpdateSharedAccount( + OrganizationUpdateSharedAccountInput{ + ID: fmt.Sprint(unitTestMockAccountOneId), + LimitingRoleId: unitTestMockLimitingRoleId, + }, + ) + + assert.NoError(t, err) + assert.NotNil(t, actual) + assert.Equal(t, expected, actual) +}