/api/administrator/administrator-accounts (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.AdministratorAccounts.get(req)Returns array
[
{
"accountid": "acct_00aa51592703886e",
"object": "account",
"appid": "tests_1656038566",
"profileid": "prof_b15a5124e8bc02cf",
"sessionKeyNumber": 1,
"lastSignedInAt": "2022-06-24T02:42:46.000Z",
"administrator": true,
"administratorSince": "2022-06-24T02:42:46.000Z",
"createdAt": "2022-06-24T02:42:46.831Z",
"updatedAt": "2022-06-24T02:42:46.860Z"
},
{
"accountid": "acct_da990c4d1416a467",
"object": "account",
"appid": "tests_1656038566",
"profileid": "prof_531b9dfd445a2629",
"sessionKeyNumber": 1,
"lastSignedInAt": "2022-06-24T02:42:46.000Z",
"administrator": true,
"administratorSince": "2022-06-24T02:42:46.000Z",
"createdAt": "2022-06-24T02:42:46.793Z",
"updatedAt": "2022-06-24T02:42:46.824Z"
},
{
"accountid": "acct_f08115e3e70b3bc2",
"object": "account",
"appid": "tests_1656038566",
"profileid": "prof_f9a88a6a861817a1",
"sessionKeyNumber": 1,
"lastSignedInAt": "2022-06-24T02:42:46.000Z",
"administrator": true,
"administratorSince": "2022-06-24T02:42:46.000Z",
"createdAt": "2022-06-24T02:42:46.755Z",
"updatedAt": "2022-06-24T02:42:46.788Z"
}
]
Receives
API routes may receive parameters from the URL and POST supporting simple and multipart:
Field | Value | Required | Type |
---|---|---|---|
all | boolean | optional | URL |
limit | integer | optional | URL |
offset | integer | optional | URL |
NodeJS source (view on github)
const dashboard = require('../../../../index.js')
const sequelize = require('sequelize')
module.exports = {
/**
* Returns a list of administrators bound to profile information
*/
get: async (req) => {
req.query = req.query || {}
let accountids
if (req.query.all) {
accountids = await dashboard.Storage.Account.findAll({
where: {
administratorSince: {
[sequelize.Op.gt]: 0
},
appid: req.appid || global.appid
},
attributes: ['accountid'],
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
accountids = await dashboard.Storage.Account.findAll({
where: {
administratorSince: {
[sequelize.Op.gt]: 0
},
appid: req.appid || global.appid
},
attributes: ['accountid'],
order: [
['createdAt', 'DESC']
],
offset,
limit
})
}
if (!accountids || !accountids.length) {
return null
}
const accounts = []
for (const accountData of accountids) {
req.query.accountid = accountData.dataValues.accountid
const account = await global.api.administrator.Account.get(req)
accounts.push(account)
}
return accounts
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../test-helper.js')
describe('/api/administrator/administrator-accounts', function () {
const cachedResponses = {}
const cachedAccounts = []
before(async () => {
await TestHelper.setupBeforeEach()
const owner = await TestHelper.createOwner()
cachedAccounts.push(owner.account.accountid)
for (let i = 0, len = global.pageSize + 1; i < len; i++) {
const administrator = await TestHelper.createAdministrator(owner)
cachedAccounts.unshift(administrator.account.accountid)
}
const req1 = TestHelper.createRequest('/api/administrator/administrator-accounts?offset=1')
req1.account = owner.account
req1.session = owner.session
cachedResponses.offset = await req1.get()
const req2 = TestHelper.createRequest('/api/administrator/administrator-accounts?limit=1')
req2.account = owner.account
req2.session = owner.session
cachedResponses.limit = await req2.get()
const req3 = TestHelper.createRequest('/api/administrator/administrator-accounts?all=true')
req3.account = owner.account
req3.session = owner.session
cachedResponses.all = await req3.get()
const req4 = TestHelper.createRequest('/api/administrator/administrator-accounts')
req4.account = owner.account
req4.session = owner.session
req4.filename = __filename
req4.saveResponse = true
cachedResponses.returns = await req4.get()
global.pageSize = 3
cachedResponses.pageSize = await req4.get()
})
describe('receives', () => {
it('optional querystring offset (integer)', async () => {
const offset = 1
const accountsNow = cachedResponses.offset
for (let i = 0, len = global.pageSize; i < len; i++) {
assert.strictEqual(accountsNow[i].accountid, cachedAccounts[offset + i])
}
})
it('optional querystring limit (integer)', async () => {
const limit = 1
const accountsNow = cachedResponses.limit
assert.strictEqual(accountsNow.length, limit)
})
it('optional querystring all (boolean)', async () => {
const accountsNow = cachedResponses.all
assert.strictEqual(accountsNow.length, cachedAccounts.length)
})
})
describe('returns', () => {
it('array', async () => {
const administrators = cachedResponses.returns
assert.strictEqual(administrators.length, global.pageSize)
})
})
describe('redacts', () => {
it('usernameHash', async () => {
const administrators = cachedResponses.returns
assert.strictEqual(undefined, administrators[0].usernameHash)
})
it('passwordHash', async () => {
const administrators = cachedResponses.returns
assert.strictEqual(undefined, administrators[0].passwordHash)
})
it('sessionKey', async () => {
const administrators = cachedResponses.returns
assert.strictEqual(undefined, administrators[0].sessionKey)
})
})
describe('configuration', () => {
it('environment PAGE_SIZE', async () => {
global.pageSize = 3
const administrators = cachedResponses.pageSize
assert.strictEqual(administrators.length, global.pageSize)
})
})
})