Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return project public ID when accepting invite #577

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/invite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class InviteApi extends TypedEmitter {
* part of this project.
*
* @param {Pick<Invite, 'inviteId'>} invite
* @returns {Promise<void>}
* @returns {Promise<string>}
*/
async accept({ inviteId: inviteIdString }) {
const inviteId = Buffer.from(inviteIdString, 'hex')
Expand Down Expand Up @@ -301,7 +301,7 @@ export class InviteApi extends TypedEmitter {
'accepted'
)
}
return
return projectPublicId
}

assert(
Expand Down Expand Up @@ -373,6 +373,8 @@ export class InviteApi extends TypedEmitter {
}

this.emit('invite-removed', internalToExternal(invite), 'accepted')

return projectPublicId
}

/**
Expand Down
6 changes: 4 additions & 2 deletions test-e2e/manager-invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ test('member invite accepted', async (t) => {
)
t.is(invite.projectName, 'Mapeo', 'project name of invite matches')

await joiner.invite.accept(invite)
const acceptResult = await joiner.invite.accept(invite)

t.is(
await responsePromise,
InviteResponse_Decision.ACCEPT,
'correct invite response'
)
t.is(acceptResult, createdProjectId, 'accept returns invite ID')

/// After invite flow has completed...

Expand Down Expand Up @@ -84,7 +85,8 @@ test('chain of invites', async (t) => {
roleId: COORDINATOR_ROLE_ID,
})
const [invite] = await once(joiner.invite, 'invite-received')
await joiner.invite.accept(invite)
const acceptResult = await joiner.invite.accept(invite)
t.is(acceptResult, createdProjectId, 'accept returns invite ID')
t.is(
await responsePromise,
InviteResponse_Decision.ACCEPT,
Expand Down
8 changes: 5 additions & 3 deletions test-e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export async function invite({
reject = false,
}) {
const invitorProject = await invitor.getProject(projectId)

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

for (const invitee of invitees) {
Expand All @@ -109,10 +111,10 @@ export async function invite({
})
)
promises.push(
once(invitee.invite, 'invite-received').then(([invite]) => {
return reject
once(invitee.invite, 'invite-received').then(async ([invite]) => {
await (reject
? invitee.invite.reject(invite)
: invitee.invite.accept(invite)
: invitee.invite.accept(invite))
})
)
}
Expand Down
23 changes: 17 additions & 6 deletions tests/invite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ test('Accept invite', async (t) => {
invite,
inviteExternal,
projectKey,
projectPublicId,
encryptionKeys,
} = setup()

Expand Down Expand Up @@ -185,8 +186,9 @@ test('Accept invite', async (t) => {

// Invitee: accept

await inviteApi.accept(inviteExternal)
const acceptResult = await inviteApi.accept(inviteExternal)

t.is(acceptResult, projectPublicId, 'accept returns project public ID')
t.ok(
projectKeysFound.some((k) => k.equals(projectKey)),
'added to project'
Expand Down Expand Up @@ -584,7 +586,7 @@ test('trying to accept or reject non-existent invite throws', async (t) => {
t.fail('should not emit an "removed" event')
})

await t.exception(inviteApi.accept(inviteExternal))
await t.exception(() => inviteApi.accept(inviteExternal))
t.exception(() => inviteApi.reject(inviteExternal))

assertInvitesAlike(t, inviteApi.getPending(), [], 'has no pending invites')
Expand Down Expand Up @@ -645,7 +647,10 @@ test('throws when quickly double-accepting the same invite', async (t) => {

const firstAcceptPromise = inviteApi.accept(inviteExternal)

await t.exception(inviteApi.accept(inviteExternal), 'second accept fails')
await t.exception(
() => inviteApi.accept(inviteExternal),
'second accept fails'
)

await firstAcceptPromise
t.ok(
Expand Down Expand Up @@ -765,7 +770,10 @@ test('throws when quickly accepting two invites for the same project', async (t)

const firstAcceptPromise = inviteApi.accept(invite1External)

await t.exception(inviteApi.accept(invite2External), 'second accept fails')
await t.exception(
() => inviteApi.accept(invite2External),
'second accept fails'
)

await firstAcceptPromise
t.ok(
Expand Down Expand Up @@ -983,7 +991,7 @@ test('failures to send acceptances cause accept to reject, no project to be adde
'has a pending invite'
)

await t.exception(inviteApi.accept(inviteExternal), 'fails to accept')
await t.exception(() => inviteApi.accept(inviteExternal), 'fails to accept')

t.is(acceptsAttempted, 1)
const [removedInvite, removalReason] = await inviteRemovedPromise
Expand Down Expand Up @@ -1086,7 +1094,10 @@ test('failures to add project cause accept() to reject and invite to be removed'

const inviteRemovedPromise = once(inviteApi, 'invite-removed')

await t.exception(inviteApi.accept(inviteExternal), 'accept should fail')
await t.exception(
() => inviteApi.accept(inviteExternal),
'accept should fail'
)

const [removedInvite, removalReason] = await inviteRemovedPromise
assertInvitesAlike(t, removedInvite, inviteExternal, 'invite was removed')
Expand Down
Loading