/api/administrator/organizations/memberships-count (GET)
await global.api.administrator.organizations.MembershipsCount.get(req) Located in Organizations module API
Returns integer
Exceptions
These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:
Exception | Circumstances |
---|
NodeJS source (edit on github)
If you see a problem with the source submit a pull request on Github.
const organizations = require('../../../../../index.js')
module.exports = {
get: async (req) => {
let index
if (req.query) {
if (req.query.accountid) {
index = `${req.appid}/account/memberships/${req.query.accountid}`
} else if (req.query.organizationid) {
index = `${req.appid}/organization/memberships/${req.query.organizationid}`
}
}
index = index || `${req.appid}/memberships`
return organizations.StorageList.count(index)
}
}
Test source (edit on github)
Tests perform real HTTP requests against a running Dashboard server.
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
describe('/api/administrator/organizations/memberships-count', () => {
describe('returns', () => {
it('integer', async () => {
const administrator = await TestHelper.createOwner()
const owner = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(owner, {
'display-name': owner.profile.firstName,
'display-email': owner.profile.contactEmail
})
await TestHelper.createOrganization(owner, {
email: owner.profile.displayEmail,
name: 'My organization',
profileid: owner.profile.profileid
})
global.userProfileFields = ['full-name', 'contact-email']
const user1 = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(user1, {
'display-name': user1.profile.firstName,
'display-email': user1.profile.contactEmail
})
await await TestHelper.createInvitation(owner)
await TestHelper.acceptInvitation(user1, owner)
global.userProfileFields = ['full-name', 'contact-email']
const owner2 = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(owner2, {
'display-name': owner2.profile.firstName,
'display-email': owner2.profile.contactEmail
})
await TestHelper.createOrganization(owner2, {
email: owner2.profile.displayEmail,
name: 'My organization',
profileid: owner2.profile.profileid
})
global.userProfileFields = ['contact-email', 'full-name']
const user2 = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(user2, {
'display-name': user2.profile.firstName,
'display-email': user2.profile.contactEmail
})
await await TestHelper.createInvitation(owner2)
await TestHelper.acceptInvitation(user2, owner2)
global.userProfileFields = ['contact-email', 'full-name']
const user3 = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(user3, {
'display-name': user3.profile.firstName,
'display-email': user3.profile.contactEmail
})
await await TestHelper.createInvitation(owner2)
await TestHelper.acceptInvitation(user3, owner2)
const req = TestHelper.createRequest('/api/administrator/organizations/memberships-count')
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const result = await req.get()
assert.strictEqual(result, 5)
})
})
})