Add document approval workflow

Introduce a complete approval system for document publishing. Document
versions can now require approval from selected reviewers before being
published, with automatic publishing once all approvers have approved.

- Add approval quorum and decision tables with backfill migration
- Implement request approval, approve, and reject flows with electronic
  signature support for approve decisions
- Add employee approvals page with dedicated tab and pending approvals view
- Add changelog field to publish and request approval flows
- Pre-select previous version's approvers in the publish dialog
- Show quorum approvers in document list with 100 approver hard limit
- Expose approval workflow through GraphQL, MCP, and CLI
- Remove legacy default approvers feature entirely
- Add comprehensive e2e test coverage for approval workflows

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-03-27 17:22:54 +01:00
parent 4a2d308da0
commit 999171a626
78 changed files with 6483 additions and 1600 deletions

View File

@@ -30,7 +30,6 @@ import (
func TestDocument_Create(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
tests := []struct {
name string
@@ -114,7 +113,6 @@ func TestDocument_Create(t *testing.T) {
input := map[string]any{
"organizationId": owner.GetOrganizationID().String(),
"approverIds": []string{approverProfileID},
}
maps.Copy(input, tt.input)
@@ -150,13 +148,11 @@ func TestDocument_Create(t *testing.T) {
func TestDocument_Create_Validation(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
tests := []struct {
name string
input map[string]any
skipOrganization bool
skipApprover bool
wantErrorContains string
}{
{
@@ -170,17 +166,6 @@ func TestDocument_Create_Validation(t *testing.T) {
skipOrganization: true,
wantErrorContains: "organizationId",
},
{
name: "missing approverIds",
input: map[string]any{
"title": "Test Document",
"content": "Test content",
"documentType": "POLICY",
"classification": "INTERNAL",
},
skipApprover: true,
wantErrorContains: "approverIds",
},
{
name: "title with HTML tags",
input: map[string]any{
@@ -281,9 +266,6 @@ func TestDocument_Create_Validation(t *testing.T) {
if !tt.skipOrganization {
input["organizationId"] = owner.GetOrganizationID().String()
}
if !tt.skipApprover {
input["approverIds"] = []string{approverProfileID}
}
maps.Copy(input, tt.input)
_, err := owner.Do(query, map[string]any{"input": input})
@@ -296,7 +278,6 @@ func TestDocument_Create_Validation(t *testing.T) {
func TestDocument_Update(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
tests := []struct {
name string
@@ -308,7 +289,7 @@ func TestDocument_Update(t *testing.T) {
{
name: "update title",
setup: func() string {
return factory.NewDocument(owner, approverProfileID).
return factory.NewDocument(owner).
WithTitle("Document to Update").
Create()
},
@@ -324,7 +305,7 @@ func TestDocument_Update(t *testing.T) {
{
name: "update document type",
setup: func() string {
return factory.NewDocument(owner, approverProfileID).
return factory.NewDocument(owner).
WithTitle("Type Test").
WithDocumentType("POLICY").
Create()
@@ -380,8 +361,8 @@ func TestDocument_Update(t *testing.T) {
func TestDocument_Update_Validation(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
baseDocumentID := factory.NewDocument(owner, approverProfileID).WithTitle("Validation Test Document").Create()
baseDocumentID := factory.NewDocument(owner).WithTitle("Validation Test Document").Create()
tests := []struct {
name string
@@ -463,10 +444,9 @@ func TestDocument_Update_Validation(t *testing.T) {
func TestDocument_Delete(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
t.Run("delete existing document", func(t *testing.T) {
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("Document to Delete").Create()
documentID := factory.NewDocument(owner).WithTitle("Document to Delete").Create()
query := `
mutation DeleteDocument($input: DeleteDocumentInput!) {
@@ -528,11 +508,10 @@ func TestDocument_Delete_Validation(t *testing.T) {
func TestDocument_List(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
documentTitles := []string{"Document A", "Document B", "Document C"}
for _, title := range documentTitles {
factory.NewDocument(owner, approverProfileID).WithTitle(title).Create()
factory.NewDocument(owner).WithTitle(title).Create()
}
query := `
@@ -600,7 +579,6 @@ func TestDocument_Query(t *testing.T) {
func TestDocument_Timestamps(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
t.Run("createdAt and updatedAt are set on create", func(t *testing.T) {
beforeCreate := time.Now().Add(-time.Second)
@@ -634,7 +612,6 @@ func TestDocument_Timestamps(t *testing.T) {
err := owner.Execute(query, map[string]any{
"input": map[string]any{
"organizationId": owner.GetOrganizationID().String(),
"approverIds": []string{approverProfileID},
"title": "Timestamp Test Document",
"content": "Test content",
"documentType": "POLICY",
@@ -648,7 +625,7 @@ func TestDocument_Timestamps(t *testing.T) {
})
t.Run("updatedAt changes on update", func(t *testing.T) {
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("Timestamp Update Test").Create()
documentID := factory.NewDocument(owner).WithTitle("Timestamp Update Test").Create()
getQuery := `
query($id: ID!) {
@@ -713,50 +690,8 @@ func TestDocument_Timestamps(t *testing.T) {
func TestDocument_SubResolvers(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("SubResolver Test Document").Create()
t.Run("approvers sub-resolver", func(t *testing.T) {
query := `
query($id: ID!) {
node(id: $id) {
... on Document {
id
approvers {
totalCount
edges {
node {
id
fullName
}
}
}
}
}
}
`
var result struct {
Node struct {
ID string `json:"id"`
Approvers struct {
TotalCount int `json:"totalCount"`
Edges []struct {
Node struct {
ID string `json:"id"`
FullName string `json:"fullName"`
} `json:"node"`
} `json:"edges"`
} `json:"approvers"`
} `json:"node"`
}
err := owner.Execute(query, map[string]any{"id": documentID}, &result)
require.NoError(t, err)
assert.Equal(t, 1, result.Node.Approvers.TotalCount)
require.Len(t, result.Node.Approvers.Edges, 1)
assert.Equal(t, approverProfileID, result.Node.Approvers.Edges[0].Node.ID)
})
documentID := factory.NewDocument(owner).WithTitle("SubResolver Test Document").Create()
t.Run("organization sub-resolver", func(t *testing.T) {
query := `
@@ -796,7 +731,6 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("create", func(t *testing.T) {
t.Run("owner can create", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
_, err := owner.Do(`
mutation CreateDocument($input: CreateDocumentInput!) {
@@ -807,7 +741,6 @@ func TestDocument_RBAC(t *testing.T) {
`, map[string]any{
"input": map[string]any{
"organizationId": owner.GetOrganizationID().String(),
"approverIds": []string{approverProfileID},
"title": "RBAC Test Document",
"content": "Test content",
"documentType": "POLICY",
@@ -820,7 +753,6 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("admin can create", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
admin := testutil.NewClientInOrg(t, testutil.RoleAdmin, owner)
approverProfileID := factory.CreateUser(owner)
_, err := admin.Do(`
mutation CreateDocument($input: CreateDocumentInput!) {
@@ -831,7 +763,6 @@ func TestDocument_RBAC(t *testing.T) {
`, map[string]any{
"input": map[string]any{
"organizationId": admin.GetOrganizationID().String(),
"approverIds": []string{approverProfileID},
"title": "RBAC Test Document",
"content": "Test content",
"documentType": "POLICY",
@@ -844,7 +775,6 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("viewer cannot create", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
viewer := testutil.NewClientInOrg(t, testutil.RoleViewer, owner)
approverProfileID := factory.CreateUser(owner)
_, err := viewer.Do(`
mutation CreateDocument($input: CreateDocumentInput!) {
@@ -855,7 +785,6 @@ func TestDocument_RBAC(t *testing.T) {
`, map[string]any{
"input": map[string]any{
"organizationId": viewer.GetOrganizationID().String(),
"approverIds": []string{approverProfileID},
"title": "RBAC Test Document",
"content": "Test content",
"documentType": "POLICY",
@@ -869,8 +798,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("update", func(t *testing.T) {
t.Run("owner can update", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Update Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Update Test").Create()
_, err := owner.Do(`
mutation UpdateDocument($input: UpdateDocumentInput!) {
@@ -890,8 +819,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("admin can update", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
admin := testutil.NewClientInOrg(t, testutil.RoleAdmin, owner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Update Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Update Test").Create()
_, err := admin.Do(`
mutation UpdateDocument($input: UpdateDocumentInput!) {
@@ -911,8 +840,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("viewer cannot update", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
viewer := testutil.NewClientInOrg(t, testutil.RoleViewer, owner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Update Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Update Test").Create()
_, err := viewer.Do(`
mutation UpdateDocument($input: UpdateDocumentInput!) {
@@ -933,8 +862,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("delete", func(t *testing.T) {
t.Run("owner can delete", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Delete Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Delete Test").Create()
_, err := owner.Do(`
mutation DeleteDocument($input: DeleteDocumentInput!) {
@@ -951,8 +880,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("admin can delete", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
admin := testutil.NewClientInOrg(t, testutil.RoleAdmin, owner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Delete Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Delete Test").Create()
_, err := admin.Do(`
mutation DeleteDocument($input: DeleteDocumentInput!) {
@@ -969,8 +898,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("viewer cannot delete", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
viewer := testutil.NewClientInOrg(t, testutil.RoleViewer, owner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Delete Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Delete Test").Create()
_, err := viewer.Do(`
mutation DeleteDocument($input: DeleteDocumentInput!) {
@@ -988,8 +917,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("read", func(t *testing.T) {
t.Run("owner can read", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Read Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Read Test").Create()
var result struct {
Node *struct {
@@ -1012,8 +941,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("admin can read", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
admin := testutil.NewClientInOrg(t, testutil.RoleAdmin, owner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Read Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Read Test").Create()
var result struct {
Node *struct {
@@ -1036,8 +965,8 @@ func TestDocument_RBAC(t *testing.T) {
t.Run("viewer can read", func(t *testing.T) {
owner := testutil.NewClient(t, testutil.RoleOwner)
viewer := testutil.NewClientInOrg(t, testutil.RoleViewer, owner)
approverProfileID := factory.CreateUser(owner)
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("RBAC Read Test").Create()
documentID := factory.NewDocument(owner).WithTitle("RBAC Read Test").Create()
var result struct {
Node *struct {
@@ -1062,7 +991,6 @@ func TestDocument_RBAC(t *testing.T) {
func TestDocument_MaxLength_Validation(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
longTitle := strings.Repeat("a", 1001)
@@ -1080,7 +1008,6 @@ func TestDocument_MaxLength_Validation(t *testing.T) {
_, err := owner.Do(query, map[string]any{
"input": map[string]any{
"organizationId": owner.GetOrganizationID().String(),
"approverIds": []string{approverProfileID},
"title": longTitle,
"content": "Test content",
"documentType": "POLICY",
@@ -1092,7 +1019,7 @@ func TestDocument_MaxLength_Validation(t *testing.T) {
})
t.Run("update", func(t *testing.T) {
documentID := factory.NewDocument(owner, approverProfileID).WithTitle("Max Length Test").Create()
documentID := factory.NewDocument(owner).WithTitle("Max Length Test").Create()
query := `
mutation UpdateDocument($input: UpdateDocumentInput!) {
@@ -1116,10 +1043,9 @@ func TestDocument_MaxLength_Validation(t *testing.T) {
func TestDocument_Pagination(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
for i := range 5 {
factory.NewDocument(owner, approverProfileID).
factory.NewDocument(owner).
WithTitle(fmt.Sprintf("Pagination Document %d", i)).
Create()
}
@@ -1265,8 +1191,7 @@ func TestDocument_TenantIsolation(t *testing.T) {
org1Owner := testutil.NewClient(t, testutil.RoleOwner)
org2Owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(org1Owner)
documentID := factory.NewDocument(org1Owner, approverProfileID).WithTitle("Org1 Document").Create()
documentID := factory.NewDocument(org1Owner).WithTitle("Org1 Document").Create()
t.Run("cannot read document from another organization", func(t *testing.T) {
query := `
@@ -1372,10 +1297,9 @@ func TestDocument_TenantIsolation(t *testing.T) {
func TestDocument_Ordering(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
approverProfileID := factory.CreateUser(owner)
factory.NewDocument(owner, approverProfileID).WithTitle("AAA Order Test").Create()
factory.NewDocument(owner, approverProfileID).WithTitle("ZZZ Order Test").Create()
factory.NewDocument(owner).WithTitle("AAA Order Test").Create()
factory.NewDocument(owner).WithTitle("ZZZ Order Test").Create()
t.Run("order by created_at descending", func(t *testing.T) {
query := `

View File

@@ -23,10 +23,52 @@ import (
"go.probo.inc/probo/e2e/internal/testutil"
)
// getOwnerProfileID queries the organization profiles and returns the first one (the owner's).
func getOwnerProfileID(t *testing.T, owner *testutil.Client) string {
t.Helper()
query := `
query GetProfiles($orgId: ID!) {
node(id: $orgId) {
... on Organization {
profiles(first: 1) {
edges {
node {
id
}
}
}
}
}
}
`
var result struct {
Node struct {
Profiles struct {
Edges []struct {
Node struct {
ID string `json:"id"`
} `json:"node"`
} `json:"edges"`
} `json:"profiles"`
} `json:"node"`
}
err := owner.Execute(
query,
map[string]any{"orgId": owner.GetOrganizationID().String()},
&result,
)
require.NoError(t, err)
require.NotEmpty(t, result.Node.Profiles.Edges)
return result.Node.Profiles.Edges[0].Node.ID
}
// createTestDocument creates a document and returns its ID and the document version ID
func createTestDocument(t *testing.T, owner *testutil.Client) (docID string, docVersionID string) {
t.Helper()
profileID := factory.CreateUser(owner)
query := `
mutation CreateDocument($input: CreateDocumentInput!) {
@@ -69,7 +111,6 @@ func createTestDocument(t *testing.T, owner *testutil.Client) (docID string, doc
"organizationId": owner.GetOrganizationID().String(),
"title": "Test Document",
"content": "Initial content",
"approverIds": []string{profileID},
"documentType": "POLICY",
"classification": "INTERNAL",
},
@@ -83,79 +124,143 @@ func createTestDocument(t *testing.T, owner *testutil.Client) (docID string, doc
return docID, docVersionID
}
// approveTestDocument requests approval and approves the document so it can be published.
func approveTestDocument(t *testing.T, owner *testutil.Client, docID string) {
t.Helper()
requestQuery := `
mutation RequestApproval($input: RequestDocumentVersionApprovalInput!) {
requestDocumentVersionApproval(input: $input) {
approvalQuorum {
id
}
}
}
`
// Use the owner's profile as the approver
approverID := getOwnerProfileID(t, owner)
_, err := owner.Do(requestQuery, map[string]any{
"input": map[string]any{
"documentId": docID,
"approverIds": []string{approverID},
"changelog": "Test changelog",
},
})
require.NoError(t, err)
// Approve for each approver
approveQuery := `
mutation ApproveDocumentVersion($input: ApproveDocumentVersionInput!) {
approveDocumentVersion(input: $input) {
approvalDecision {
id
state
}
}
}
`
// Get the latest version ID
versionQuery := `
query GetVersions($id: ID!) {
node(id: $id) {
... on Document {
versions(first: 1, orderBy: { field: CREATED_AT, direction: DESC }) {
edges {
node {
id
}
}
}
}
}
}
`
var versionResult struct {
Node struct {
Versions struct {
Edges []struct {
Node struct {
ID string `json:"id"`
} `json:"node"`
} `json:"edges"`
} `json:"versions"`
} `json:"node"`
}
err = owner.Execute(versionQuery, map[string]any{"id": docID}, &versionResult)
require.NoError(t, err)
require.NotEmpty(t, versionResult.Node.Versions.Edges)
versionID := versionResult.Node.Versions.Edges[0].Node.ID
_, err = owner.Do(approveQuery, map[string]any{
"input": map[string]any{
"documentVersionId": versionID,
},
})
require.NoError(t, err)
}
func TestDocumentVersion_PublishVersion(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
docID, _ := createTestDocument(t, owner)
approveTestDocument(t, owner, docID)
// After approval, the version is auto-published.
// Verify the version status by querying.
query := `
mutation PublishDocumentVersion($input: PublishDocumentVersionInput!) {
publishDocumentVersion(input: $input) {
documentVersion {
id
status
version
changelog
}
document {
id
query GetDocument($id: ID!) {
node(id: $id) {
... on Document {
versions(first: 1, orderBy: { field: CREATED_AT, direction: DESC }) {
edges {
node {
id
status
version
}
}
}
}
}
}
`
var result struct {
PublishDocumentVersion struct {
DocumentVersion struct {
ID string `json:"id"`
Status string `json:"status"`
Version int `json:"version"`
Changelog string `json:"changelog"`
} `json:"documentVersion"`
Document struct {
ID string `json:"id"`
} `json:"document"`
} `json:"publishDocumentVersion"`
Node struct {
Versions struct {
Edges []struct {
Node struct {
ID string `json:"id"`
Status string `json:"status"`
Version int `json:"version"`
} `json:"node"`
} `json:"edges"`
} `json:"versions"`
} `json:"node"`
}
err := owner.Execute(query, map[string]any{
"input": map[string]any{
"documentId": docID,
"changelog": "Initial release",
},
}, &result)
err := owner.Execute(query, map[string]any{"id": docID}, &result)
require.NoError(t, err)
require.NotEmpty(t, result.Node.Versions.Edges)
assert.Equal(t, "PUBLISHED", result.PublishDocumentVersion.DocumentVersion.Status)
assert.Equal(t, 1, result.PublishDocumentVersion.DocumentVersion.Version)
assert.Equal(t, "Initial release", result.PublishDocumentVersion.DocumentVersion.Changelog)
assert.Equal(t, "PUBLISHED", result.Node.Versions.Edges[0].Node.Status)
assert.Equal(t, 1, result.Node.Versions.Edges[0].Node.Version)
}
func TestDocumentVersion_CreateDraft(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
// Create and publish a document first
// Create and approve a document (auto-publishes on approval)
docID, _ := createTestDocument(t, owner)
publishQuery := `
mutation PublishDocumentVersion($input: PublishDocumentVersionInput!) {
publishDocumentVersion(input: $input) {
documentVersion {
id
}
}
}
`
_, err := owner.Do(publishQuery, map[string]any{
"input": map[string]any{
"documentId": docID,
"changelog": "Initial release",
},
})
require.NoError(t, err)
approveTestDocument(t, owner, docID)
query := `
mutation CreateDraftDocumentVersion($input: CreateDraftDocumentVersionInput!) {
@@ -181,7 +286,7 @@ func TestDocumentVersion_CreateDraft(t *testing.T) {
} `json:"createDraftDocumentVersion"`
}
err = owner.Execute(query, map[string]any{
err := owner.Execute(query, map[string]any{
"input": map[string]any{
"documentID": docID,
},
@@ -232,36 +337,44 @@ func TestDocumentVersion_RequestSignature(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
// Create and publish a document
// Create and approve a document (auto-publishes on approval)
docID, _ := createTestDocument(t, owner)
approveTestDocument(t, owner, docID)
publishQuery := `
mutation PublishDocumentVersion($input: PublishDocumentVersionInput!) {
publishDocumentVersion(input: $input) {
documentVersion {
id
// Get the published version ID
versionQuery := `
query GetVersions($id: ID!) {
node(id: $id) {
... on Document {
versions(first: 1, orderBy: { field: CREATED_AT, direction: DESC }) {
edges {
node {
id
}
}
}
}
}
}
`
var publishResult struct {
PublishDocumentVersion struct {
DocumentVersion struct {
ID string `json:"id"`
} `json:"documentVersion"`
} `json:"publishDocumentVersion"`
var versionResult struct {
Node struct {
Versions struct {
Edges []struct {
Node struct {
ID string `json:"id"`
} `json:"node"`
} `json:"edges"`
} `json:"versions"`
} `json:"node"`
}
err := owner.Execute(publishQuery, map[string]any{
"input": map[string]any{
"documentId": docID,
"changelog": "Initial release",
},
}, &publishResult)
err := owner.Execute(versionQuery, map[string]any{"id": docID}, &versionResult)
require.NoError(t, err)
require.NotEmpty(t, versionResult.Node.Versions.Edges)
publishedVersionID := publishResult.PublishDocumentVersion.DocumentVersion.ID
publishedVersionID := versionResult.Node.Versions.Edges[0].Node.ID
// Create a person to sign
signerProfileID := factory.CreateUser(owner)
@@ -318,15 +431,15 @@ func TestDocumentVersion_BulkPublish(t *testing.T) {
// Create multiple documents
docID1, _ := createTestDocument(t, owner)
docID2, _ := createTestDocument(t, owner)
approveTestDocument(t, owner, docID1)
approveTestDocument(t, owner, docID2)
query := `
mutation BulkPublishDocumentVersions($input: BulkPublishDocumentVersionsInput!) {
bulkPublishDocumentVersions(input: $input) {
documentVersionEdges {
node {
id
status
}
documentVersions {
id
status
}
}
}
@@ -334,12 +447,10 @@ func TestDocumentVersion_BulkPublish(t *testing.T) {
var result struct {
BulkPublishDocumentVersions struct {
DocumentVersionEdges []struct {
Node struct {
ID string `json:"id"`
Status string `json:"status"`
} `json:"node"`
} `json:"documentVersionEdges"`
DocumentVersions []struct {
ID string `json:"id"`
Status string `json:"status"`
} `json:"documentVersions"`
} `json:"bulkPublishDocumentVersions"`
}
@@ -351,9 +462,9 @@ func TestDocumentVersion_BulkPublish(t *testing.T) {
}, &result)
require.NoError(t, err)
assert.Equal(t, 2, len(result.BulkPublishDocumentVersions.DocumentVersionEdges))
for _, edge := range result.BulkPublishDocumentVersions.DocumentVersionEdges {
assert.Equal(t, "PUBLISHED", edge.Node.Status)
assert.Equal(t, 2, len(result.BulkPublishDocumentVersions.DocumentVersions))
for _, dv := range result.BulkPublishDocumentVersions.DocumentVersions {
assert.Equal(t, "PUBLISHED", dv.Status)
}
}
@@ -361,26 +472,9 @@ func TestDocumentVersion_BulkRequestSignatures(t *testing.T) {
t.Parallel()
owner := testutil.NewClient(t, testutil.RoleOwner)
// Create and publish a document
// Create and approve a document (auto-publishes on approval)
docID, _ := createTestDocument(t, owner)
publishQuery := `
mutation PublishDocumentVersion($input: PublishDocumentVersionInput!) {
publishDocumentVersion(input: $input) {
documentVersion {
id
}
}
}
`
_, err := owner.Do(publishQuery, map[string]any{
"input": map[string]any{
"documentId": docID,
"changelog": "Initial release",
},
})
require.NoError(t, err)
approveTestDocument(t, owner, docID)
// Create multiple signers
signer1ProfileID := factory.CreateUser(owner)
@@ -410,7 +504,7 @@ func TestDocumentVersion_BulkRequestSignatures(t *testing.T) {
} `json:"bulkRequestSignatures"`
}
err = owner.Execute(query, map[string]any{
err := owner.Execute(query, map[string]any{
"input": map[string]any{
"documentIds": []string{docID},
"signatoryIds": []string{signer1ProfileID, signer2ProfileID},

View File

@@ -370,7 +370,6 @@ func TestControlDocumentMapping_CreateDelete(t *testing.T) {
controlID := createControlResult.CreateControl.ControlEdge.Node.ID
// Create a document
profileID := factory.CreateUser(owner)
var createDocumentResult struct {
CreateDocument struct {
DocumentEdge struct {
@@ -395,7 +394,6 @@ func TestControlDocumentMapping_CreateDelete(t *testing.T) {
"organizationId": owner.GetOrganizationID().String(),
"title": "Document for Control Mapping",
"content": "Document content",
"approverIds": []string{profileID},
"documentType": "POLICY",
"classification": "INTERNAL",
},
@@ -760,7 +758,6 @@ func TestRiskDocumentMapping_CreateDelete(t *testing.T) {
riskID := createRiskResult.CreateRisk.RiskEdge.Node.ID
// Create a document
profileID := factory.CreateUser(owner)
var createDocumentResult struct {
CreateDocument struct {
DocumentEdge struct {
@@ -785,7 +782,6 @@ func TestRiskDocumentMapping_CreateDelete(t *testing.T) {
"organizationId": owner.GetOrganizationID().String(),
"title": "Document for Risk Mapping",
"content": "Document content",
"approverIds": []string{profileID},
"documentType": "POLICY",
"classification": "INTERNAL",
},

View File

@@ -824,7 +824,7 @@ func (b *MeetingBuilder) Create() string {
return CreateMeeting(b.client, b.attrs)
}
func CreateDocument(c *testutil.Client, approverID string, attrs ...Attrs) string {
func CreateDocument(c *testutil.Client, attrs ...Attrs) string {
c.T.Helper()
var a Attrs
@@ -844,7 +844,6 @@ func CreateDocument(c *testutil.Client, approverID string, attrs ...Attrs) strin
input := map[string]any{
"organizationId": c.GetOrganizationID().String(),
"approverIds": []string{approverID},
"title": a.getString("title", SafeName("Document")),
"content": a.getString("content", "Document content"),
"documentType": a.getString("documentType", "POLICY"),
@@ -868,13 +867,12 @@ func CreateDocument(c *testutil.Client, approverID string, attrs ...Attrs) strin
}
type DocumentBuilder struct {
client *testutil.Client
approverID string
attrs Attrs
client *testutil.Client
attrs Attrs
}
func NewDocument(c *testutil.Client, approverID string) *DocumentBuilder {
return &DocumentBuilder{client: c, approverID: approverID, attrs: Attrs{}}
func NewDocument(c *testutil.Client) *DocumentBuilder {
return &DocumentBuilder{client: c, attrs: Attrs{}}
}
func (b *DocumentBuilder) WithTitle(title string) *DocumentBuilder {
@@ -898,7 +896,7 @@ func (b *DocumentBuilder) WithClassification(classification string) *DocumentBui
}
func (b *DocumentBuilder) Create() string {
return CreateDocument(b.client, b.approverID, b.attrs)
return CreateDocument(b.client, b.attrs)
}
func CreateProcessingActivity(c *testutil.Client, attrs ...Attrs) string {