/api/administrator/profiles (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.Profiles.get(req)Returns array
[
{
"profileid": "prof_c1a41d580ea7b445",
"object": "profile",
"appid": "tests_1656038569",
"accountid": "acct_ba184d8d4d83fa7a",
"companyName": null,
"fullName": "Christopher Hyatt",
"contactEmail": "Christopher56@yahoo.com",
"displayEmail": null,
"displayName": null,
"phone": null,
"occupation": null,
"location": null,
"dob": null,
"website": null,
"fields": null,
"createdAt": "2022-06-24T02:42:49.525Z",
"updatedAt": "2022-06-24T02:42:49.525Z"
},
{
"profileid": "prof_6c0b368762a61c5d",
"object": "profile",
"appid": "tests_1656038569",
"accountid": "acct_7f8a53d13fa99cd5",
"companyName": null,
"fullName": "Lynn Marks",
"contactEmail": "Lynn_Marks@yahoo.com",
"displayEmail": null,
"displayName": null,
"phone": null,
"occupation": null,
"location": null,
"dob": null,
"website": null,
"fields": null,
"createdAt": "2022-06-24T02:42:49.488Z",
"updatedAt": "2022-06-24T02:42:49.488Z"
},
{
"profileid": "prof_19d4410c907f25a2",
"object": "profile",
"appid": "tests_1656038569",
"accountid": "acct_1d18c8e1712cd923",
"companyName": null,
"fullName": "Raquel Marquardt",
"contactEmail": "Raquel.Marquardt9@yahoo.com",
"displayEmail": null,
"displayName": null,
"phone": null,
"occupation": null,
"location": null,
"dob": null,
"website": null,
"fields": null,
"createdAt": "2022-06-24T02:42:49.458Z",
"updatedAt": "2022-06-24T02:42:49.458Z"
}
]
Receives
API routes may receive parameters from the URL and POST supporting simple and multipart:
Field | Value | Required | Type |
---|---|---|---|
accountid | string | optional | URL |
all | boolean | optional | URL |
limit | integer | optional | URL |
offset | integer | optional | URL |
NodeJS source (view on github)
const dashboard = require('../../../../index.js')
module.exports = {
get: async (req) => {
req.query = req.query || {}
const where = {
appid: req.appid || global.appid
}
if (req.query.accountid) {
where.accountid = req.query.accountid
}
let profileids
if (req.query.all) {
profileids = await dashboard.Storage.Profile.findAll({
where,
attributes: ['profileid'],
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
profileids = await dashboard.Storage.Profile.findAll({
where,
attributes: ['profileid'],
offset,
limit,
order: [
['createdAt', 'DESC']
]
})
}
if (!profileids || !profileids.length) {
return null
}
const profiles = []
for (const profileData of profileids) {
req.query.profileid = profileData.dataValues.profileid
const profile = await global.api.administrator.Profile.get(req)
profiles.push(profile)
}
return profiles
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../test-helper.js')
describe('/api/administrator/profiles', function () {
const cachedResponses = {}
const cachedProfiles = []
before(async () => {
await TestHelper.setupBeforeEach()
const administrator = await TestHelper.createOwner()
cachedProfiles.push(administrator.profile.profileid)
for (let i = 0, len = global.pageSize + 1; i < len; i++) {
const user = await TestHelper.createUser()
cachedProfiles.unshift(user.profile.profileid)
}
const req1 = TestHelper.createRequest('/api/administrator/profiles?offset=1')
req1.account = administrator.account
req1.session = administrator.session
cachedResponses.offset = await req1.get()
const req2 = TestHelper.createRequest('/api/administrator/profiles?limit=1')
req2.account = administrator.account
req2.session = administrator.session
cachedResponses.limit = await req2.get()
const req3 = TestHelper.createRequest('/api/administrator/profiles?all=true')
req3.account = administrator.account
req3.session = administrator.session
cachedResponses.all = await req3.get()
const req4 = TestHelper.createRequest(`/api/administrator/profiles?accountid=${administrator.account.accountid}`)
req4.account = administrator.account
req4.session = administrator.session
cachedResponses.accountid = await req4.get()
const req5 = TestHelper.createRequest('/api/administrator/profiles')
req5.account = administrator.account
req5.session = administrator.session
req5.filename = __filename
req5.saveResponse = true
cachedResponses.returns = await req5.get()
global.pageSize = 3
cachedResponses.pageSize = await req5.get()
})
describe('receives', () => {
it('optional querystring offset (integer)', async () => {
const offset = 1
const profilesNow = cachedResponses.offset
for (let i = 0, len = global.pageSize; i < len; i++) {
assert.strictEqual(profilesNow[i].profileid, cachedProfiles[offset + i])
}
})
it('optional querystring limit (integer)', async () => {
const limit = 1
const profilesNow = cachedResponses.limit
assert.strictEqual(profilesNow.length, limit)
})
it('optional querystring all (boolean)', async () => {
const profilesNow = cachedResponses.all
assert.strictEqual(profilesNow.length, cachedProfiles.length)
})
it('optional querystring accountid (string)', async () => {
const profilesNow = cachedResponses.accountid
assert.strictEqual(profilesNow.length, 1)
})
})
describe('returns', () => {
it('array', async () => {
const profilesNow = cachedResponses.returns
assert.strictEqual(profilesNow.length, global.pageSize)
})
})
describe('configuration', () => {
it('environment PAGE_SIZE', async () => {
global.pageSize = 3
const profilesNow = cachedResponses.pageSize
assert.strictEqual(profilesNow.length, global.pageSize)
})
})
})