Skip to content

Commit

Permalink
test(payments, create-initial-pr): add simple-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
Realtin committed Oct 2, 2017
1 parent c9cc68e commit 36eb436
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ async function getAccountNeedsMarketplaceUpgrade (accountId) {
if (paymentDoc.plan === 'opensource') return true
if (paymentDoc.plan === 'team') {
console.log('***TEAM***')
console.log('***Repos***', await getCurrentlyPrivateAndEnabledRepos(accountId))
if (await getCurrentlyPrivateAndEnabledRepos(accountId) >= 15) {
console.log('***Repos***', await module.exports.getCurrentlyPrivateAndEnabledRepos(accountId))
if (await module.exports.getCurrentlyPrivateAndEnabledRepos(accountId) >= 15) {
console.log('***TEAM OVER LIMIT***')
return true // team plan & repo limit reached
}
Expand Down
40 changes: 23 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"nyc": "^11.0.3",
"prettier-standard-formatter": "^0.222222222222222.333333333333333",
"proxyquire": "^1.7.10",
"simple-mock": "^0.8.0",
"standard": "^10.0.2",
"tap": "^10.0.1"
},
Expand Down
15 changes: 6 additions & 9 deletions test/jobs/create-initial-pr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { test, tearDown } = require('tap')
const nock = require('nock')
const proxyquire = require('proxyquire')
const simple = require('simple-mock')

const dbs = require('../../lib/dbs')
const createInitial = require('../../jobs/create-initial-pr')
Expand Down Expand Up @@ -350,6 +350,8 @@ test('create-initial-pr', async t => {
})

t.test('create pr for private repo and account with Github `team` plan with payment required', async t => {
const payments = require('../../lib/payments')

await repositories.put({
_id: '44b',
accountId: '123team',
Expand Down Expand Up @@ -400,15 +402,9 @@ test('create-initial-pr', async t => {
return {}
})

const worker = proxyquire('../../jobs/create-initial-pr', {
'../lib/payments': {
'getCurrentlyPrivateAndEnabledRepos': async (accountId) => { // Help! not working!
return 15
}
}
})
simple.mock(payments, 'getCurrentlyPrivateAndEnabledRepos').returnWith(15)

await worker({
await createInitial({
repository: { id: '44b' },
branchDoc: branchDoc,
combined: {
Expand All @@ -418,6 +414,7 @@ test('create-initial-pr', async t => {
installationId: 11,
accountId: '123team'
})
simple.restore()
})

t.test('create pr for private repo and account with Github `business` plan', async t => {
Expand Down
11 changes: 5 additions & 6 deletions test/lib/payments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { test, tearDown } = require('tap')
const proxyquire = require('proxyquire')
const simple = require('simple-mock')

const dbs = require('../../lib/dbs')
const { getActiveBilling, maybeUpdatePaymentsJob, hasStripeBilling, getAccountNeedsMarketplaceUpgrade } = require(
Expand Down Expand Up @@ -165,12 +165,11 @@ test('payments', async t => {
})

t.test('getAccountNeedsMarketplaceUpgrade with `team` plan and reached repo limit', async t => {
const { getAccountNeedsMarketplaceUpgrade } = proxyquire('../../lib/payments', { // Help! can't get this to be overwritten
'./getCurrentlyPrivateAndEnabledRepos': async (accountId) => {
return 15
}
})
const payments = require('../../lib/payments')
simple.mock(payments, 'getCurrentlyPrivateAndEnabledRepos').resolveWith(15)
const result = await getAccountNeedsMarketplaceUpgrade('123team')
simple.restore()

t.ok(result)
t.end()
})
Expand Down

0 comments on commit 36eb436

Please sign in to comment.