Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

test(server): update page default role with non-exists workspace (#10012)

Brooooooklyn9262cb120cc9
diff --git a/packages/backend/server/src/__tests__/team.e2e.ts b/packages/backend/server/src/__tests__/team.e2e.ts
index 482fdaf0ef..05297694c1 100644
--- a/packages/backend/server/src/__tests__/team.e2e.ts
+++ b/packages/backend/server/src/__tests__/team.e2e.ts
@@ -1025,3 +1025,33 @@ test('should be able to grant and revoke doc user role', async t => {
});
}
});
+
+test('update page default role should throw error if the space does not exist', async t => {
+ const { app } = t.context;
+ const { admin } = await init(app, 5);
+ const pageId = nanoid();
+ const nonExistWorkspaceId = 'non-exist-workspace';
+ const res = await request(app.getHttpServer())
+ .post('/graphql')
+ .auth(admin.token.token, { type: 'bearer' })
+ .set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
+ .send({
+ query: `
+ mutation {
+ updatePageDefaultRole(input: {
+ workspaceId: "${nonExistWorkspaceId}",
+ docId: "${pageId}",
+ role: Manager,
+ })
+ }
+ `,
+ })
+ .expect(200);
+ t.like(res.body, {
+ errors: [
+ {
+ message: `You do not have permission to access doc ${pageId} under Space ${nonExistWorkspaceId}.`,
+ },
+ ],
+ });
+});
diff --git a/packages/backend/server/src/base/error/def.ts b/packages/backend/server/src/base/error/def.ts
index a00b2cef5d..8c17bd8bab 100644
--- a/packages/backend/server/src/base/error/def.ts
+++ b/packages/backend/server/src/base/error/def.ts
@@ -352,7 +352,7 @@ export const USER_FRIENDLY_ERRORS = {
// Workspace & Userspace & Doc & Sync errors
workspace_permission_not_found: {
- type: 'internal_server_error',
+ type: 'resource_not_found',
args: { spaceId: 'string' },
message: ({ spaceId }) => `Space ${spaceId} permission not found.`,
},
diff --git a/packages/backend/server/src/base/error/errors.gen.ts b/packages/backend/server/src/base/error/errors.gen.ts
index 4dd76c8d78..56848ebe80 100644
--- a/packages/backend/server/src/base/error/errors.gen.ts
+++ b/packages/backend/server/src/base/error/errors.gen.ts
@@ -197,7 +197,7 @@ class WorkspacePermissionNotFoundDataType {
export class WorkspacePermissionNotFound extends UserFriendlyError {
constructor(args: WorkspacePermissionNotFoundDataType, message?: string | ((args: WorkspacePermissionNotFoundDataType) => string)) {
- super('internal_server_error', 'workspace_permission_not_found', message, args);
+ super('resource_not_found', 'workspace_permission_not_found', message, args);
}
}
@ObjectType()