diff --git a/src/models/organization-invite.ts b/src/models/organization-invite.ts index 2e3984d22..81dbfeac8 100644 --- a/src/models/organization-invite.ts +++ b/src/models/organization-invite.ts @@ -167,7 +167,7 @@ const getOrganizationInviteModel = function ( message, }; if (roles) { - const [{ id: roleId }] = roles; + const roleId = roles[0]?.id; // Throw if the user provided a roleName, but we didn't find that role if (!roleId && roleName) { throw new errors.BalenaOrganizationMembershipRoleNotFound(roleName); diff --git a/tests/integration/models/organizationInvite.spec.ts b/tests/integration/models/organizationInvite.spec.ts index c6d88b6a4..331c3d3aa 100644 --- a/tests/integration/models/organizationInvite.spec.ts +++ b/tests/integration/models/organizationInvite.spec.ts @@ -107,8 +107,10 @@ describe('Organization Invite Model', function () { }, ); await expect(promise).to.be.rejected.then((error) => { - expect(error).to.have.property('code', 'BalenaRequestError'); - expect(error).to.have.property('statusCode', 404); + expect(error).to.have.property( + 'code', + 'BalenaOrganizationMembershipRoleNotFound', + ); expect(error) .to.have.property('message') .that.contains(