Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const nock = require('nock')
const dbs = require('../../lib/dbs')
const removeIfExists = require('../helpers/remove-if-exists')
const cancelStripeSubscription = require('../../jobs/cancel-stripe-subscription')
nock.disableNetConnect()
nock.enableNetConnect('localhost')
afterAll(async () => {
const { payments } = await dbs()
await Promise.all([
removeIfExists(payments, '123')
])
})
test('Cancel Stripe Subscription', async () => {
const { payments } = await dbs()
expect.assertions(3)
nock('https://api.stripe.com/v1')
.delete('/subscriptions/345')
.reply(200, () => {
// Stripe called
afterEach(function(callback) {
// Ensure we don't mess with the HTTP stack by accident
nock.enableNetConnect();
// Clean up all the mocks
nock.cleanAll();
log().info('Finishing test "%s"', this.currentTest.title);
return callback();
});
function WebPageTestMockServer(host) {
var server;
if (!(this instanceof WebPageTestMockServer)) {
return new WebPageTestMockServer(host);
}
server = nock(host || 'https://www.webpagetest.org');
nock.enableNetConnect();
// request/response mapping
Object.keys(reqResMap).forEach(function (source) {
var filename = reqResMap[source],
pathname = path.join(PATH_RESPONSES, filename),
ext = (path.extname(pathname) || '').slice(1),
type = typeMap[ext];
if (filename) {
server
.filteringPath(/http%3A%2F%2F127.0.0.1%3A\d+%2F/g,
'http%3A%2F%2F127.0.0.1%3A8000%2F')
.persist()
.get(source)
.replyWithFile(200, pathname, {'Content-Type': type});
} else {
// This file gets loaded when mocha is run
process.env.LOG_LEVEL = 'fatal'
import nock from 'nock'
nock.disableNetConnect()
nock.enableNetConnect(/127\.0\.0\.1/)
var mockery = require('mockery');
mockery.enable({
warnOnUnregistered: false
});
// Register the mock mailer with mockery
// TODO: should use more absolute path?
mockery.registerMock('../utils/mailTransporter.js', {
sendMail: function(mail) {
mockMailer.sentMails.push(mail);
return BPromise.resolve(undefined);
}
});
// Configure Nock to allow connections to localhost (for the e2e tests to connect to the API).
nock.enableNetConnect('localhost:' + port);
// Create a mock response for the Nominatim API.
// This mock will keep on re-installing itself to allow for unlimited requests.
var nominatim = nock('https://nominatim.openstreetmap.org');
var installNominatimMock = function() {
nominatim
.get('/reverse')
.query(true)
.optionally()
.reply(200, function() {
// Re-install the mock to always be ready for a next request
installNominatimMock();
return {
address: {
house_number: '1', // jshint ignore:line
road: 'Bundesplatz',
const nock = require('nock')
const simple = require('simple-mock')
nock.disableNetConnect()
nock.enableNetConnect('localhost')
test('parse github host', async () => {
expect.assertions(1)
nock('https://enterprise.github')
.get('/api/v3/repos/greenkeeperio/greenkeeper')
.reply(200, () => {
expect(true).toBeTruthy()
})
simple.mock(process.env, 'GITHUB_HOST', 'https://enterprise.github')
const Github = require('../../lib/github')
const github = Github()
try {
before(async () => {
probotOptions = {
id: process.env.APP_ID || createAppId(),
secret: process.env.WEBHOOK_SECRET || createSha(),
cert: process.env.PRIVATE_KEY || await createPrivateKey(),
port: 3000
};
nock.disableNetConnect();
nock.enableNetConnect('localhost:3000');
});
module.exports.disableNetConnect = () => {
nock.disableNetConnect()
nock.enableNetConnect('localhost')
}
const nock = require('nock')
const dbs = require('../../lib/dbs')
const timeToWaitAfterTests = 1000
const waitFor = (milliseconds) => {
return new Promise((resolve) => {
setTimeout(resolve, milliseconds)
})
}
nock.disableNetConnect()
nock.enableNetConnect('localhost')
describe('send-stripe-cancel-survey', async () => {
beforeEach(async () => {
const { payments } = await dbs()
await payments.put({
_id: '1',
stripeSubscriptionId: null
})
await payments.put({
_id: '2',
stripeSubscriptionId: 'hello'
})
jest.clearAllMocks()
})
const nock = require('nock')
const dbs = require('../../../../lib/dbs')
const removeIfExists = require('../../../helpers/remove-if-exists')
nock.disableNetConnect()
nock.enableNetConnect('localhost')
describe('github-event checksuite_completed', async () => {
beforeAll(async () => {
const { installations } = await dbs()
await installations.put({
_id: '1111',
installation: '7331'
})
})
beforeEach(() => {
jest.resetModules()
})
afterAll(async () => {