Dashboard API explorer

/api/administrator/set-account-deleted (PATCH)

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

await global.api.administrator.SetAccountDeleted.patch(req)

Returns object

{
  "accountid": "acct_29acf2a5d24eec3f",
  "object": "account",
  "appid": "tests_1656038572",
  "profileid": "prof_22a7414aaaae2d73",
  "sessionKeyNumber": 1,
  "deletedAt": "2022-07-01T02:42:52.000Z",
  "lastSignedInAt": "2022-06-24T02:42:52.000Z",
  "createdAt": "2022-06-24T02:42:52.289Z",
  "updatedAt": "2022-06-24T02:42:52.320Z"
}

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 account is already deleted
querystring accountid is deleted
invalid-accountid unspecified querystring accountid
invalid querystring accountid

NodeJS source (view on github)

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

module.exports = {
  patch: async (req) => {
    if (!req.query || !req.query.accountid) {
      throw new Error('invalid-accountid')
    }
    const account = await global.api.administrator.Account.get(req)
    if (!account) {
      throw new Error('invalid-accountid')
    }
    if (account.deletedAt) {
      throw new Error('invalid-account')
    }
    const now = new Date()
    let deletedAt
    if (global.deleteDelay) {
      deletedAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + global.deleteDelay, now.getHours(), now.getMinutes(), now.getSeconds())
    } else {
      deletedAt = now
    }
    const updateClause = {
      deletedAt
    }
    await dashboard.Storage.Account.update(updateClause, {
      where: {
        accountid: req.query.accountid,
        appid: req.appid || global.appid
      }
    })
    await dashboard.StorageCache.remove(req.query.accountid)
    return global.api.administrator.Account.get(req)
  }
}

Test source (view on github)

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

describe('/api/administrator/set-account-deleted', () => {
  describe('exceptions', () => {
    describe('invalid-accountid', () => {
      it('unspecified querystring accountid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/set-account-deleted')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-accountid')
      })

      it('invalid querystring accountid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/set-account-deleted?accountid=invalid')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-accountid')
      })
    })

    describe('invalid-account', () => {
      it('ineligible querystring account is already deleted', async () => {
        const administrator = await TestHelper.createOwner()
        const user = await TestHelper.createUser()
        await TestHelper.setDeleted(user)
        const req = TestHelper.createRequest(`/api/administrator/set-account-deleted?accountid=${user.account.accountid}`)
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.patch(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-account')
      })
    })
  })

  describe('invalid-account', () => {
    it('querystring accountid is deleted', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      await TestHelper.setDeleted(user)
      const req = TestHelper.createRequest(`/api/administrator/set-account-deleted?accountid=${user.account.accountid}`)
      req.account = administrator.account
      req.session = administrator.session
      let errorMessage
      try {
        await req.patch(req)
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-account')
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/administrator/set-account-deleted?accountid=${user.account.accountid}`)
      req.account = administrator.account
      req.session = administrator.session
      global.deleteDelay = 1
      const accountNow = await req.patch()
      const deleted = new Date(accountNow.deletedAt).getTime() / 1000
      const now = Math.floor(new Date().getTime() / 1000)
      const days = Math.floor((deleted - now) / 60 / 60 / 24)
      const days2 = Math.ceil((deleted - now) / 60 / 60 / 24)
      assert.strictEqual(days === 1 || days2 === 1, true)
    })
  })

  describe('configuration', () => {
    it('environment DELETE_DELAY', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/administrator/set-account-deleted?accountid=${user.account.accountid}`)
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      global.deleteDelay = 7
      const accountNow = await req.patch()
      const deleted = new Date(accountNow.deletedAt).getTime() / 1000
      const now = Math.floor(new Date().getTime() / 1000)
      const days = Math.floor((deleted - now) / 60 / 60 / 24)
      const days2 = Math.ceil((deleted - now) / 60 / 60 / 24)
      assert.strictEqual(days === 7 || days2 === 7, true)
    })
  })
})