Dashboard API explorer

/api/user/create-account (POST)

Account information like email addresses is generated with faker-js it is not real user information.

await global.api.user.CreateAccount.post(req)

Returns object

{
  "accountid": "acct_81c8fb2753977d67",
  "object": "account",
  "appid": "tests_1656038573",
  "profileid": null,
  "sessionKeyNumber": 1,
  "owner": true,
  "ownerSince": "2022-06-24T02:42:53.000Z",
  "administrator": true,
  "administratorSince": "2022-06-24T02:42:53.000Z",
  "createdAt": "2022-06-24T02:42:53.976Z",
  "updatedAt": "2022-06-24T02:42:53.976Z"
}

Receives

API routes may receive parameters from the URL and POST supporting simple and multipart:

Field Value Required Type
company-name string configurable as required POST
contact-email string configurable as required POST
display-email string configurable as required POST
display-name string configurable as required POST
dob string configurable as required POST
full-name string configurable as required POST
location string configurable as required POST
occupation string configurable as required POST
phone string configurable as required POST

Exceptions

These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:

Exception Circumstances
duplicate-username username already registered
invalid-company-name missing posted company-name
invalid-contact-email missing posted contact-email
invalid-display-email missing posted display-email
invalid-display-name missing posted display-name
invalid-display-name-length posted display-name too short
posted display-name too long
invalid-dob missing posted dob
invalid-full-name missing posted full-name
invalid-full-name-length posted full-name too short
posted full-name too long
invalid-location missing posted location
invalid-occupation missing posted occupation
invalid-password missing posted password
invalid-password-length posted password too short
posted password too long
invalid-phone missing posted phone
invalid-username missing posted username
invalid-username-length posted username too short
posted username too long

NodeJS source (view on github)

const crypto = require('crypto')
const dashboard = require('../../../../index.js')

module.exports = {
  auth: false,
  post: async (req) => {
    if (!req || !req.body) {
      throw new Error('invalid-username')
    }
    if (!req.body.username || !req.body.username.length) {
      throw new Error('invalid-username')
    }
    if (!req.body.password || !req.body.password.length) {
      throw new Error('invalid-password')
    }
    if (global.minimumUsernameLength > req.body.username.length ||
        global.maximumUsernameLength < req.body.username.length) {
      throw new Error('invalid-username-length')
    }
    if (global.minimumPasswordLength > req.body.password.length ||
        global.maximumPasswordLength < req.body.password.length) {
      throw new Error('invalid-password-length')
    }
    if (global.requireProfile) {
      const profileFields = req.userProfileFields || global.userProfileFields
      for (const field of profileFields) {
        switch (field) {
          case 'full-name':
            if (!req.body['full-name'] || !req.body['full-name'].length) {
              throw new Error('invalid-full-name')
            }
            if (global.minimumProfileFullNameLength > req.body['full-name'].length ||
              global.maximumProfileFullNameLength < req.body['full-name'].length) {
              throw new Error('invalid-full-name-length')
            }
            continue
          case 'contact-email':
            if (!req.body[field] || req.body[field].indexOf('@') < 1 || !dashboard.Validate.emailAddress(req.body[field])) {
              throw new Error(`invalid-${field}`)
            }
            continue
          case 'display-email':
            if (!req.body[field] || req.body[field].indexOf('@') < 1 || !dashboard.Validate.emailAddress(req.body[field])) {
              throw new Error(`invalid-${field}`)
            }
            continue
          case 'display-name':
            if (!req.body[field] || !req.body[field].length) {
              throw new Error(`invalid-${field}`)
            }
            if (global.minimumProfileDisplayNameLength > req.body[field].length ||
              global.maximumProfileDisplayNameLength < req.body[field].length) {
              throw new Error('invalid-display-name-length')
            }
            continue
          case 'dob':
            if (!req.body[field] || !req.body[field].length) {
              throw new Error(`invalid-${field}`)
            }
            try {
              const date = dashboard.Format.parseDate(req.body[field])
              if (!date || !date.getFullYear) {
                throw new Error(`invalid-${field}`)
              }
            } catch (error) {
              throw new Error(`invalid-${field}`)
            }
            continue
          default:
            if (!req.body || !req.body[field]) {
              throw new Error(`invalid-${field}`)
            }
            continue
        }
      }
    }
    let dashboardEncryptionKey = global.dashboardEncryptionKey
    if (req.server) {
      dashboardEncryptionKey = req.server.dashboardEncryptionKey || dashboardEncryptionKey
    }
    const usernameHash = await dashboard.Hash.sha512Hash(req.body.username, dashboardEncryptionKey)
    const passwordHash = await dashboard.Hash.bcryptHashHash(req.body.password, dashboardEncryptionKey)
    const accountInfo = {
      appid: req.appid || global.appid,
      usernameHash,
      passwordHash,
      sessionKey: crypto.randomBytes(32).toString('hex'),
      sessionKeyNumber: 1
    }
    const otherUsersExist = await dashboard.Storage.Account.findOne({
      where: {
        appid: req.appid || global.appid
      }
    })
    if (!otherUsersExist) {
      accountInfo.administratorSince = new Date()
      accountInfo.ownerSince = new Date()
    }
    let account
    try {
      account = await dashboard.Storage.Account.create(accountInfo)
    } catch (error) {
      if (error.name === 'SequelizeUniqueConstraintError') {
        throw new Error('duplicate-username')
      }
    }
    if (!account) {
      throw new Error('unknown-error')
    }
    req.query = req.query || {}
    req.query.accountid = account.dataValues.accountid
    req.account = req.query
    req.body.default = 'true'
    if (global.requireProfile) {
      await global.api.user.CreateProfile.post(req)
    }
    req.account = await global.api.user.Account.get(req)
    return req.account
  }
}

