Created
June 26, 2019 06:52
-
-
Save ThomasGHenry/144259728e91fa447991cdc43060b336 to your computer and use it in GitHub Desktop.
stripe async test woes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('simplified test', async function() { | |
expect.assertions(1); | |
const stripe = Stripe(app.get('STRIPE_KEY')); | |
const ntc = new NightlyTranChecker(app); | |
jest | |
.spyOn(stripe.transfers, 'create') | |
.mockImplementation(() => ntc.stripe_cb(null, { whatever: 'blah' })); | |
const { req, res } = setupParams(); | |
await ntc.checkTransactions(req, res); | |
expect(stripe.transfers.create).toHaveBeenCalledTimes(1); | |
}); | |
// code under test | |
async stripe_cb_inner(error, host, tour, tran, transfer) { | |
console.log('stripe_cb_inner, error: ', error); | |
console.log('stripe_cb_inner, transfer: ', transfer); | |
if (error) { | |
await this.emailFailureToAdmins(error, transfer); | |
await this.emailFailureToHostAndAdmins(host, tour, tran); | |
} else { | |
await this.processStripeSuccess(host, tour, tran, transfer); | |
} | |
} | |
async processTour(host, tour, tran) { | |
console.log('processTour, tour: ' + tour); | |
const stripe = Stripe(this.app.get('STRIPE_KEY')); | |
let { stripe_user_id } = host; | |
if (stripe_user_id) stripe_user_id = validator.escape(stripe_user_id); | |
let { chargeId, currency, tourPrice } = tran; | |
if (chargeId) chargeId = validator.escape(chargeId); | |
this.stripe_cb = async (error, transfer) => { | |
return await this.stripe_cb_inner(error, host, tour, tran, transfer); | |
}; | |
this.stripe_cb = this.stripe_cb.bind(this); | |
await stripe.transfers.create( | |
{ | |
amount: tourPrice * 100, | |
currency: currency, | |
destination: stripe_user_id, | |
source_transaction: chargeId | |
}, | |
this.stripe_cb | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment