mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-27 17:24:05 +08:00
test of billing.generateBilling
This commit is contained in:
@@ -20,7 +20,7 @@ exports.cyclicalBilling = (callback) ->
|
||||
callback()
|
||||
|
||||
exports.isForceFreeze = (account) ->
|
||||
if _.isEmpty account.billing.services
|
||||
if _.isEmpty account.billing.plans
|
||||
return false
|
||||
|
||||
if account.billing.balance < config.billing.force_freeze.when_balance_below
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
describe 'billing', ->
|
||||
billing = null
|
||||
config = null
|
||||
Account = null
|
||||
|
||||
account = null
|
||||
|
||||
before ->
|
||||
{billing} = app
|
||||
{billing, config} = app
|
||||
{Account} = app.models
|
||||
|
||||
account = new Account
|
||||
@@ -23,7 +24,7 @@ describe 'billing', ->
|
||||
expect(billing.isForceFreeze(account)).to.not.ok
|
||||
|
||||
it 'should be true when balance below then 0', ->
|
||||
account.billing.services = ['sample']
|
||||
account.billing.plans = ['sample']
|
||||
account.billing.balance = -5
|
||||
expect(billing.isForceFreeze(account)).to.be.ok
|
||||
|
||||
@@ -37,7 +38,42 @@ describe 'billing', ->
|
||||
expect(billing.isForceFreeze(account)).to.not.ok
|
||||
|
||||
describe 'generateBilling', ->
|
||||
it 'pending'
|
||||
it 'should success for billing_by_time plan', (done) ->
|
||||
config.plans.billing_test =
|
||||
billing_by_time:
|
||||
unit: 24 * 3600 * 1000
|
||||
price: 10 / 30
|
||||
|
||||
services: []
|
||||
resources: {}
|
||||
|
||||
last_billing_at = new Date Date.now() - 2 * 24 * 3600 * 1000 + 5000000
|
||||
|
||||
account.plan = ['billing_test']
|
||||
account.billing.last_billing_at =
|
||||
billing_test: last_billing_at
|
||||
|
||||
billing.generateBilling account, 'billing_test', (billing_report) ->
|
||||
new_last_billing_at = new Date last_billing_at.getTime() + 2 * 24 * 3600 * 1000
|
||||
|
||||
billing_report.should.eql
|
||||
plan_name: 'billing_test'
|
||||
billing_unit_count: 2
|
||||
last_billing_at: new_last_billing_at
|
||||
amount_inc: -10 / 15
|
||||
|
||||
new_last_billing_at.should.above new Date()
|
||||
new_last_billing_at.should.below new Date Date.now() + 24 * 3600 * 1000
|
||||
|
||||
done()
|
||||
|
||||
it 'should return null when less then unit', (done) ->
|
||||
account.billing.last_billing_at =
|
||||
billing_test: new Date Date.now() + 5000000
|
||||
|
||||
billing.generateBilling account, 'billing_test', (billing_report) ->
|
||||
expect(billing_report).to.not.exist
|
||||
done()
|
||||
|
||||
describe 'triggerBilling', ->
|
||||
it 'pending'
|
||||
|
||||
Reference in New Issue
Block a user