Test source (view on github)

/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../test-helper.js')

describe('/api/user/create-account', () => {
  describe('exceptions', () => {
    describe('invalid-username', () => {
      it('missing posted username', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: '',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-username')
      })
    })

    describe('duplicate-username', () => {
      it('username already registered', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: user.account.username,
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'duplicate-username')
      })
    })

    describe('invalid-username-length', () => {
      it('posted username too short', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: '123456',
          password: 'password'
        }
        let errorMessage
        global.minimumUsernameLength = 100
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-username-length')
      })

      it('posted username too long', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: '123456',
          password: 'password'
        }
        global.maximumUsernameLength = 1
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-username-length')
      })
    })

    describe('invalid-password', () => {
      it('missing posted password', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: ''
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-password')
      })
    })

    describe('invalid-password-length', () => {
      it('posted password too short', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: '1'
        }
        global.minimumPasswordLength = 100
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-password-length')
      })

      it('posted password too long', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: '12345'
        }
        global.maximumPasswordLength = 1
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-password-length')
      })
    })

    describe('invalid-full-name', () => {
      it('missing posted full-name', async () => {
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password',
          'full-name': ''
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-full-name')
      })
    })

    describe('invalid-full-name-length', () => {
      it('posted full-name too short', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: '123456',
          password: 'password',
          'full-name': 'Test Person'
        }
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        global.minimumProfileFullNameLength = 100
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-full-name-length')
      })

      it('posted full-name too long', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: '123456',
          password: 'password',
          'full-name': 'Test Person'
        }
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        global.maximumProfileFullNameLength = 1
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-full-name-length')
      })
    })

    describe('invalid-display-name', () => {
      it('missing posted display-name', async () => {
        global.requireProfile = true
        global.userProfileFields = ['display-name']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-display-name')
      })
    })

    describe('invalid-display-name-length', () => {
      it('posted display-name too short', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: '123456',
          password: 'password',
          'display-name': 'Test'
        }
        global.requireProfile = true
        global.userProfileFields = ['display-name']
        global.minimumProfileDisplayNameLength = 100
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-display-name-length')
      })

      it('posted display-name too long', async () => {
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: '123456',
          password: 'password',
          'display-name': 'Test'
        }
        global.requireProfile = true
        global.userProfileFields = ['display-name']
        global.maximumProfileDisplayNameLength = 1
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-display-name-length')
      })
    })

    describe('invalid-company-name', () => {
      it('missing posted company-name', async () => {
        global.requireProfile = true
        global.userProfileFields = ['company-name']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-company-name')
      })
    })

    describe('invalid-company-name-length', () => {
    })

    describe('invalid-contact-email', () => {
      it('missing posted contact-email', async () => {
        global.requireProfile = true
        global.userProfileFields = ['contact-email']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-contact-email')
      })
    })

    describe('invalid-display-email', () => {
      it('missing posted display-email', async () => {
        global.requireProfile = true
        global.userProfileFields = ['display-email']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-display-email')
      })
    })

    describe('invalid-location', () => {
      it('missing posted location', async () => {
        global.requireProfile = true
        global.userProfileFields = ['location']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-location')
      })
    })

    describe('invalid-occupation', () => {
      it('missing posted occupation', async () => {
        global.requireProfile = true
        global.userProfileFields = ['occupation']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-occupation')
      })
    })

    describe('invalid-phone', () => {
      it('missing posted phone', async () => {
        global.requireProfile = true
        global.userProfileFields = ['phone']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-phone')
      })
    })

    describe('invalid-dob', () => {
      it('missing posted dob', async () => {
        global.requireProfile = true
        global.userProfileFields = ['dob']
        const req = TestHelper.createRequest('/api/user/create-account')
        req.body = {
          username: 'username',
          password: 'password'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-dob')
      })
    })
  })

  describe('receives', () => {
    it('optionally-required posted full-name', async () => {
      global.requireProfile = true
      global.userProfileFields = ['full-name']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        'full-name': 'Testing Person'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.fullName, 'Testing Person')
    })

    it('optionally-required posted display-name', async () => {
      global.requireProfile = true
      global.userProfileFields = ['display-name']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        'display-name': 'Testing'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.displayName, 'Testing')
    })

    it('optionally-required posted company-name', async () => {
      global.requireProfile = true
      global.userProfileFields = ['company-name']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        'company-name': 'Testing'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.companyName, 'Testing')
    })

    it('optionally-required posted contact-email', async () => {
      global.requireProfile = true
      global.userProfileFields = ['contact-email']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        'contact-email': 'test@test.com'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.contactEmail, 'test@test.com')
    })

    it('optionally-required posted display-email', async () => {
      global.requireProfile = true
      global.userProfileFields = ['display-email']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        'display-email': 'test@test.com'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.displayEmail, 'test@test.com')
    })

    it('optionally-required posted location', async () => {
      global.requireProfile = true
      global.userProfileFields = ['location']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        location: 'testing'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.location, 'testing')
    })

    it('optionally-required posted occupation', async () => {
      global.requireProfile = true
      global.userProfileFields = ['occupation']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        occupation: 'testing'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.occupation, 'testing')
    })

    it('optionally-required posted phone', async () => {
      global.requireProfile = true
      global.userProfileFields = ['phone']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        phone: '123-456-7890'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.phone, '123-456-7890')
    })

    it('optionally-required posted dob', async () => {
      global.requireProfile = true
      global.userProfileFields = ['dob']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username',
        password: 'password',
        dob: '1950-01-01'
      }
      const account = await req.post()
      account.username = req.body.username
      account.password = req.body.password
      const session = await TestHelper.createSession({ account })
      const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
      req2.account = account
      req2.session = session
      const profile = await req2.get()
      assert.strictEqual(profile.dob, '1950-01-01')
    })
  })

  describe('returns', () => {
    it('object', async () => {
      global.requireProfile = false
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username-' + new Date().getTime(),
        password: 'password1234',
        confirm: 'password1234'
      }
      req.filename = __filename
      req.saveResponse = true
      const account = await req.post()
      assert.strictEqual(account.object, 'account')
    })
  })

  describe('configuration', () => {
    it('environment MINIMUM_USERNAME_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password'
      }
      global.minimumUsernameLength = 100
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-username-length')
    })

    it('environment MAXIMUM_USERNAME_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password'
      }
      global.maximumUsernameLength = 1
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-username-length')
    })

    it('environment MINIMUM_PASSWORD_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password'
      }
      global.minimumPasswordLength = 100
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-password-length')
    })

    it('environment MAXIMUM_PASSWORD_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username-' + new Date().getTime(),
        password: 'password1234',
        confirm: 'password1234'
      }
      global.maximumPasswordLength = 1
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-password-length')
    })

    it('environment REQUIRE_PROFILE', async () => {
      global.requireProfile = true
      global.userProfileFields = ['contact-email']
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: 'username-' + new Date().getTime(),
        password: 'password1234',
        confirm: 'password1234'
      }
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-contact-email')
    })

    it('environment USER_PROFILE_FIELDS', async () => {
      global.requireProfile = true
      const req = TestHelper.createRequest('/api/user/create-account')
      const fields = ['full-name', 'display-name', 'contact-email', 'display-email', 'dob', 'phone', 'occupation', 'location', 'company-name', 'website']
      const body = {
        'full-name': 'Test Person',
        'contact-email': 'test1@test.com',
        'display-email': 'test2@test.com',
        dob: '2000-01-01',
        'display-name': 'tester',
        phone: '456-789-0123',
        occupation: 'Programmer',
        location: 'USA',
        'company-name': 'Test company',
        website: 'https://example.com'
      }
      for (const field of fields) {
        req.body = {
          username: 'username-' + new Date().getTime(),
          password: 'password1234',
          confirm: 'password1234',
          [field]: body[field]
        }
        global.userProfileFields = [field]
        const displayName = global.profileFieldMap[field]
        const account = await req.post()
        account.username = req.body.username
        account.password = req.body.password
        const session = await TestHelper.createSession({ account })
        const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
        req2.account = account
        req2.session = session
        const profile = await req2.get()
        assert.strictEqual(profile[displayName], body[field])
      }
    })

    it('environment MINIMUM_PROFILE_FULL_NAME_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password',
        'full-name': 'Test Person'
      }
      global.requireProfile = true
      global.userProfileFields = ['full-name']
      global.minimumProfileFullNameLength = 100
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-full-name-length')
    })

    it('environment MAXIMUM_PROFILE_FULL_NAME_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password',
        'full-name': 'Test Person'
      }
      global.requireProfile = true
      global.userProfileFields = ['full-name']
      global.maximumProfileFullNameLength = 1
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-full-name-length')
    })

    it('environment MINIMUM_PROFILE_DISPLAY_NAME_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password',
        'display-name': '1'
      }
      global.requireProfile = true
      global.userProfileFields = ['display-name']
      global.minimumProfileDisplayNameLength = 100
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-display-name-length')
    })

    it('environment MAXIMUM_PROFILE_DISPLAY_NAME_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password',
        'display-name': 'meeeee123'
      }
      global.requireProfile = true
      global.userProfileFields = ['display-name']
      global.maximumProfileDisplayNameLength = 1
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-display-name-length')
    })

    it('environment MINIMUM_PROFILE_COMPANY_NAME_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password',
        'company-name': '1'
      }
      global.requireProfile = true
      global.userProfileFields = ['company-name']
      global.minimumProfileCompanyNameLength = 100
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-company-name-length')
    })

    it('environment MAXIMUM_PROFILE_COMPANY_NAME_LENGTH', async () => {
      const req = TestHelper.createRequest('/api/user/create-account')
      req.body = {
        username: '123456',
        password: 'password',
        'company-name': 'acme inc'
      }
      global.requireProfile = true
      global.userProfileFields = ['company-name']
      global.maximumProfileCompanyNameLength = 1
      let errorMessage
      try {
        await req.post()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-company-name-length')
    })

    it('override req.userProfileFields', async () => {
      global.requireProfile = true
      global.userProfileFields = ['full-name', 'display-name', 'contact-email', 'display-email', 'dob', 'phone', 'occupation', 'location', 'company-name', 'website']
      const req = TestHelper.createRequest('/api/user/create-account')
      const body = {
        'full-name': 'Test Person',
        'contact-email': 'test1@test.com',
        'display-email': 'test2@test.com',
        dob: '2000-01-01',
        'display-name': 'tester',
        phone: '456-789-0123',
        occupation: 'Programmer',
        location: 'USA',
        'company-name': 'Test company',
        website: 'https://example.com'
      }
      for (const field of global.userProfileFields) {
        req.userProfileFields = [field]
        req.body = {
          username: 'username-' + new Date().getTime(),
          password: 'password1234',
          confirm: 'password1234',
          [field]: body[field]
        }
        const displayName = global.profileFieldMap[field]
        const account = await req.route.api.post(req)
        account.username = req.body.username
        account.password = req.body.password
        const session = await TestHelper.createSession({ account })
        const req2 = TestHelper.createRequest(`/api/user/profile?profileid=${account.profileid}`)
        req2.account = account
        req2.session = session
        const profile = await req2.get()
        assert.strictEqual(profile[displayName], body[field])
      }
    })
  })
})