test(server): grant doc user roles (#10016)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export * from './blobs';
|
||||
export * from './invite';
|
||||
export * from './permission';
|
||||
export * from './user';
|
||||
export * from './utils';
|
||||
export * from './workspace';
|
||||
|
||||
114
packages/backend/server/src/__tests__/utils/permission.ts
Normal file
114
packages/backend/server/src/__tests__/utils/permission.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import request from 'supertest';
|
||||
|
||||
import { DocRole } from '../../core/permission/types';
|
||||
import { gql } from './common';
|
||||
|
||||
export function grantDocUserRoles(
|
||||
app: INestApplication,
|
||||
token: string,
|
||||
workspaceId: string,
|
||||
docId: string,
|
||||
userIds: string[],
|
||||
role: DocRole
|
||||
) {
|
||||
return request(app.getHttpServer())
|
||||
.post(gql)
|
||||
.auth(token, { type: 'bearer' })
|
||||
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
||||
.send({
|
||||
query: `
|
||||
mutation {
|
||||
grantDocUserRoles(input: {
|
||||
workspaceId: "${workspaceId}",
|
||||
docId: "${docId}",
|
||||
userIds: ["${userIds.join('","')}"],
|
||||
role: ${DocRole[role]}
|
||||
})
|
||||
}
|
||||
`,
|
||||
});
|
||||
}
|
||||
|
||||
export function revokeDocUserRoles(
|
||||
app: INestApplication,
|
||||
token: string,
|
||||
workspaceId: string,
|
||||
docId: string,
|
||||
userId: string
|
||||
) {
|
||||
return request(app.getHttpServer())
|
||||
.post(gql)
|
||||
.auth(token, { type: 'bearer' })
|
||||
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
||||
.send({
|
||||
query: `
|
||||
mutation {
|
||||
revokeDocUserRoles(input: {
|
||||
workspaceId: "${workspaceId}",
|
||||
docId: "${docId}",
|
||||
userId: "${userId}"
|
||||
})
|
||||
}
|
||||
`,
|
||||
});
|
||||
}
|
||||
|
||||
export function updatePageDefaultRole(
|
||||
app: INestApplication,
|
||||
token: string,
|
||||
workspaceId: string,
|
||||
docId: string,
|
||||
role: DocRole
|
||||
) {
|
||||
return request(app.getHttpServer())
|
||||
.post(gql)
|
||||
.auth(token, { type: 'bearer' })
|
||||
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
||||
.send({
|
||||
query: `
|
||||
mutation {
|
||||
updatePageDefaultRole(input: {
|
||||
workspaceId: "${workspaceId}",
|
||||
docId: "${docId}",
|
||||
role: ${DocRole[role]}
|
||||
})
|
||||
}
|
||||
`,
|
||||
});
|
||||
}
|
||||
|
||||
export async function pageGrantedUsersList(
|
||||
app: INestApplication,
|
||||
token: string,
|
||||
workspaceId: string,
|
||||
docId: string,
|
||||
first = 10,
|
||||
offset = 0
|
||||
) {
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(gql)
|
||||
.auth(token, { type: 'bearer' })
|
||||
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
||||
.send({
|
||||
query: `
|
||||
query {
|
||||
workspace(id: "${workspaceId}") {
|
||||
pageGrantedUsersList(pageId: "${docId}", pagination: { first: ${first}, offset: ${offset} }) {
|
||||
totalCount
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
role
|
||||
user {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
});
|
||||
return res.body;
|
||||
}
|
||||
Reference in New Issue
Block a user