/api/user/organizations/open-invitation-organization (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.user.organizations.OpenInvitationOrganization.get(req)Returns object
{
"organizationid": "orgn_77f1669c1f3909fb",
"object": "organization",
"appid": "tests_1656039710",
"ownerid": "acct_a353d5dbfd79e596",
"name": "My organization",
"pin": "12345",
"email": "Estelle.Spinka61@yahoo.com",
"createdAt": "2022-06-24T03:01:50.507Z",
"updatedAt": "2022-06-24T03:01:50.507Z"
}
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-invitation | querystring invitationid is used |
invalid-invitationid | missing querystring invitationid |
invalid querystring invitationid |
NodeJS source (view on github)
const dashboard = require('@layeredapps/dashboard')
const organizations = require('../../../../../index.js')
module.exports = {
get: async (req) => {
if (!req.query || !req.query.invitationid) {
throw new Error('invalid-invitationid')
}
const invitation = await global.api.user.organizations.OpenInvitation.get(req)
let organization = await dashboard.StorageCache.get(invitation.organizationid)
if (!organization) {
const organizationInfo = await organizations.Storage.Organization.findOne({
where: {
organizationid: invitation.organizationid,
appid: req.appid || global.appid
}
})
if (!organizationInfo) {
throw new Error('invalid-organizationid')
}
organization = {}
for (const field of organizationInfo._options.attributes) {
organization[field] = organizationInfo.get(field)
}
await dashboard.StorageCache.set(invitation.organizationid, organization)
}
return organization
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
describe('/api/user/organizations/open-invitation-organization', () => {
describe('exceptions', () => {
describe('invalid-invitationid', () => {
it('missing querystring invitationid', async () => {
const owner = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/user/organizations/open-invitation-organization')
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/open-invitation-organization?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-invitation', () => {
it('querystring invitationid is used', 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, {
lifespan: 'single'
})
await TestHelper.acceptInvitation(user, owner)
const req = TestHelper.createRequest(`/api/user/organizations/open-invitation-organization?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-invitation')
})
})
})
describe('returns', () => {
it('object', 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)
const req = TestHelper.createRequest(`/api/user/organizations/open-invitation-organization?invitationid=${owner.invitation.invitationid}`)
req.account = owner.account
req.session = owner.session
req.filename = __filename
req.saveResponse = true
const organization = await req.get()
assert.strictEqual(organization.object, 'organization')
})
})
})