Add end-to-end tests for trust center aliases

Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
Bryan Frimin
2026-06-22 08:40:43 +02:00
parent cd52e7fb0c
commit 9a56311d60
2 changed files with 170 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// 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 console_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.probo.inc/probo/e2e/internal/factory"
"go.probo.inc/probo/e2e/internal/testutil"
)
func TestTrustCenterAlias_SetAndRead(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
documentID := factory.NewDocument(owner).WithTitle("Alias Test Document").Create()
const setAliasMutation = `
mutation($input: SetTrustCenterAliasInput!) {
setTrustCenterAlias(input: $input) {
alias {
resourceId
alias
}
}
}
`
var setResult struct {
SetTrustCenterAlias struct {
Alias struct {
ResourceID string `json:"resourceId"`
Alias string `json:"alias"`
} `json:"alias"`
} `json:"setTrustCenterAlias"`
}
err := owner.Execute(setAliasMutation, map[string]any{
"input": map[string]any{
"resourceId": documentID,
"alias": "privacy-policy",
},
}, &setResult)
require.NoError(t, err)
assert.Equal(t, documentID, setResult.SetTrustCenterAlias.Alias.ResourceID)
assert.Equal(t, "privacy-policy", setResult.SetTrustCenterAlias.Alias.Alias)
const getDocumentQuery = `
query($id: ID!) {
node(id: $id) {
... on Document {
id
alias
}
}
}
`
var getResult struct {
Node struct {
ID string `json:"id"`
Alias *string `json:"alias"`
} `json:"node"`
}
err = owner.Execute(getDocumentQuery, map[string]any{"id": documentID}, &getResult)
require.NoError(t, err)
require.NotNil(t, getResult.Node.Alias)
assert.Equal(t, "privacy-policy", *getResult.Node.Alias)
}
func TestTrustCenterAlias_Conflict(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
docA := factory.NewDocument(owner).WithTitle("Alias Conflict A").Create()
docB := factory.NewDocument(owner).WithTitle("Alias Conflict B").Create()
const setAliasMutation = `
mutation($input: SetTrustCenterAliasInput!) {
setTrustCenterAlias(input: $input) {
alias { alias }
}
}
`
err := owner.Execute(setAliasMutation, map[string]any{
"input": map[string]any{
"resourceId": docA,
"alias": "shared-alias",
},
}, nil)
require.NoError(t, err)
_, err = owner.Do(setAliasMutation, map[string]any{
"input": map[string]any{
"resourceId": docB,
"alias": "shared-alias",
},
})
require.Error(t, err)
}

View File

@@ -0,0 +1,54 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// 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 mcp_test
import (
"testing"
"github.com/stretchr/testify/assert"
"go.probo.inc/probo/e2e/internal/factory"
"go.probo.inc/probo/e2e/internal/testutil"
)
func TestMCP_SetTrustCenterAlias(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
mc := testutil.NewMCPClient(t, owner)
documentID := factory.NewDocument(owner).WithTitle("MCP Alias Document").Create()
var result struct {
TrustCenterAlias struct {
ResourceID string `json:"resource_id"`
Alias string `json:"alias"`
} `json:"trust_center_alias"`
}
mc.CallToolInto("setTrustCenterAlias", map[string]any{
"resource_id": documentID,
"alias": "mcp-privacy-policy",
}, &result)
assert.Equal(t, documentID, result.TrustCenterAlias.ResourceID)
assert.Equal(t, "mcp-privacy-policy", result.TrustCenterAlias.Alias)
var removeResult struct {
DeletedResourceID string `json:"deleted_resource_id"`
}
mc.CallToolInto("removeTrustCenterAlias", map[string]any{
"resource_id": documentID,
}, &removeResult)
assert.Equal(t, documentID, removeResult.DeletedResourceID)
}