Skip to content

Commit 1a806aa

Browse files
committed
Merge remote-tracking branch 'origin/MC-19023' into 2.3.3-develop-pr68
2 parents fce26a4 + 7c240d9 commit 1a806aa

File tree

3 files changed

+111
-6
lines changed

3 files changed

+111
-6
lines changed

app/code/Magento/Checkout/view/frontend/web/js/action/select-payment-method.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ define([
1212
'use strict';
1313

1414
return function (paymentMethod) {
15-
paymentMethod.__disableTmpl = {
16-
title: true
17-
};
18-
15+
if (paymentMethod) {
16+
paymentMethod.__disableTmpl = {
17+
title: true
18+
};
19+
}
1920
quote.paymentMethod(paymentMethod);
2021
};
2122
});

app/code/Magento/Checkout/view/frontend/web/js/action/set-payment-information-extended.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,33 @@ define([
1313
'Magento_Checkout/js/model/error-processor',
1414
'Magento_Customer/js/model/customer',
1515
'Magento_Checkout/js/action/get-totals',
16-
'Magento_Checkout/js/model/full-screen-loader'
17-
], function (quote, urlBuilder, storage, errorProcessor, customer, getTotalsAction, fullScreenLoader) {
16+
'Magento_Checkout/js/model/full-screen-loader',
17+
'underscore'
18+
], function (quote, urlBuilder, storage, errorProcessor, customer, getTotalsAction, fullScreenLoader, _) {
1819
'use strict';
1920

21+
/**
22+
* Filter template data.
23+
*
24+
* @param {Object|Array} data
25+
*/
26+
var filterTemplateData = function (data) {
27+
return _.each(data, function (value, key, list) {
28+
if (_.isArray(value) || _.isObject(value)) {
29+
list[key] = filterTemplateData(value);
30+
}
31+
32+
if (key === '__disableTmpl') {
33+
delete list[key];
34+
}
35+
});
36+
};
37+
2038
return function (messageContainer, paymentData, skipBilling) {
2139
var serviceUrl,
2240
payload;
2341

42+
paymentData = filterTemplateData(paymentData);
2443
skipBilling = skipBilling || false;
2544
payload = {
2645
cartId: quote.getQuoteId(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'squire',
8+
'jquery'
9+
], function (Squire, $) {
10+
'use strict';
11+
12+
var injector = new Squire(),
13+
setPaymentInformation,
14+
serviceUrl = 'http://url',
15+
mocks = {
16+
'Magento_Checkout/js/model/quote': {
17+
getQuoteId: jasmine.createSpy().and.returnValue(1),
18+
billingAddress: jasmine.createSpy().and.returnValue(null)
19+
},
20+
'Magento_Checkout/js/model/url-builder': {
21+
createUrl: jasmine.createSpy().and.returnValue(serviceUrl)
22+
},
23+
'mage/storage': {
24+
post: function () {} // jscs:ignore jsDoc
25+
},
26+
'Magento_Customer/js/model/customer': {
27+
isLoggedIn: jasmine.createSpy().and.returnValue(false)
28+
},
29+
'Magento_Checkout/js/model/full-screen-loader': {
30+
startLoader: jasmine.createSpy(),
31+
stopLoader: jasmine.createSpy()
32+
},
33+
'Magento_Checkout/js/action/get-totals': jasmine.createSpy('getTotalsAction'),
34+
'Magento_Checkout/js/model/error-processor': jasmine.createSpy('errorProcessor')
35+
};
36+
37+
beforeEach(function (done) {
38+
injector.mock(mocks);
39+
injector.require(
40+
['Magento_Checkout/js/action/set-payment-information-extended'],
41+
function (action) {
42+
setPaymentInformation = action;
43+
done();
44+
});
45+
});
46+
47+
afterEach(function () {
48+
try {
49+
injector.clean();
50+
injector.remove();
51+
} catch (e) {
52+
}
53+
});
54+
55+
describe('Magento/Checkout/js/action/set-payment-information-extended', function () {
56+
it('Checks that paymentData consist correct data value.', function () {
57+
var messageContainer = jasmine.createSpy('messageContainer'),
58+
deferral = new $.Deferred(),
59+
paymentData = {
60+
method: 'checkmo',
61+
additionalData: null,
62+
__disableTmpl: {
63+
title: true
64+
}
65+
},
66+
payload = {
67+
cartId: 1,
68+
paymentMethod: {
69+
method: 'checkmo',
70+
additionalData: null
71+
},
72+
billingAddress: null
73+
};
74+
75+
spyOn(mocks['mage/storage'], 'post').and.callFake(function () {
76+
return deferral.resolve({});
77+
});
78+
79+
setPaymentInformation(messageContainer, paymentData, false);
80+
expect(mocks['Magento_Checkout/js/model/full-screen-loader'].startLoader).toHaveBeenCalled();
81+
expect(mocks['mage/storage'].post).toHaveBeenCalledWith(serviceUrl, JSON.stringify(payload));
82+
expect(mocks['Magento_Checkout/js/model/full-screen-loader'].stopLoader).toHaveBeenCalled();
83+
});
84+
});
85+
});

0 commit comments

Comments
 (0)