Skip to content

Commit

Permalink
update test to check for invite response
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 committed Aug 31, 2023
1 parent 471a2af commit d2e387c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { KeyManager } from '@mapeo/crypto'

import { MapeoRPC } from '../src/rpc/index.js'
import { MemberApi } from '../src/member-api.js'
import { InviteResponse_Decision } from '../src/generated/rpc.js'
import { replicate } from './helpers/rpc.js'

test('Invite sends expected project-related details', async (t) => {
t.plan(3)
t.plan(4)

const projectKey = KeyManager.generateProjectKeypair().publicKey
const encryptionKeys = { auth: randomBytes(32) }
Expand All @@ -23,16 +24,23 @@ test('Invite sends expected project-related details', async (t) => {
rpc: r1,
})

r1.on('peers', (peers) => {
memberApi.invite(peers[0].id, {
r1.on('peers', async (peers) => {
const response = await memberApi.invite(peers[0].id, {
role: 'member',
})

t.is(response, InviteResponse_Decision.ACCEPT)
})

r2.on('invite', async (_peerId, invite) => {
r2.on('invite', async (peerId, invite) => {
t.alike(invite.projectKey, projectKey)
t.alike(invite.encryptionKeys, encryptionKeys)
t.alike(invite.projectInfo, projectInfo)

r2.inviteResponse(peerId, {
projectKey: invite.projectKey,
decision: InviteResponse_Decision.ACCEPT,
})
})

replicate(r1, r2)
Expand Down

0 comments on commit d2e387c

Please sign in to comment.