diff --git a/src/app/core/data/google-recaptcha.service.spec.ts b/src/app/core/data/google-recaptcha.service.spec.ts new file mode 100644 index 0000000000..bc13e3e494 --- /dev/null +++ b/src/app/core/data/google-recaptcha.service.spec.ts @@ -0,0 +1,32 @@ +import { GoogleRecaptchaService } from './google-recaptcha.service'; +import { of as observableOf } from 'rxjs'; + +describe('GoogleRecaptchaService', () => { + let service: GoogleRecaptchaService; + + let reCaptchaV3Service; + + function init() { + reCaptchaV3Service = jasmine.createSpyObj('reCaptchaV3Service', { + execute: observableOf('googleRecaptchaToken') + }); + service = new GoogleRecaptchaService(reCaptchaV3Service); + } + + beforeEach(() => { + init(); + }); + + describe('getRecaptchaToken', () => { + let result; + + beforeEach(() => { + result = service.getRecaptchaToken('test'); + }); + + it('should send a Request with action', () => { + expect(reCaptchaV3Service.execute).toHaveBeenCalledWith('test'); + }); + + }); +}); diff --git a/src/app/core/data/google-recaptcha.service.ts b/src/app/core/data/google-recaptcha.service.ts index 1865b6ffbb..edf559d501 100644 --- a/src/app/core/data/google-recaptcha.service.ts +++ b/src/app/core/data/google-recaptcha.service.ts @@ -1,6 +1,9 @@ import { Injectable } from '@angular/core'; import { ReCaptchaV3Service } from 'ng-recaptcha'; +/** + * A GoogleRecaptchaService used to send action and get a token from REST + */ @Injectable() export class GoogleRecaptchaService { @@ -8,6 +11,10 @@ export class GoogleRecaptchaService { private recaptchaV3Service: ReCaptchaV3Service ) {} + /** + * Returns an observable of string + * @param action action is the process type in which used to protect multiple spam REST calls + */ public getRecaptchaToken (action) { return this.recaptchaV3Service.execute(action); }