/api/user/organizations/invitation-memberships (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.user.organizations.InvitationMemberships.get(req)Returns array
[
{
"membershipid": "mmbr_57ebeff65de33641",
"object": "membership",
"appid": "tests_1656039706",
"accountid": "acct_c4a342610224f9d1",
"organizationid": "orgn_2116cfb9f3a1b72d",
"invitationid": null,
"profileid": "prof_a59be710e8084ca2",
"createdAt": "2022-06-24T03:01:46.261Z",
"updatedAt": "2022-06-24T03:01:46.261Z"
},
{
"membershipid": "mmbr_57ebeff65de33641",
"object": "membership",
"appid": "tests_1656039706",
"accountid": "acct_c4a342610224f9d1",
"organizationid": "orgn_2116cfb9f3a1b72d",
"invitationid": null,
"profileid": "prof_a59be710e8084ca2",
"createdAt": "2022-06-24T03:01:46.261Z",
"updatedAt": "2022-06-24T03:01:46.261Z"
},
{
"membershipid": "mmbr_57ebeff65de33641",
"object": "membership",
"appid": "tests_1656039706",
"accountid": "acct_c4a342610224f9d1",
"organizationid": "orgn_2116cfb9f3a1b72d",
"invitationid": null,
"profileid": "prof_a59be710e8084ca2",
"createdAt": "2022-06-24T03:01:46.261Z",
"updatedAt": "2022-06-24T03:01:46.261Z"
}
]
Exceptions
These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:
Exception | Circumstances |
---|---|
invalid-account | ineligible accessing account |
invalid-invitationid | missing querystring invitationid |
invalid querystring invitationid |
NodeJS source (view on github)
const organizations = require('../../../../../index.js')
module.exports = {
get: async (req) => {
const invitation = await global.api.user.organizations.Invitation.get(req)
if (!invitation) {
throw new Error('invalid-invitationid')
}
req.query.organizationid = invitation.organizationid
const organization = await global.api.user.organizations.Organization.get(req)
if (!organization) {
throw new Error('invalid-invitationid')
}
if (organization.ownerid !== req.account.accountid) {
throw new Error('invalid-account')
}
let membershipids
if (req.query.all) {
membershipids = await organizations.Storage.Membership.findAll({
where: {
invitationid: req.query.invitationid,
appid: req.appid || global.appid
},
attributes: ['membershipid'],
order: [
['createdAt', 'DESC']
]
})
} else {
const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
membershipids = await organizations.Storage.Membership.findAll({
where: {
invitationid: req.query.invitationid,
appid: req.appid || global.appid
},
attributes: ['membershipid'],
offset,
limit,
order: [
['createdAt', 'DESC']
]
})
}
if (!membershipids || !membershipids.length) {
return null
}
const items = []
for (const membershipInfo of membershipids) {
req.query.membershipid = membershipInfo.dataValues.membershipid
const membership = await global.api.user.organizations.OrganizationMembership.get(req)
items.push(membership)
}
return items
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
describe('/api/user/organizations/invitation-memberships', () => {
describe('exceptions', () => {
describe('invalid-invitationid', () => {
it('missing querystring invitationid', async () => {
const owner = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/user/organizations/invitation-memberships')
req.account = owner.account
req.session = owner.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-invitationid')
})
it('invalid querystring invitationid', async () => {
const owner = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/user/organizations/invitation-memberships?invitationid=invalid')
req.account = owner.account
req.session = owner.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-invitationid')
})
})
describe('invalid-account', () => {
it('ineligible accessing account', async () => {
const owner = await TestHelper.createUser()
const user = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(owner, {
'display-name': owner.profile.fullName,
'display-email': owner.profile.contactEmail
})
await TestHelper.createProfile(user, {
'display-name': user.profile.fullName,
'display-email': user.profile.contactEmail
})
await TestHelper.createOrganization(owner, {
email: owner.profile.displayEmail,
name: 'My organization',
profileid: owner.profile.profileid,
pin: '12345'
})
await TestHelper.createInvitation(owner)
await TestHelper.acceptInvitation(user, owner)
const req = TestHelper.createRequest(`/api/user/organizations/invitation-memberships?invitationid=${owner.invitation.invitationid}`)
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-account')
})
})
})
describe('returns', () => {
it('array', async () => {
const owner = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(owner, {
'display-name': owner.profile.fullName,
'display-email': owner.profile.contactEmail
})
await TestHelper.createOrganization(owner, {
email: owner.profile.displayEmail,
name: 'My organization',
profileid: owner.profile.profileid,
pin: '12345'
})
await TestHelper.createInvitation(owner)
for (let i = 0, len = global.pageSize + 1; i < len; i++) {
const user = await TestHelper.createUser()
await TestHelper.createProfile(user, {
'display-name': user.profile.fullName,
'display-email': user.profile.contactEmail
})
await TestHelper.acceptInvitation(user, owner)
}
const req = TestHelper.createRequest(`/api/user/organizations/invitation-memberships?invitationid=${owner.invitation.invitationid}`)
req.account = owner.account
req.session = owner.session
req.filename = __filename
req.saveResponse = true
const result = await req.get()
assert.strictEqual(result.length, global.pageSize)
})
})
describe('configuration', () => {
it('environment PAGE_SIZE', async () => {
global.pageSize = 3
const owner = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(owner, {
'display-name': owner.profile.fullName,
'display-email': owner.profile.contactEmail
})
await TestHelper.createOrganization(owner, {
email: owner.profile.displayEmail,
name: 'My organization',
profileid: owner.profile.profileid,
pin: '12345'
})
await TestHelper.createInvitation(owner)
for (let i = 0, len = global.pageSize + 1; i < len; i++) {
const user = await TestHelper.createUser()
await TestHelper.createProfile(user, {
'display-name': user.profile.fullName,
'display-email': user.profile.contactEmail
})
await TestHelper.acceptInvitation(user, owner)
}
const req = TestHelper.createRequest(`/api/user/organizations/invitation-memberships?invitationid=${owner.invitation.invitationid}`)
req.account = owner.account
req.session = owner.session
req.filename = __filename
req.saveResponse = true
const result = await req.get()
assert.strictEqual(result.length, global.pageSize)
})
})
})