Stripe Subscriptions module API explorer

/api/administrator/subscriptions/usage-records-count (GET)

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

await global.api.administrator.subscriptions.UsageRecordsCount.get(req)

NodeJS source (view on github)

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

module.exports = {
  get: async (req) => {
    const where = {
      appid: req.appid || global.appid
    }
    req.query = req.query || {}
    if (req.query.customerid) {
      where.customerid = req.query.customerid
    } else if (req.query.subscriptionid) {
      where.subscriptionid = req.query.subscriptionid
    } else if (req.query.accountid) {
      where.accountid = req.query.accountid
    }
    return subscriptions.Storage.UsageRecord.count({
      where
    })
  }
}

Test source (view on github)

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

describe('/api/administrator/subscriptions/usage-records-count', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('returns', () => {
    it('integer', async () => {
      const administrator = await TestStripeAccounts.createOwnerWithPrice({
        active: 'true',
        currency: 'usd',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        billing_scheme: 'tiered',
        tax_behavior: 'inclusive',
        tiers_mode: 'volume',
        tier1_up_to: '1000',
        tier1_flat_amount: '9999',
        tier2_up_to: 'inf',
        tier2_flat_amount: '8999'
      })
      let accountUser
      for (let i = 0, len = global.pageSize; i < len; i++) {
        const user = accountUser = await TestStripeAccounts.createUserWithPaidSubscription(administrator.price)
        await TestHelper.createUsageRecord(user, 100)
      }
      await TestStripeAccounts.createUserWithPaidSubscription(administrator.price, accountUser)
      await TestHelper.createUsageRecord(accountUser, 100)
      await TestHelper.wait(1100)
      await TestHelper.createUsageRecord(accountUser, 100)
      const req = TestHelper.createRequest('/api/administrator/subscriptions/usage-records-count')
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const result = await req.get()
      assert.strictEqual(result, global.pageSize + 2)
    })
  })
})