mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
@@ -7,6 +7,7 @@ import ava from 'ava';
|
||||
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { AuthService } from '../src/core/auth';
|
||||
import { DocContentService } from '../src/core/doc-renderer';
|
||||
import { Permission, PermissionService } from '../src/core/permission';
|
||||
import {
|
||||
QuotaManagementService,
|
||||
@@ -15,11 +16,11 @@ import {
|
||||
} from '../src/core/quota';
|
||||
import {
|
||||
acceptInviteById,
|
||||
createInviteLink,
|
||||
createTestingApp,
|
||||
createWorkspace,
|
||||
getInviteInfo,
|
||||
grantMember,
|
||||
inviteLink,
|
||||
inviteUser,
|
||||
inviteUsers,
|
||||
leaveWorkspace,
|
||||
@@ -40,6 +41,16 @@ const test = ava as TestFn<{
|
||||
test.beforeEach(async t => {
|
||||
const { app } = await createTestingApp({
|
||||
imports: [AppModule],
|
||||
tapModule: module => {
|
||||
module.overrideProvider(DocContentService).useValue({
|
||||
getWorkspaceContent() {
|
||||
return {
|
||||
name: 'test',
|
||||
avatarKey: null,
|
||||
};
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const quota = app.get(QuotaService);
|
||||
@@ -94,8 +105,14 @@ const init = async (app: INestApplication, memberLimit = 10) => {
|
||||
return [members, invites] as const;
|
||||
};
|
||||
|
||||
const createInviteLink = async () => {
|
||||
const inviteId = await inviteLink(app, owner.token.token, ws.id, 'OneDay');
|
||||
const getCreateInviteLinkFetcher = async () => {
|
||||
const { link } = await createInviteLink(
|
||||
app,
|
||||
owner.token.token,
|
||||
ws.id,
|
||||
'OneDay'
|
||||
);
|
||||
const inviteId = link.split('/').pop()!;
|
||||
return [
|
||||
inviteId,
|
||||
async (email: string): Promise<UserAuthedType> => {
|
||||
@@ -113,7 +130,7 @@ const init = async (app: INestApplication, memberLimit = 10) => {
|
||||
return {
|
||||
invite,
|
||||
inviteBatch,
|
||||
createInviteLink,
|
||||
createInviteLink: getCreateInviteLinkFetcher,
|
||||
owner,
|
||||
ws,
|
||||
admin,
|
||||
@@ -169,7 +186,7 @@ test('should be able to check seat limit', async t => {
|
||||
ws.id,
|
||||
(await members1)[0][0].id
|
||||
),
|
||||
WorkspaceMemberStatus.Accepted,
|
||||
WorkspaceMemberStatus.Pending,
|
||||
'should become accepted after refresh'
|
||||
);
|
||||
t.is(
|
||||
@@ -239,8 +256,7 @@ test('should be able to leave workspace', async t => {
|
||||
);
|
||||
});
|
||||
|
||||
// enabled in next PR
|
||||
test.skip('should be able to invite by link', async t => {
|
||||
test('should be able to invite by link', async t => {
|
||||
const { app, permissions, quotaManager } = t.context;
|
||||
const { createInviteLink, owner, ws } = await init(app, 4);
|
||||
const [inviteId, invite] = await createInviteLink();
|
||||
|
||||
@@ -65,12 +65,12 @@ export async function inviteUsers(
|
||||
return res.body.data.inviteBatch;
|
||||
}
|
||||
|
||||
export async function inviteLink(
|
||||
export async function createInviteLink(
|
||||
app: INestApplication,
|
||||
token: string,
|
||||
workspaceId: string,
|
||||
expireTime: 'OneDay' | 'ThreeDays' | 'OneWeek' | 'OneMonth'
|
||||
): Promise<string> {
|
||||
): Promise<{ link: string; expireTime: string }> {
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(gql)
|
||||
.auth(token, { type: 'bearer' })
|
||||
@@ -78,7 +78,10 @@ export async function inviteLink(
|
||||
.send({
|
||||
query: `
|
||||
mutation {
|
||||
createInviteLink(workspaceId: "${workspaceId}", expireTime: ${expireTime})
|
||||
createInviteLink(workspaceId: "${workspaceId}", expireTime: ${expireTime}) {
|
||||
link
|
||||
expireTime
|
||||
}
|
||||
}
|
||||
`,
|
||||
})
|
||||
@@ -109,7 +112,10 @@ export async function acceptInviteById(
|
||||
})
|
||||
.expect(200);
|
||||
if (res.body.errors) {
|
||||
throw new Error(res.body.errors[0].message);
|
||||
console.error(res.body.errors);
|
||||
throw new Error(res.body.errors[0].message, {
|
||||
cause: res.body.errors[0].cause,
|
||||
});
|
||||
}
|
||||
return res.body.data.acceptInviteById;
|
||||
}
|
||||
@@ -127,7 +133,7 @@ export async function leaveWorkspace(
|
||||
.send({
|
||||
query: `
|
||||
mutation {
|
||||
leaveWorkspace(workspaceId: "${workspaceId}", workspaceName: "test workspace", sendLeaveMail: ${sendLeaveMail})
|
||||
leaveWorkspace(workspaceId: "${workspaceId}", sendLeaveMail: ${sendLeaveMail})
|
||||
}
|
||||
`,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user