From ec0a3d0e640f605faba214d9d6c03ba18f3b4771 Mon Sep 17 00:00:00 2001 From: Muli Yulzary Date: Sun, 3 Feb 2019 12:11:37 +0200 Subject: [PATCH] Add `action` parameter for v3 execution. See https://developers.google.com/recaptcha/docs/v3#actions --- src/service.js | 6 ++++-- tests/service_test.js | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/service.js b/src/service.js index 36bfbc1..cc70351 100644 --- a/src/service.js +++ b/src/service.js @@ -206,11 +206,13 @@ /** * Executes the reCaptcha + * @param widgetId + * @param [action] the action for reCAPTCHA v3 */ - execute: function (widgetId) { + execute: function (widgetId, action) { validateRecaptchaInstance(); - recaptcha.execute(widgetId); + recaptcha.execute(widgetId, {action: action}); }, /** diff --git a/tests/service_test.js b/tests/service_test.js index 2765457..0b3fa95 100644 --- a/tests/service_test.js +++ b/tests/service_test.js @@ -57,9 +57,9 @@ describe('service', function () { it('should call execute', function () { var _widgetId = 123; - driver.service.execute(_widgetId); + driver.service.execute(_widgetId, 'my-action'); - expect(grecaptchaMock.execute).toHaveBeenCalledWith(_widgetId); + expect(grecaptchaMock.execute).toHaveBeenCalledWith(_widgetId, {action: 'my-action'}); }); it('should call getResponse', function () { @@ -163,9 +163,9 @@ describe('service', function () { var _widgetId = 123; - driver.service.execute(_widgetId); + driver.service.execute(_widgetId, 'my-action'); - expect(grecaptchaMock.execute).toHaveBeenCalledWith(_widgetId); + expect(grecaptchaMock.execute).toHaveBeenCalledWith(_widgetId, {action: 'my-action'}); }); it('should not proceed if render function not available in grecaptcha', function () {