feat(server): improve team invite (#9092)

This commit is contained in:
DarkSky
2024-12-11 18:00:49 +08:00
committed by GitHub
parent 671c41cb1a
commit 9b0f1bb293
14 changed files with 146 additions and 46 deletions
+18 -7
View File
@@ -17,6 +17,7 @@ import {
acceptInviteById,
createTestingApp,
createWorkspace,
getInviteInfo,
grantMember,
inviteLink,
inviteUser,
@@ -95,11 +96,14 @@ const init = async (app: INestApplication, memberLimit = 10) => {
const createInviteLink = async () => {
const inviteId = await inviteLink(app, owner.token.token, ws.id, 'OneDay');
return async (email: string): Promise<UserAuthedType> => {
const member = await signUp(app, email.split('@')[0], email, '123456');
await acceptInviteById(app, ws.id, inviteId, false, member.token.token);
return member;
};
return [
inviteId,
async (email: string): Promise<UserAuthedType> => {
const member = await signUp(app, email.split('@')[0], email, '123456');
await acceptInviteById(app, ws.id, inviteId, false, member.token.token);
return member;
},
] as const;
};
const admin = await invite('admin@affine.pro', 'Admin');
@@ -237,8 +241,15 @@ test('should be able to leave workspace', async t => {
test('should be able to invite by link', async t => {
const { app, permissions, quotaManager } = t.context;
const { createInviteLink, ws } = await init(app, 4);
const invite = await createInviteLink();
const { createInviteLink, owner, ws } = await init(app, 4);
const [inviteId, invite] = await createInviteLink();
{
// check invite link
const info = await getInviteInfo(app, owner.token.token, inviteId);
t.is(info.workspace.id, ws.id, 'should be able to get invite info');
}
{
// invite link
const members: UserAuthedType[] = [];
@@ -78,7 +78,7 @@ export async function inviteLink(
.send({
query: `
mutation {
inviteLink(workspaceId: "${workspaceId}", expireTime: ${expireTime})
createInviteLink(workspaceId: "${workspaceId}", expireTime: ${expireTime})
}
`,
})
@@ -86,7 +86,7 @@ export async function inviteLink(
if (res.body.errors) {
throw new Error(res.body.errors[0].message);
}
return res.body.data.inviteLink;
return res.body.data.createInviteLink;
}
export async function acceptInviteById(
@@ -187,5 +187,10 @@ export async function getInviteInfo(
`,
})
.expect(200);
if (res.body.errors) {
throw new Error(res.body.errors[0].message, {
cause: res.body.errors[0].cause,
});
}
return res.body.data.getInviteInfo;
}