Skip to content

Commit 0964841

Browse files
author
Anna Bukatar
committed
ACP2E-876: Google Recaptcha on Checkout not working
1 parent fe27bad commit 0964841

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define(['squire'
7+
], function (Squire) {
8+
'use strict';
9+
10+
var injector = new Squire(),
11+
12+
defaultContext = require.s.contexts._,
13+
mixin,
14+
registry,
15+
redirect;
16+
17+
beforeEach(function (done) {
18+
window.checkoutConfig = {
19+
defaultSuccessPageUrl: ''
20+
};
21+
22+
injector.require([
23+
'Magento_ReCaptchaCheckout/js/model/place-order-mixin',
24+
'Magento_ReCaptchaWebapiUi/js/webapiReCaptchaRegistry',
25+
'Magento_Checkout/js/action/redirect-on-success'
26+
], function (Mixin, Registry, Redirect) {
27+
mixin = Mixin;
28+
registry = Registry;
29+
redirect = Redirect;
30+
done();
31+
});
32+
});
33+
34+
afterEach(function () {
35+
try {
36+
injector.clean();
37+
injector.remove();
38+
} catch (e) {}
39+
});
40+
41+
describe('Magento_ReCaptchaCheckout/js/model/place-order-mixin', function () {
42+
it('mixin is applied to Magento_Checkout/js/model/place-order', function () {
43+
var placeOrderMixins = defaultContext.config.config.mixins['Magento_Checkout/js/model/place-order'];
44+
45+
expect(placeOrderMixins['Magento_ReCaptchaCheckout/js/model/place-order-mixin']).toBe(true);
46+
});
47+
48+
it('Magento_Checkout/js/action/redirect-on-success is called', function () {
49+
let recaptchaId = 'recaptcha-checkout-place-order',
50+
messageContainer = jasmine.createSpy('messageContainer'),
51+
payload = {},
52+
serviceUrl = 'test',
53+
54+
/**
55+
* Order place action mock
56+
*
57+
* @returns {{fail: fail, done: (function(Function): *)}}
58+
*/
59+
action = function () {
60+
return {
61+
/**
62+
* Success result for request
63+
*
64+
* @param {Function} handler
65+
* @returns {*}
66+
*/
67+
done: function (handler) {
68+
handler();
69+
return this;
70+
},
71+
72+
/**
73+
* Fail result for request
74+
*/
75+
fail: function () {}
76+
};
77+
};
78+
79+
/**
80+
* Triggers declared listener
81+
*
82+
* @returns {*}
83+
*/
84+
registry.triggers[recaptchaId] = function () {
85+
if (registry._listeners[recaptchaId] !== undefined) {
86+
return registry._listeners[recaptchaId]('token');
87+
}
88+
};
89+
90+
/**
91+
* Registers a listener
92+
*
93+
* @param id
94+
* @param func
95+
*/
96+
registry.addListener = function (id, func) {
97+
registry._listeners[id] = func;
98+
};
99+
100+
redirect.execute = jasmine.createSpy();
101+
mixin()(action, serviceUrl, payload, messageContainer);
102+
expect(redirect.execute).toHaveBeenCalled();
103+
});
104+
});
105+
});

0 commit comments

Comments
 (0)