text: /* eslint-env mocha */
  const assert = require('assert')
  const TestHelper = require('../../../../test-helper.js')
  const ScreenshotData = require('../../../../screenshot-data.js')
  const DashboardTestHelper = require('@layeredapps/dashboard/test-helper.js')
  
  describe('/administrator/connect/stripe-account', function () {
    let cachedResponses
    async function bundledData (retryNumber) {
      if (retryNumber > 0) {
        cachedResponses = {}
      }
      if (cachedResponses && cachedResponses.finished) {
        return
      }
      cachedResponses = {}
      await DashboardTestHelper.setupBeforeEach()
      await TestHelper.setupBeforeEach()
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      await TestHelper.createStripeAccount(user, {
        country: 'US',
        business_type: 'individual'
      })
      const req = TestHelper.createRequest(`/administrator/connect/stripe-account?stripeid=${user.stripeAccount.stripeid}`)
      req.account = administrator.account
      req.session = administrator.session
      await req.route.api.before(req)
      cachedResponses.before = req.data
      req.filename = __filename
      req.screenshots = [
        { hover: '#administrator-menu-container' },
        { click: '/administrator/connect' },
        { click: '/administrator/connect/stripe-accounts' },
        { click: `/administrator/connect/stripe-account?stripeid=${user.stripeAccount.stripeid}` }
      ]
      global.pageSize = 50
      global.packageJSON.dashboard.server.push(ScreenshotData.administratorIndex)
      global.packageJSON.dashboard.server.push(ScreenshotData.administratorStripeAccounts)
      cachedResponses.view = await req.get()
      cachedResponses.finished = true
    }
  
    describe('before', () => {
      it('should bind data to req', async function () {
        await bundledData(this.test.currentRetry())
        const data = cachedResponses.before
        assert.strictEqual(data.stripeAccount.object, 'account')
      })
    })
  
    describe('view', () => {
      it('should present Stripe account table (screenshots)', async function () {
        await bundledData(this.test.currentRetry())
        const result = cachedResponses.view
        const doc = TestHelper.extractDoc(result.html)
        const table = doc.getElementById('stripe-accounts-table')
        assert.strictEqual(table.tag, 'table')
      })
    })
  
    describe('error', () => {
      it('invalid-stripeid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/administrator/connect/stripe-account?stripeid=invalid')
        req.account = administrator.account
        req.session = administrator.session
        await req.route.api.before(req)
        assert.strictEqual(req.error, 'invalid-stripeid')
      })
    })
  })
  