Dashboard API explorer

/api/user/update-profile (PATCH)

await global.api.user.UpdateProfile.patch(req)
Located in Dashboard API

Returns object

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-profileid ineligible querystring profileid
invalid-first-name missing posted first-name
posted first-name too long
invalid-first-name-length posted first-name too short
invalid-last-name missing posted last-name
posted last-name too long
invalid-last-name-length posted last-name too short
invalid-display-name missing posted display-name
posted display-name too long
invalid-display-name-length posted display-name too short
invalid-company-name missing posted company-name
posted company-name too long
invalid-company-name-length posted company-name too short
invalid-contact-email missing posted contact-email
invalid-display-email missing posted display-email
invalid-location missing posted location
invalid-occupation missing posted occupation
invalid-phone missing posted phone
invalid-dob missing posted dob

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
first-name string configurable as required POST
last-name string configurable as required POST
location string configurable as required POST
occupation string configurable as required POST
phone string configurable as required POST

NodeJS source (edit on github)

If you see a problem with the source submit a pull request on Github.

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

module.exports = {
  patch: async (req) => {
    if (!req.query || !req.query.profileid) {
      throw new Error('invalid-profileid')
    }
    const profile = await global.api.user.Profile.get(req)
    if (!profile) {
      throw new Error('invalid-profileid')
    }
    req.body = req.body || {}
    const profileInfo = {}
    const profileFields = req.userProfileFields || global.userProfileFields
    const accountProperties = {}
    for (const field of profileFields) {
      const displayName = global.profileFieldMap[field]
      switch (field) {
        case 'full-name':
          if (!req.body['first-name'] || !req.body['first-name'].length) {
            throw new Error('invalid-first-name')
          }
          if (global.minimumProfileFirstNameLength > req.body['first-name'].length ||
            global.maximumProfileFirstNameLength < req.body['first-name'].length) {
            throw new Error('invalid-first-name-length')
          }
          if (!req.body['last-name'] || !req.body['last-name'].length) {
            throw new Error('invalid-last-name')
          }
          if (global.minimumProfileLastNameLength > req.body['last-name'].length ||
            global.maximumProfileLastNameLength < req.body['last-name'].length) {
            throw new Error('invalid-last-name-length')
          }
          profileInfo.firstName = accountProperties.firstName = req.body['first-name']
          profileInfo.lastName = accountProperties.lastName = req.body['last-name']
          continue
        case 'contact-email':
          if (!req.body[field] || req.body[field].indexOf('@') < 1) {
            throw new Error(`invalid-${field}`)
          }
          profileInfo.contactEmail = accountProperties.contactEmail = req.body[field]
          continue
        case 'display-email':
          if (!req.body[field] || req.body[field].indexOf('@') < 1) {
            throw new Error(`invalid-${field}`)
          }
          profileInfo.displayEmail = accountProperties.displayName = req.body[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')
          }
          profileInfo.displayName = accountProperties.displayName = req.body[field]
          continue
        case 'company-name':
          if (!req.body[field] || !req.body[field].length) {
            throw new Error(`invalid-${field}`)
          }
          if (global.minimumProfileCompanyNameLength > req.body[field].length ||
            global.maximumProfileCompanyNameLength < req.body[field].length) {
            throw new Error('invalid-company-name-length')
          }
          profileInfo.companyName = accountProperties.companyName = req.body[field]
          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}`)
            }
            profileInfo.dob = accountProperties.dob = dashboard.Format.date(date)
          } catch (error) {
            throw new Error(`invalid-${field}`)
          }
          continue
        default:
          if (!req.body[field]) {
            throw new Error(`invalid-${field}`)
          }
          profileInfo[displayName] = accountProperties[displayName] = req.body[field]
          continue
      }
    }
    const storage = req.storage || dashboard
    await storage.StorageObject.setProperties(`${req.appid}/profile/${req.query.profileid}`, profileInfo)
    if (req.query.profileid === req.account.profileid || req.body.default === 'true') {
      await storage.StorageObject.setProperties(`${req.appid}/account/${req.account.accountid}`, accountProperties)
    }
    for (const field in profileInfo) {
      profile[field] = profileInfo[field]
    }
    return profile
  }
}

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/user/update-profile', () => {
  describe('exceptions', () => {
    describe('invalid-profileid', () => {
      it('missing querystring profileid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/update-profile')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.patch()
        } 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/update-profile?profileid=invalid')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-profileid')
      })
    })

    describe('invalid-profileid', () => {
      it('ineligible querystring profileid', async () => {
        const user = await TestHelper.createUser()
        const user2 = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user2.account.profileid}`)
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-account')
      })
    })

    describe('invalid-first-name', () => {
      it('missing posted first-name', async () => {
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'last-name': 'Person'
        }
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-first-name')
      })
    })

    describe('invalid-first-name-length', () => {
      it('posted first-name too short', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'first-name': 'Test',
          'last-name': 'Person'
        }
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        global.minimumProfileFirstNameLength = 100
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-first-name-length')
      })

      it('posted first-name too long', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'first-name': 'Test',
          'last-name': 'Person'
        }
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        global.maximumProfileFirstNameLength = 1
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-first-name-length')
      })
    })

    describe('invalid-last-name', () => {
      it('missing posted last-name', async () => {
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'first-name': 'Test'
        }
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-last-name')
      })
    })

    describe('invalid-last-name-length', () => {
      it('posted last-name too short', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'first-name': 'Test',
          'last-name': 'Person'
        }
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        global.minimumProfileLastNameLength = 100
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-last-name-length')
      })

      it('posted last-name too long', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'first-name': 'Test',
          'last-name': 'Person'
        }
        global.requireProfile = true
        global.userProfileFields = ['full-name']
        global.maximumProfileLastNameLength = 1
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-last-name-length')
      })
    })

    describe('invalid-display-name', () => {
      it('missing posted display-name', async () => {
        global.requireProfile = true
        global.userProfileFields = ['display-name']
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {}
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-display-name')
      })
    })

    describe('invalid-display-name-length', () => {
      it('posted display-name too short', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'display-name': 'Test'
        }
        global.requireProfile = true
        global.userProfileFields = ['display-name']
        global.minimumProfileDisplayNameLength = 100
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-display-name-length')
      })

      it('posted display-name too long', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'display-name': 'Test'
        }
        global.requireProfile = true
        global.userProfileFields = ['display-name']
        global.maximumProfileDisplayNameLength = 1
        let errorMessage
        try {
          await req.patch()
        } 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 user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {}
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-company-name')
      })
    })

    describe('invalid-company-name-length', () => {
      it('posted company-name too short', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/create-profile?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'company-name': 'Test'
        }
        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('posted company-name too long', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/create-profile?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          'company-name': 'Test'
        }
        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')
      })
    })

    describe('invalid-contact-email', () => {
      it('missing posted contact-email', async () => {
        global.requireProfile = true
        global.userProfileFields = ['contact-email']
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {}
        let errorMessage
        try {
          await req.patch()
        } 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 user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {}
        let errorMessage
        try {
          await req.patch()
        } 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 user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {}
        let errorMessage
        try {
          await req.patch()
        } 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 user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {}
        let errorMessage
        try {
          await req.patch()
        } 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 user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {}
        let errorMessage
        try {
          await req.patch()
        } 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 user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
        req.account = user.account
        req.session = user.session
        req.body = {}
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-dob')
      })
    })
  })

  describe('receives', () => {
    it('optionally-required posted first-name', async () => {
      global.requireProfile = true
      global.userProfileFields = ['full-name']
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'first-name': 'Testing',
        'last-name': 'Person'
      }
      const profile = await req.patch()
      assert.strictEqual(profile.firstName, 'Testing')
    })

    it('optionally-required posted last-name', async () => {
      global.requireProfile = true
      global.userProfileFields = ['full-name']
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'first-name': 'Test',
        'last-name': 'Testing'
      }
      const profile = await req.patch()
      assert.strictEqual(profile.lastName, 'Testing')
    })

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

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

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

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

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

    it('optionally-required posted occupation', async () => {
      global.requireProfile = true
      global.userProfileFields = ['occupation']
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        occupation: 'Testing'
      }
      const profile = await req.patch()
      assert.strictEqual(profile.occupation, 'Testing')
    })

    it('optionally-required posted phone', async () => {
      global.requireProfile = true
      global.userProfileFields = ['phone']
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        phone: '456-789-0123'
      }
      const profile = await req.patch()
      assert.strictEqual(profile.phone, '456-789-0123')
    })

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

  describe('returns', () => {
    it('object', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'first-name': 'Test',
        'last-name': 'Person'
      }
      req.filename = __filename
      req.saveResponse = true
      global.userProfileFields = ['full-name']
      const profile = await req.patch()
      assert.strictEqual(profile.object, 'profile')
    })
  })

  describe('configuration', () => {
    it('environment USER_PROFILE_FIELDS', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      const fields = ['full-name', 'display-name', 'contact-email', 'display-email', 'dob', 'phone', 'occupation', 'location', 'company-name', 'website']
      const body = {
        'first-name': 'Test',
        'last-name': '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 = {
          confirm: 'password1234'
        }
        if (field === 'full-name') {
          req.body['first-name'] = body['first-name']
          req.body['last-name'] = body['last-name']
        } else {
          req.body[field] = body[field]
        }
        global.userProfileFields = [field]
        const displayName = global.profileFieldMap[field]
        const account = await req.patch()
        assert.strictEqual(account[displayName], body[field])
      }
    })

    it('environment MINIMUM_PROFILE_FIRST_NAME_LENGTH', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'first-name': 'Test',
        'last-name': 'Person'
      }
      global.userProfileFields = ['full-name']
      global.minimumProfileFirstNameLength = 100
      let errorMessage
      try {
        await req.patch()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-first-name-length')
    })

    it('environment MAXIMUM_PROFILE_FIRST_NAME_LENGTH', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'first-name': 'Test',
        'last-name': 'Person'
      }
      global.userProfileFields = ['full-name']
      global.maximumProfileFirstNameLength = 1
      let errorMessage
      try {
        await req.patch()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-first-name-length')
    })

    it('environment MINIMUM_PROFILE_LAST_NAME_LENGTH', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'first-name': 'Test',
        'last-name': 'Person'
      }
      global.userProfileFields = ['full-name']
      global.minimumProfileLastNameLength = 100
      let errorMessage
      try {
        await req.patch()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-last-name-length')
    })

    it('environment MAXIMUM_PROFILE_LAST_NAME_LENGTH', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'first-name': 'Test',
        'last-name': 'Person'
      }
      global.userProfileFields = ['full-name']
      global.maximumProfileLastNameLength = 1
      let errorMessage
      try {
        await req.patch()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-last-name-length')
    })

    it('environment MINIMUM_PROFILE_DISPLAY_NAME_LENGTH', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'display-name': '1'
      }
      global.userProfileFields = ['display-name']
      global.minimumProfileDisplayNameLength = 100
      let errorMessage
      try {
        await req.patch()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-display-name-length')
    })

    it('environment MAXIMUM_PROFILE_DISPLAY_NAME_LENGTH', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'display-name': 'meeeee123'
      }
      global.userProfileFields = ['display-name']
      global.maximumProfileDisplayNameLength = 1
      let errorMessage
      try {
        await req.patch()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-display-name-length')
    })

    it('environment MINIMUM_PROFILE_COMPANY_NAME_LENGTH', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'company-name': '1'
      }
      global.userProfileFields = ['company-name']
      global.minimumProfileCompanyNameLength = 100
      let errorMessage
      try {
        await req.patch()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-company-name-length')
    })

    it('environment MAXIMUM_PROFILE_COMPANY_NAME_LENGTH', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        'company-name': 'acme inc'
      }
      global.userProfileFields = ['company-name']
      global.maximumProfileCompanyNameLength = 1
      let errorMessage
      try {
        await req.patch()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-company-name-length')
    })

    it('override req.userProfileFields', async () => {
      const user = await TestHelper.createUser()
      global.userProfileFields = ['full-name', 'display-name', 'contact-email', 'display-email', 'dob', 'phone', 'occupation', 'location', 'company-name', 'website']
      const req = TestHelper.createRequest(`/api/user/update-profile?profileid=${user.account.profileid}`)
      req.account = user.account
      req.session = user.session
      const body = {
        'first-name': 'Test',
        'last-name': '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 = {}
        if (field === 'full-name') {
          req.body['first-name'] = body['first-name']
          req.body['last-name'] = body['last-name']
        } else {
          req.body[field] = body[field]
        }
        const displayName = global.profileFieldMap[field]
        const account = await req.route.api.patch(req)
        assert.strictEqual(account[displayName], body[field])
      }
    })
  })
})