diff --git a/e2e/trust/helpers_test.go b/e2e/trust/helpers_test.go new file mode 100644 index 000000000..6891613ee --- /dev/null +++ b/e2e/trust/helpers_test.go @@ -0,0 +1,75 @@ +// Copyright (c) 2026 Probo Inc . +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +package trust_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "go.probo.inc/probo/e2e/internal/testutil" +) + +// lookupTrustCenterID resolves the trust center ID of the owner's organization. +func lookupTrustCenterID(t *testing.T, owner *testutil.Client) string { + t.Helper() + + const query = ` + query($organizationId: ID!) { + node(id: $organizationId) { + ... on Organization { + trustCenter { id } + } + } + } + ` + + var result struct { + Node struct { + TrustCenter struct { + ID string `json:"id"` + } `json:"trustCenter"` + } `json:"node"` + } + + err := owner.Execute(query, map[string]any{ + "organizationId": owner.GetOrganizationID().String(), + }, &result) + require.NoError(t, err) + require.NotEmpty(t, result.Node.TrustCenter.ID) + + return result.Node.TrustCenter.ID +} + +// activateTrustCenter flips the trust center to active so its public surface +// (NDA, subprocessors, reports, branding) becomes reachable by visitors. +func activateTrustCenter(t *testing.T, owner *testutil.Client, trustCenterID string) { + t.Helper() + + const query = ` + mutation($input: UpdateTrustCenterInput!) { + updateTrustCenter(input: $input) { + trustCenter { id active } + } + } + ` + + err := owner.Execute(query, map[string]any{ + "input": map[string]any{ + "trustCenterId": trustCenterID, + "active": true, + }, + }, nil) + require.NoError(t, err) +} diff --git a/e2e/trust/subprocessors_filter_test.go b/e2e/trust/subprocessors_filter_test.go index 02e21cfa4..d06dc1399 100644 --- a/e2e/trust/subprocessors_filter_test.go +++ b/e2e/trust/subprocessors_filter_test.go @@ -27,7 +27,8 @@ func TestTrustCenter_SubprocessorsFilter(t *testing.T) { t.Parallel() owner := testutil.NewClient(t, testutil.RoleOwner) - trustCenterID := activateTrustCenter(t, owner) + trustCenterID := lookupTrustCenterID(t, owner) + activateTrustCenter(t, owner, trustCenterID) awsName := factory.SafeName("AWS") awsID := factory.NewThirdParty(owner).WithName(awsName).WithCategory("CLOUD_PROVIDER").Create() @@ -155,52 +156,6 @@ func querySubprocessors( return result } -func activateTrustCenter(t *testing.T, owner *testutil.Client) string { - t.Helper() - - const trustCenterQuery = ` - query($organizationId: ID!) { - node(id: $organizationId) { - ... on Organization { - trustCenter { id } - } - } - } - ` - - var lookup struct { - Node struct { - TrustCenter struct { - ID string `json:"id"` - } `json:"trustCenter"` - } `json:"node"` - } - - err := owner.Execute(trustCenterQuery, map[string]any{ - "organizationId": owner.GetOrganizationID().String(), - }, &lookup) - require.NoError(t, err) - require.NotEmpty(t, lookup.Node.TrustCenter.ID) - - const activateMutation = ` - mutation($input: UpdateTrustCenterInput!) { - updateTrustCenter(input: $input) { - trustCenter { id active } - } - } - ` - - err = owner.Execute(activateMutation, map[string]any{ - "input": map[string]any{ - "trustCenterId": lookup.Node.TrustCenter.ID, - "active": true, - }, - }, nil) - require.NoError(t, err) - - return lookup.Node.TrustCenter.ID -} - func publishSubprocessor(t *testing.T, owner *testutil.Client, thirdPartyID string, countries []string) { t.Helper() diff --git a/e2e/trust/trust_center_logo_test.go b/e2e/trust/trust_center_logo_test.go index 045f8d991..1f923b7ce 100644 --- a/e2e/trust/trust_center_logo_test.go +++ b/e2e/trust/trust_center_logo_test.go @@ -30,54 +30,8 @@ func TestTrustCenter_LogoFileDownloadURL(t *testing.T) { t.Parallel() owner := testutil.NewClient(t, testutil.RoleOwner) - organizationID := owner.GetOrganizationID().String() - - const trustCenterQuery = ` - query($organizationId: ID!) { - node(id: $organizationId) { - ... on Organization { - trustCenter { - id - } - } - } - } - ` - - var trustCenterLookup struct { - Node struct { - TrustCenter struct { - ID string `json:"id"` - } `json:"trustCenter"` - } `json:"node"` - } - - err := owner.Execute(trustCenterQuery, map[string]any{ - "organizationId": organizationID, - }, &trustCenterLookup) - require.NoError(t, err) - require.NotEmpty(t, trustCenterLookup.Node.TrustCenter.ID) - - trustCenterID := trustCenterLookup.Node.TrustCenter.ID - - const activateMutation = ` - mutation($input: UpdateTrustCenterInput!) { - updateTrustCenter(input: $input) { - trustCenter { - id - active - } - } - } - ` - - err = owner.Execute(activateMutation, map[string]any{ - "input": map[string]any{ - "trustCenterId": trustCenterID, - "active": true, - }, - }, nil) - require.NoError(t, err) + trustCenterID := lookupTrustCenterID(t, owner) + activateTrustCenter(t, owner, trustCenterID) const uploadMutation = ` mutation UpdateTrustCenterBrand($input: UpdateTrustCenterBrandInput!) { @@ -119,7 +73,7 @@ func TestTrustCenter_LogoFileDownloadURL(t *testing.T) { } `json:"updateTrustCenterBrand"` } - err = owner.ExecuteWithFile(uploadMutation, map[string]any{ + err := owner.ExecuteWithFile(uploadMutation, map[string]any{ "input": map[string]any{ "trustCenterId": trustCenterID, "logoFile": nil, diff --git a/e2e/trust/trust_center_nda_signature_test.go b/e2e/trust/trust_center_nda_signature_test.go index 7169c418d..8651b9e41 100644 --- a/e2e/trust/trust_center_nda_signature_test.go +++ b/e2e/trust/trust_center_nda_signature_test.go @@ -113,36 +113,6 @@ func TestTrustCenter_AcceptElectronicSignature_RejectsForeignSignature(t *testin assert.Equal(t, "ACCEPTED", acceptResult.AcceptElectronicSignature.Signature.Status) } -func lookupTrustCenterID(t *testing.T, owner *testutil.Client) string { - t.Helper() - - const query = ` - query($organizationId: ID!) { - node(id: $organizationId) { - ... on Organization { - trustCenter { id } - } - } - } - ` - - var result struct { - Node struct { - TrustCenter struct { - ID string `json:"id"` - } `json:"trustCenter"` - } `json:"node"` - } - - err := owner.Execute(query, map[string]any{ - "organizationId": owner.GetOrganizationID().String(), - }, &result) - require.NoError(t, err) - require.NotEmpty(t, result.Node.TrustCenter.ID) - - return result.Node.TrustCenter.ID -} - func uploadTrustCenterNDA(t *testing.T, owner *testutil.Client, trustCenterID string) { t.Helper() @@ -171,26 +141,6 @@ func uploadTrustCenterNDA(t *testing.T, owner *testutil.Client, trustCenterID st require.NoError(t, err) } -func activateTrustCenter(t *testing.T, owner *testutil.Client, trustCenterID string) { - t.Helper() - - const query = ` - mutation($input: UpdateTrustCenterInput!) { - updateTrustCenter(input: $input) { - trustCenter { id active } - } - } - ` - - err := owner.Execute(query, map[string]any{ - "input": map[string]any{ - "trustCenterId": trustCenterID, - "active": true, - }, - }, nil) - require.NoError(t, err) -} - func viewerSignature(t *testing.T, visitor *testutil.Client, trustCenterID string) (string, string) { t.Helper() diff --git a/e2e/trust/trust_center_report_export_test.go b/e2e/trust/trust_center_report_export_test.go index 944f32e70..8b89bc702 100644 --- a/e2e/trust/trust_center_report_export_test.go +++ b/e2e/trust/trust_center_report_export_test.go @@ -188,47 +188,8 @@ func setupPublicAuditReport(t *testing.T, owner *testutil.Client) (trustCenterID }, nil) require.NoError(t, err) - const trustCenterQuery = ` - query($organizationId: ID!) { - node(id: $organizationId) { - ... on Organization { - trustCenter { id } - } - } - } - ` - - var trustCenterLookup struct { - Node struct { - TrustCenter struct { - ID string `json:"id"` - } `json:"trustCenter"` - } `json:"node"` - } - - err = owner.Execute(trustCenterQuery, map[string]any{ - "organizationId": owner.GetOrganizationID().String(), - }, &trustCenterLookup) - require.NoError(t, err) - - trustCenterID = trustCenterLookup.Node.TrustCenter.ID - require.NotEmpty(t, trustCenterID) - - const activateMutation = ` - mutation($input: UpdateTrustCenterInput!) { - updateTrustCenter(input: $input) { - trustCenter { id active } - } - } - ` - - err = owner.Execute(activateMutation, map[string]any{ - "input": map[string]any{ - "trustCenterId": trustCenterID, - "active": true, - }, - }, nil) - require.NoError(t, err) + trustCenterID = lookupTrustCenterID(t, owner) + activateTrustCenter(t, owner, trustCenterID) return trustCenterID, reportID }