增加一次性群邀请链接和二维码
This commit is contained in:
1 parent
dfeb5bfefa
commit
5ec9c81f90
18 files changed
+727
-14
No files matched your search
@@ -154,6 +154,39 @@ test('群组邀请、授权、成员移除、版本变更与实时提示', { tim
|
||||
assert.deepEqual(unrelated, [])
|
||||
})
|
||||
|
||||
test('群邀请链接可轮换、撤销且只能领取一次', { timeout: 25_000 }, async () => {
|
||||
const [owner, first, second] = await Promise.all([register(), register(), register()])
|
||||
const group = await json('/groups', 'POST', owner.token, { name: '群链接验收' }, 201)
|
||||
const path = '/groups/' + group.id
|
||||
const issue = () => json(path + '/invite-link', 'POST', owner.token, undefined, 201)
|
||||
const redeem = (actor, code) => call('/group-invites/redeem', 'POST', actor.token, { code })
|
||||
assert.equal((await call(path + '/invite-link', 'POST', first.token)).status, 404)
|
||||
const initial = await issue()
|
||||
assert.match(initial.code, /^[A-Za-z0-9_-]{43}$/)
|
||||
assert.ok(Date.parse(initial.expiresAt) - Date.now() > 23 * 60 * 60 * 1000)
|
||||
const current = await issue()
|
||||
assert.equal((await redeem(first, initial.code)).status, 404)
|
||||
assert.equal((await redeem(owner, current.code)).status, 409)
|
||||
const results = await Promise.all([redeem(first, current.code), redeem(second, current.code)])
|
||||
assert.deepEqual(results.map((result) => result.status).sort(), [200, 404])
|
||||
const winner = results[0].ok ? first : second
|
||||
const other = results[0].ok ? second : first
|
||||
assert.deepEqual(await results.find((result) => result.ok).json(), { groupId: group.id })
|
||||
const pending = await json(path, 'GET', winner.token)
|
||||
assert.equal(pending.state, 'invited')
|
||||
assert.deepEqual(pending.members, [])
|
||||
assert.equal((await call(path + '/messages', 'GET', winner.token)).status, 404)
|
||||
assert.equal((await call(path, 'POST', winner.token, { action: 'accept' })).status, 204)
|
||||
assert.equal((await json(path, 'GET', winner.token)).membershipVersion, '2')
|
||||
assert.equal((await call(path + '/invite-link', 'POST', winner.token)).status, 409)
|
||||
const revoked = await issue()
|
||||
assert.equal((await call(path + '/invite-link', 'DELETE', owner.token)).status, 204)
|
||||
assert.equal((await redeem(other, revoked.code)).status, 404)
|
||||
const previousOwner = await issue()
|
||||
assert.equal((await call(path, 'POST', owner.token, { action: 'transfer', target: winner.user.id })).status, 204)
|
||||
assert.equal((await redeem(other, previousOwner.code)).status, 404)
|
||||
})
|
||||
|
||||
test('群密文和实时提示只投递到名单设备,移除或撤销阻断旧世代', { timeout: 25_000 }, async (t) => {
|
||||
const enroll = async () => {
|
||||
const keys = generateKeyPairSync('ed25519')
|
||||
|
||||
@@ -482,11 +482,35 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
await owner.getByRole('button', { name: '创建群组' }).click()
|
||||
await owner.getByRole('heading', { name: targetGroup }).waitFor()
|
||||
assert.match(await owner.getByRole('complementary', { name: '群组列表' }).getByRole('link').first().textContent(), /已置顶/)
|
||||
await owner.getByLabel('邀请联系人').selectOption({ label: names[1] })
|
||||
await owner.getByRole('button', { name: '发送邀请' }).click()
|
||||
await windows.getByRole('link', { name: new RegExp(targetGroup) }).click()
|
||||
await owner.getByText('群邀请链接和二维码', { exact: true }).click()
|
||||
await owner.getByRole('button', { name: '生成邀请链接', exact: true }).click()
|
||||
const qr = owner.getByRole('img', { name: '群邀请二维码' })
|
||||
const inviteURL = await owner.getByLabel('邀请链接', { exact: true }).inputValue()
|
||||
assert.match(inviteURL, /#\/groups\?invite=[A-Za-z0-9_-]{43}$/)
|
||||
await owner.waitForFunction(() => {
|
||||
const image = document.querySelector('canvas[aria-label="群邀请二维码"]')
|
||||
return image?.getContext('2d').getImageData(0, 0, 1, 1).data[3] === 255
|
||||
})
|
||||
assert.ok(await qr.evaluate((canvas) => canvas.width > 150))
|
||||
await windows.getByLabel('群邀请链接或邀请码').fill(inviteURL)
|
||||
await windows.getByRole('button', { name: '领取群邀请' }).click()
|
||||
await windows.getByRole('heading', { name: targetGroup }).waitFor()
|
||||
await windows.getByRole('button', { name: '接受邀请' }).click()
|
||||
await owner.getByRole('list', { name: '群成员' }).getByRole('listitem').getByText(names[1] + ' · 成员', { exact: true }).waitFor()
|
||||
|
||||
await owner.getByRole('button', { name: '重新生成邀请链接', exact: true }).click()
|
||||
await owner.waitForFunction((old) => document.querySelector('.invite-output input')?.value !== old, inviteURL)
|
||||
const newURL = await owner.getByLabel('邀请链接', { exact: true }).inputValue()
|
||||
const invitePage = await browser.newPage()
|
||||
await invitePage.goto(newURL)
|
||||
await invitePage.getByRole('heading', { name: '登录 XHChat' }).waitFor()
|
||||
assert.ok(!new URL(invitePage.url()).hash.includes('invite='))
|
||||
await register(invitePage, 'inviteqa_' + id(), password)
|
||||
await invitePage.getByRole('button', { name: '领取群邀请' }).click()
|
||||
await invitePage.getByRole('heading', { name: targetGroup }).waitFor()
|
||||
await invitePage.getByRole('button', { name: '拒绝邀请' }).click()
|
||||
await invitePage.getByRole('heading', { name: targetGroup }).waitFor({ state: 'detached' })
|
||||
await invitePage.close()
|
||||
await windows.getByRole('link', { name: new RegExp(group) }).click()
|
||||
await chat(windows).getByRole('button', { name: '启用本机群聊' }).click()
|
||||
const forwardPanel = chat(windows).getByRole('form', { name: '转发群消息' })
|
||||
@@ -586,7 +610,11 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
await windows.getByRole('link', { name: new RegExp(targetGroup) }).click()
|
||||
const successor = owner.getByRole('list', { name: '群成员' }).getByRole('listitem').filter({ hasText: names[1] })
|
||||
await successor.getByRole('button', { name: '转让群主', exact: true }).click()
|
||||
await owner.getByText(new RegExp('确认将群主转让给 ' + names[1])).waitFor()
|
||||
const transferred = owner.waitForResponse((response) => response.request().method() === 'POST' &&
|
||||
/\/groups\/[^/]+$/.test(response.url()) && response.request().postDataJSON().action === 'transfer')
|
||||
await owner.getByRole('button', { name: '确认操作', exact: true }).click()
|
||||
assert.equal((await transferred).status(), 204)
|
||||
await windows.getByRole('list', { name: '群成员' }).getByText(names[1] + ' · 群主', { exact: true }).waitFor()
|
||||
await owner.getByRole('button', { name: '退出群组', exact: true }).waitFor()
|
||||
await owner.getByRole('button', { name: '退出群组', exact: true }).click()
|
||||
|
||||
Reference in new issue
Block a user