|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +// go test -v -run TestWorkspacePolicyCheck ./e2e/... |
| 9 | +func TestWorkspacePolicyCheck(t *testing.T) { |
| 10 | + e, _ := StartGQLServerAndRepos(t, baseSeederUser) |
| 11 | + |
| 12 | + // Test successful policy check for existing workspace |
| 13 | + res := Request(e, uId1.String(), GraphQLRequest{ |
| 14 | + Query: fmt.Sprintf(`query { |
| 15 | + workspacePolicyCheck(input: {workspaceId: "%s"}) { |
| 16 | + workspaceId |
| 17 | + enableToCreatePrivateProject |
| 18 | + } |
| 19 | + }`, wId1), |
| 20 | + }) |
| 21 | + |
| 22 | + // Verify the response structure |
| 23 | + res.Path("$.data.workspacePolicyCheck.workspaceId").IsEqual(wId1.String()) |
| 24 | + res.Path("$.data.workspacePolicyCheck.enableToCreatePrivateProject").IsBoolean() |
| 25 | + |
| 26 | + // Test with non-existent workspace ID |
| 27 | + nonExistentWorkspaceId := "01H4XCVR7QZJN0Z8V9XN9N9N9N" |
| 28 | + res = Request(e, uId1.String(), GraphQLRequest{ |
| 29 | + Query: fmt.Sprintf(`query { |
| 30 | + workspacePolicyCheck(input: {workspaceId: "%s"}) { |
| 31 | + workspaceId |
| 32 | + enableToCreatePrivateProject |
| 33 | + } |
| 34 | + }`, nonExistentWorkspaceId), |
| 35 | + }) |
| 36 | + |
| 37 | + // Should return error for non-existent workspace |
| 38 | + res.Path("$.errors[0].message").IsString() |
| 39 | + |
| 40 | + // Test with invalid workspace ID format |
| 41 | + res = Request(e, uId1.String(), GraphQLRequest{ |
| 42 | + Query: `query { |
| 43 | + workspacePolicyCheck(input: {workspaceId: "invalid-id"}) { |
| 44 | + workspaceId |
| 45 | + enableToCreatePrivateProject |
| 46 | + } |
| 47 | + }`, |
| 48 | + }) |
| 49 | + |
| 50 | + // Should return error for invalid ID format |
| 51 | + res.Path("$.errors[0].message").IsString() |
| 52 | +} |
| 53 | + |
| 54 | +// Test policy check with different user permissions |
| 55 | +func TestWorkspacePolicyCheckPermissions(t *testing.T) { |
| 56 | + e, _ := StartGQLServerAndRepos(t, baseSeederUser) |
| 57 | + |
| 58 | + // Test with workspace owner |
| 59 | + res := Request(e, uId1.String(), GraphQLRequest{ |
| 60 | + Query: fmt.Sprintf(`query { |
| 61 | + workspacePolicyCheck(input: {workspaceId: "%s"}) { |
| 62 | + workspaceId |
| 63 | + enableToCreatePrivateProject |
| 64 | + } |
| 65 | + }`, wId1), |
| 66 | + }) |
| 67 | + |
| 68 | + res.Path("$.data.workspacePolicyCheck.workspaceId").IsEqual(wId1.String()) |
| 69 | + res.Path("$.data.workspacePolicyCheck.enableToCreatePrivateProject").IsBoolean() |
| 70 | + res.Path("$.data.workspacePolicyCheck.enableToCreatePrivateProject").IsEqual(true) |
| 71 | + |
| 72 | + // Test with different user (should still work if they have access to the workspace) |
| 73 | + res = Request(e, uId2.String(), GraphQLRequest{ |
| 74 | + Query: fmt.Sprintf(`query { |
| 75 | + workspacePolicyCheck(input: {workspaceId: "%s"}) { |
| 76 | + workspaceId |
| 77 | + enableToCreatePrivateProject |
| 78 | + } |
| 79 | + }`, wId1), |
| 80 | + }) |
| 81 | + |
| 82 | + res.Path("$.data.workspacePolicyCheck.workspaceId").IsEqual(wId1.String()) |
| 83 | + res.Path("$.data.workspacePolicyCheck.enableToCreatePrivateProject").IsBoolean() |
| 84 | + res.Path("$.data.workspacePolicyCheck.enableToCreatePrivateProject").IsEqual(true) |
| 85 | +} |
0 commit comments