Skip to content

Commit

Permalink
test: invite helper should automatically wait for peers
Browse files Browse the repository at this point in the history
Our `invite` helper breaks if other peers aren't found. There's no time
we'd use `invite` without waiting for other peers to be found, so let's
always wait for them in `invite`.
  • Loading branch information
EvanHahn committed Sep 26, 2024
1 parent dfaceb2 commit 5f0dff7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 55 deletions.
14 changes: 1 addition & 13 deletions test-e2e/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ import {
MEMBER_ROLE_ID,
NO_ROLE,
} from '../src/roles.js'
import {
connectPeers,
createManagers,
invite,
waitForPeers,
waitForSync,
} from './utils.js'
import { connectPeers, createManagers, invite, waitForSync } from './utils.js'
import { kDataTypes } from '../src/mapeo-project.js'

test('getting yourself after creating project', async (t) => {
Expand Down Expand Up @@ -118,7 +112,6 @@ test('getting invited member after invite rejected', async (t) => {
const [invitor, invitee] = managers
const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const projectId = await invitor.createProject({ name: 'Mapeo' })
const project = await invitor.getProject(projectId)
Expand Down Expand Up @@ -149,7 +142,6 @@ test('getting invited member after invite accepted', async (t) => {
const [invitor, invitee] = managers
const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const { name: inviteeName } = invitee.getDeviceInfo()
const projectId = await invitor.createProject({ name: 'Mapeo' })
Expand Down Expand Up @@ -197,7 +189,6 @@ test('invite uses custom role name when provided', async (t) => {
const [invitor, invitee] = managers
const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const projectId = await invitor.createProject({ name: 'Mapeo' })

Expand All @@ -220,7 +211,6 @@ test('invite uses default role name when not provided', async (t) => {
const [invitor, invitee] = managers
const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const projectId = await invitor.createProject({ name: 'Mapeo' })

Expand Down Expand Up @@ -363,7 +353,6 @@ test('roles - assignRole()', async (t) => {
const [invitor, invitee] = managers
const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const projectId = await invitor.createProject({ name: 'Mapeo' })

Expand Down Expand Up @@ -470,7 +459,6 @@ test('roles - assignRole() with forked role', async (t) => {
const managers = await createManagers(3, t)
const [invitor, invitee1, invitee2] = managers
let disconnectPeers = connectPeers(managers)
await waitForPeers(managers)

const projectId = await invitor.createProject({ name: 'Mapeo' })

Expand Down
9 changes: 1 addition & 8 deletions test-e2e/original_version_id_to_device_id.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ import { generate } from '@mapeo/mock-data'
import { valueOf } from '@comapeo/schema'
import assert from 'node:assert/strict'
import test from 'node:test'
import {
connectPeers,
createManagers,
invite,
waitForPeers,
waitForSync,
} from './utils.js'
import { connectPeers, createManagers, invite, waitForSync } from './utils.js'

test('$originalVersionIdToDeviceId', async (t) => {
const managers = await createManagers(2, t)

const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const [creator, member] = managers
const projectId = await creator.createProject({ name: 'mapeo' })
Expand Down
7 changes: 0 additions & 7 deletions test-e2e/project-leave.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ test("Creator cannot leave project if they're the only coordinator", async (t) =

const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const [creator, member] = managers
const projectId = await creator.createProject({ name: 'mapeo' })
Expand Down Expand Up @@ -67,7 +66,6 @@ test('Blocked member cannot leave project', async (t) => {

const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const [creator, member] = managers
const projectId = await creator.createProject({ name: 'mapeo' })
Expand Down Expand Up @@ -126,7 +124,6 @@ test('Creator can leave project if another coordinator exists', async (t) => {

const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const [creator, coordinator] = managers
const projectId = await creator.createProject({ name: 'mapeo' })
Expand Down Expand Up @@ -178,7 +175,6 @@ test('Member can leave project if creator exists', async (t) => {

const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const [creator, member] = managers
const projectId = await creator.createProject({ name: 'mapeo' })
Expand Down Expand Up @@ -320,7 +316,6 @@ test('leaving a project deletes data from disk', async (t) => {

const disconnectPeers = connectPeers(managers)
t.after(disconnectPeers)
await waitForPeers(managers)

const projectId = await creator.createProject({ name: 'mapeo' })

Expand Down Expand Up @@ -368,8 +363,6 @@ test('leaving a project while disconnected', async (t) => {
let disconnectPeers = connectPeers(managers)
t.after(() => disconnectPeers())

await waitForPeers(managers)

const [creator, member] = managers
const projectId = await creator.createProject({ name: 'mapeo' })

Expand Down
52 changes: 25 additions & 27 deletions test-e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,31 @@ export async function invite({
}) {
const invitorProject = await invitor.getProject(projectId)

/** @type {Array<Promise<unknown>>} */
const promises = []

for (const invitee of invitees) {
const inviteId = randomBytes(32)
promises.push(
invitorProject.$member.invite(invitee.deviceId, {
roleId,
roleName,
__testOnlyInviteId: inviteId,
})
)
promises.push(
(async () => {
const invite = await pEvent(
invitee.invite,
'invite-received',
(invite) => Buffer.from(invite.inviteId, 'hex').equals(inviteId)
)
await (reject
? invitee.invite.reject(invite)
: invitee.invite.accept(invite))
})()
)
}

await Promise.allSettled(promises)
await Promise.allSettled(
invitees.map(async (invitee) => {
const inviteId = randomBytes(32)

await waitForPeers([invitor, invitee])

await Promise.all([
(async () => {
const invite = await pEvent(
invitee.invite,
'invite-received',
(invite) => Buffer.from(invite.inviteId, 'hex').equals(inviteId)
)
await (reject
? invitee.invite.reject(invite)
: invitee.invite.accept(invite))
})(),
invitorProject.$member.invite(invitee.deviceId, {
roleId,
roleName,
__testOnlyInviteId: inviteId,
}),
])
})
)
}

/**
Expand Down

0 comments on commit 5f0dff7

Please sign in to comment.