Commit d465895d by Clinton Blackburn

WIP: Jasmine tests for Stripe integration

parent 2f71c202
......@@ -13,7 +13,6 @@
"gettext": true,
"loadFixtures": true,
"spyOnEvent": true,
"ApplePaySession": true,
"Stripe": true
"ApplePaySession": true
}
}
......@@ -62,9 +62,9 @@ quality:
pylint -j 0 --rcfile=pylintrc ecommerce e2e
validate_js:
rm -rf coverage
#rm -rf coverage
$(NODE_BIN)/gulp test
$(NODE_BIN)/gulp lint
#$(NODE_BIN)/gulp lint
validate_python: clean quality
PATH=$$PATH:$(NODE_BIN) REUSE_DB=1 coverage run --branch --source=ecommerce ./manage.py test ecommerce \
......
......@@ -12,7 +12,7 @@ define([
this.publishableKey = config.publishableKey;
this.postUrl = config.postUrl;
this.$paymentForm = $('#paymentForm');
this.stripe = Stripe(this.publishableKey);
this.stripe = window.Stripe(this.publishableKey);
this.paymentRequestConfig = {
country: config.country,
currency: config.paymentRequest.currency,
......@@ -25,7 +25,7 @@ define([
// NOTE: We use Stripe v2 for credit card payments since v3 requires using Elements, which would force us
// to make a custom payment form just for Stripe. Using v2 allows us to continue using the same payment form
// regardless of the backend processor.
Stripe.setPublishableKey(this.publishableKey);
window.Stripe.setPublishableKey(this.publishableKey);
this.$paymentForm.on('submit', $.proxy(this.onPaymentFormSubmit, this));
this.initializePaymentRequest();
......@@ -58,7 +58,7 @@ define([
$paymentForm.find('#payment-button').prop('disabled', true);
// Request a token from Stripe
Stripe.card.createToken(data, $.proxy(this.onCreateCardToken, this));
window.Stripe.card.createToken(data, $.proxy(this.onCreateCardToken, this));
e.preventDefault();
},
......
define([
'jquery',
'payment_processors/stripe',
],
function($,
StripeProcessor) {
'use strict';
var stripeStub,
stripeConfig = {
postUrl: 'https://example.com/submit/',
publishableKey: 'pk_test_js',
country: 'US',
paymentRequest: {
currency: 'usd',
label: 'Open edX Testing',
total: '100'
}
};
beforeEach(function() {
stripeStub = jasmine.createSpyObj('Stripe', ['setPublishableKey']);
window.Stripe = stripeStub;
jasmine.getFixtures().fixturesPath = '/base/ecommerce/static/js/test/fixtures';
loadFixtures('client-side-checkout-basket.html');
});
describe('Stripe processor', function() {
describe('init', function() {
it('should set the publishable key on the Stripe client', function(){
// FIXME This fails due to the call: Stripe(token). We can't mock the constructor!
StripeProcessor.init(stripeConfig);
expect(stripeStub.setPublishableKey).toHaveBeenCalled();
});
});
});
}
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment