Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('continues processing after a connection failure', (done) => {
const Client = require('pg').Client
const orgConnect = Client.prototype.connect
let called = false
Client.prototype.connect = function (cb) {
// Simulate a failure on first call
if (!called) {
called = true
return setTimeout(() => {
cb(connectionFailure)
}, 100)
}
// And pass-through the second call
orgConnect.call(this, cb)
}
const pool = new Pool({
it('continues processing after a connection failure', (done) => {
const Client = require('pg').Client
const orgConnect = Client.prototype.connect
let called = false
Client.prototype.connect = function (cb) {
// Simulate a failure on first call
if (!called) {
called = true
return setTimeout(() => {
cb(connectionFailure)
}, 100)
}
// And pass-through the second call
orgConnect.call(this, cb)
}
const pool = new Pool({
Client: Client,
connectionTimeoutMillis: 1000,
max: 1
it('Tweets about good beers', done => {
var bot = new TwitterBot('username', 'token', 'token_secret')
var queryStub = sinon.stub(Client.prototype, 'query').callsFake(query => new Promise((resolve, reject) => {
resolve({
rows : [{
beer : 'Abraxas',
bid : 77322,
venue_id : 3803461,
count : 9,
rating : 4.44918012619019,
date : '2017-02-04 00:07:28',
username : 'nyc_feed',
brewery : 'Perennial Artisan Ales',
venue : 'As Is NYC',
twitter : '@asisnyc'
}]
})
}))
beforeAll(() => {
connectStub = sinon.stub(Client.prototype, 'connect')
TwitterBot = require('../backend/twitter-bot').TwitterBot
TWITTER_KEY = process.env.TWITTER_KEY
process.env.TWITTER_KEY = 'twitter_key'
TWITTER_SECRET = process.env.TWITTER_SECRET
process.env.TWITTER_SECRET = 'twitter_secret'
toISOStub = sinon.stub(Date.prototype, 'toISOString').callsFake(() => 'fake-time');
})