Skip to content

Commit

Permalink
reafctor(tests): extract removeIfExists function to helper file
Browse files Browse the repository at this point in the history
  • Loading branch information
Realtin committed Oct 2, 2017
1 parent 8c98d44 commit 96778af
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 40 deletions.
11 changes: 1 addition & 10 deletions test/jobs/github-event/marketplace_purchase/cancelled.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
const { test, tearDown } = require('tap')
const dbs = require('../../../../lib/dbs')
const worker = require('../../../../jobs/github-event/marketplace_purchase/cancelled')

const removeIfExists = async (db, id) => {
try {
return await db.remove(await db.get(id))
} catch (e) {
if (e.status !== 404) {
throw e
}
}
}
const removeIfExists = require('../../../remove-if-exists.js')

test('marketplace canceled', async t => {
t.test('change entry in payments database to `free`', async t => {
Expand Down
11 changes: 1 addition & 10 deletions test/jobs/github-event/marketplace_purchase/changed.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
const { test, tearDown } = require('tap')
const dbs = require('../../../../lib/dbs')
const worker = require('../../../../jobs/github-event/marketplace_purchase/changed')

const removeIfExists = async (db, id) => {
try {
return await db.remove(await db.get(id))
} catch (e) {
if (e.status !== 404) {
throw e
}
}
}
const removeIfExists = require('../../../remove-if-exists.js')

test('marketplace changed', async t => {
t.test('change entry in payments database', async t => {
Expand Down
11 changes: 1 addition & 10 deletions test/jobs/github-event/marketplace_purchase/purchased.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ const { test, tearDown } = require('tap')
const nock = require('nock')
const dbs = require('../../../../lib/dbs')
const worker = require('../../../../jobs/github-event/marketplace_purchase/purchased')

const removeIfExists = async (db, id) => {
try {
return await db.remove(await db.get(id))
} catch (e) {
if (e.status !== 404) {
throw e
}
}
}
const removeIfExists = require('../../../remove-if-exists.js')

nock.disableNetConnect()
nock.enableNetConnect('localhost')
Expand Down
11 changes: 1 addition & 10 deletions test/jobs/reset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { test } = require('tap')
const nock = require('nock')
const worker = require('../../jobs/reset')
const removeIfExists = require('../remove-if-exists.js')

const dbs = require('../../lib/dbs')
const timeToWaitAfterTests = 500
Expand All @@ -11,16 +12,6 @@ const waitFor = (milliseconds) => {
})
}

const removeIfExists = async (db, id) => {
try {
return await db.remove(await db.get(id))
} catch (e) {
if (e.status !== 404) {
throw e
}
}
}

nock.disableNetConnect()
nock.enableNetConnect('localhost')

Expand Down
9 changes: 9 additions & 0 deletions test/remove-if-exists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = async function (db, id) {
try {
return await db.remove(await db.get(id))
} catch (e) {
if (e.status !== 404) {
throw e
}
}
}

0 comments on commit 96778af

Please sign in to comment.