Skip to content

Commit

Permalink
refactor(payments): rename function
Browse files Browse the repository at this point in the history
getCurrentlyPrivateAndEnabledRepos to
getAmountOfCurrentlyPrivateAndEnabledRepos
  • Loading branch information
Realtin committed Oct 2, 2017
1 parent 885efd4 commit e616343
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions jobs/update-payments.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const env = require('../lib/env')
const { getActiveBilling, getCurrentlyPrivateAndEnabledRepos } = require('../lib/payments')
const { getActiveBilling, getAmountOfCurrentlyPrivateAndEnabledRepos } = require('../lib/payments')
const stripe = require('stripe')(env.STRIPE_SECRET_KEY)

module.exports = async ({ accountId, repositoryId }) => {
const billingAccount = await getActiveBilling(accountId)
// ignore non-stripe users
if (!billingAccount || !billingAccount.stripeSubscriptionId) return

const currentlyPrivateAndEnabledRepos = await getCurrentlyPrivateAndEnabledRepos(accountId)
const currentlyPrivateAndEnabledRepos = await getAmountOfCurrentlyPrivateAndEnabledRepos(accountId)

// charge for new repo from Stripe
const baseRepos = billingAccount.plan === 'org' ? 10 : 0
Expand Down
6 changes: 3 additions & 3 deletions lib/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function maybeUpdatePaymentsJob (accountId, isPrivate) {
}
}

async function getCurrentlyPrivateAndEnabledRepos (accountId) {
async function getAmountOfCurrentlyPrivateAndEnabledRepos (accountId) {
const { repositories } = await dbs()

const billing = await repositories.query('billing', {
Expand All @@ -48,7 +48,7 @@ async function getAccountNeedsMarketplaceUpgrade (accountId) {
if (!paymentDoc.plan) return false
if (paymentDoc.plan === 'opensource') return true
if (paymentDoc.plan === 'team') {
if (await module.exports.getCurrentlyPrivateAndEnabledRepos(accountId) >= 15) {
if (await module.exports.getAmountOfCurrentlyPrivateAndEnabledRepos(accountId) >= 15) {
return true // team plan & repo limit reached
}
return false // team plan & repo limit *not* reached
Expand All @@ -63,6 +63,6 @@ module.exports = {
hasStripeBilling,
getActiveBilling,
maybeUpdatePaymentsJob,
getCurrentlyPrivateAndEnabledRepos,
getAmountOfCurrentlyPrivateAndEnabledRepos,
getAccountNeedsMarketplaceUpgrade
}
2 changes: 1 addition & 1 deletion test/jobs/create-initial-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ test('create-initial-pr', async t => {
return {}
})

simple.mock(payments, 'getCurrentlyPrivateAndEnabledRepos').returnWith(15)
simple.mock(payments, 'getAmountOfCurrentlyPrivateAndEnabledRepos').returnWith(15)

await createInitial({
repository: { id: '44b' },
Expand Down
14 changes: 7 additions & 7 deletions test/lib/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { test, tearDown } = require('tap')
const simple = require('simple-mock')

const dbs = require('../../lib/dbs')
const { getActiveBilling, maybeUpdatePaymentsJob, hasStripeBilling, getAccountNeedsMarketplaceUpgrade, getCurrentlyPrivateAndEnabledRepos } = require(
const { getActiveBilling, maybeUpdatePaymentsJob, hasStripeBilling, getAccountNeedsMarketplaceUpgrade, getAmountOfCurrentlyPrivateAndEnabledRepos } = require(
'../../lib/payments'
)

Expand Down Expand Up @@ -158,16 +158,16 @@ test('payments', async t => {
t.end()
})

/* getCurrentlyPrivateAndEnabledRepos */
/* getAmountOfCurrentlyPrivateAndEnabledRepos */

t.test('getCurrentlyPrivateAndEnabledRepos with no Repos', async t => {
const result = await getCurrentlyPrivateAndEnabledRepos('123')
t.test('getAmountOfCurrentlyPrivateAndEnabledRepos with no Repos', async t => {
const result = await getAmountOfCurrentlyPrivateAndEnabledRepos('123')
t.equal(result, 0, '0 private and enabled repos')
t.end()
})

t.test('getCurrentlyPrivateAndEnabledRepos with one Repo', async t => {
const result = await getCurrentlyPrivateAndEnabledRepos('123team')
t.test('getAmountOfCurrentlyPrivateAndEnabledRepos with one Repo', async t => {
const result = await getAmountOfCurrentlyPrivateAndEnabledRepos('123team')
t.equal(result, 1, '1 private and enabled repo')
t.end()
})
Expand Down Expand Up @@ -212,7 +212,7 @@ test('payments', async t => {

t.test('getAccountNeedsMarketplaceUpgrade with `team` plan and reached repo limit', async t => {
const payments = require('../../lib/payments')
simple.mock(payments, 'getCurrentlyPrivateAndEnabledRepos').resolveWith(15)
simple.mock(payments, 'getAmountOfCurrentlyPrivateAndEnabledRepos').resolveWith(15)
const result = await getAccountNeedsMarketplaceUpgrade('123team')
simple.restore()

Expand Down

0 comments on commit e616343

Please sign in to comment.