/api/user/profile (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.user.Profile.get(req)Returns object
{
"profileid": "prof_b8265ded70696a3a",
"object": "profile",
"appid": "tests_1656038577",
"accountid": "acct_75b031fb3369ff43",
"companyName": null,
"fullName": "Tammy Douglas",
"contactEmail": "Tammy.Douglas60@gmail.com",
"displayEmail": null,
"displayName": null,
"phone": null,
"occupation": null,
"location": null,
"dob": null,
"website": null,
"fields": null,
"createdAt": "2022-06-24T02:42:57.658Z",
"updatedAt": "2022-06-24T02:42:57.658Z"
}
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 querystring profileid |
invalid-profileid | missing querystring profileid |
invalid querystring profileid |
NodeJS source (view on github)
const dashboard = require('../../../../index.js')
module.exports = {
get: async (req) => {
if (!req.query || !req.query.profileid) {
throw new Error('invalid-profileid')
}
let profile = await dashboard.StorageCache.get(req.query.profileid)
if (!profile) {
let profileInfo
try {
profileInfo = await dashboard.Storage.Profile.findOne({
where: {
profileid: req.query.profileid,
appid: req.appid || global.appid
}
})
} catch (error) {
}
if (!profileInfo) {
throw new Error('invalid-profileid')
}
profile = {}
for (const field of profileInfo._options.attributes) {
profile[field] = profileInfo.get(field)
}
await dashboard.StorageCache.set(req.query.profileid, profile)
}
if (profile.accountid !== req.account.accountid) {
throw new Error('invalid-account')
}
return profile
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../test-helper.js')
describe('/api/user/profile', () => {
describe('exceptions', () => {
describe('invalid-profileid', () => {
it('missing querystring profileid', async () => {
const user = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/user/profile')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-profileid')
})
it('invalid querystring profileid', async () => {
const user = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/user/profile?profileid=invalid')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-profileid')
})
})
describe('invalid-account', () => {
it('ineligible querystring profileid', async () => {
const user = await TestHelper.createUser()
const user2 = await TestHelper.createUser()
const req = TestHelper.createRequest(`/api/user/profile?profileid=${user2.account.profileid}`)
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('object', async () => {
const user = await TestHelper.createUser()
const req = TestHelper.createRequest(`/api/user/profile?profileid=${user.profile.profileid}`)
req.account = user.account
req.session = user.session
req.filename = __filename
req.saveResponse = true
const profile = await req.get()
assert.strictEqual(profile.object, 'profile')
})
})
})